Changed percentage bars to use an explicit assertion error if valid is outside of the expected range.

pull/686/head
kevinlondon 2015-09-20 12:44:59 -07:00 committed by Alessio Sergi
parent b75d921ff0
commit 2b1b80c032
2 changed files with 15 additions and 2 deletions

View File

@ -69,8 +69,9 @@ class Bar(object):
@percent.setter
def percent(self, value):
assert value >= 0
assert value <= 100
if value < 0 or value > 100:
raise AssertionError('The percent must be between 0 and 100.')
self.__percent = value
@property

View File

@ -24,6 +24,7 @@ import sys
import time
import unittest
from glances.outputs.glances_bars import Bar
from glances.core.glances_globals import (
appname,
is_linux,
@ -186,5 +187,16 @@ class TestGlances(unittest.TestCase):
# Check if number of processes in the list equal counter
# self.assertEqual(total, len(stats_grab))
def test_011_output_bars_must_be_between_0_and_100_percent(self):
bar = Bar(size=1)
with self.assertRaises(AssertionError):
bar.percent = -1
bar.percent = 101
# 0 - 100 is an inclusive range, so these should not error.
bar.percent = 0
bar.percent = 100
if __name__ == '__main__':
unittest.main()