mirror of https://github.com/nicolargo/glances
Changed percentage bars to use an explicit assertion error if valid is outside of the expected range.
parent
b75d921ff0
commit
2b1b80c032
|
@ -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
|
||||
|
|
12
unitest.py
12
unitest.py
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue