summaryrefslogtreecommitdiffstats
path: root/unitest.py
diff options
context:
space:
mode:
authorTomáš Vyčítal <tom.vycital@gmail.com>2018-02-14 21:08:44 +0100
committerTomáš Vyčítal <tom.vycital@gmail.com>2018-02-14 21:08:44 +0100
commit7bd0cff0aaa4bcec32eec67e1a97c4f952eb5091 (patch)
treea72cf0832fdc0857511442027d06b4ef7ef96ad4 /unitest.py
parent5819b72682e3b03b91b5012867a9c76d6be71486 (diff)
Add a unit test for plugin's sorted stats method
Diffstat (limited to 'unitest.py')
-rwxr-xr-xunitest.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/unitest.py b/unitest.py
index 84a8e4c7..3ee52369 100755
--- a/unitest.py
+++ b/unitest.py
@@ -33,6 +33,7 @@ from glances.thresholds import GlancesThresholdCareful
from glances.thresholds import GlancesThresholdWarning
from glances.thresholds import GlancesThresholdCritical
from glances.thresholds import GlancesThresholds
+from glances.plugins.glances_plugin import GlancesPlugin
# Global variables
# =================
@@ -212,6 +213,34 @@ class TestGlances(unittest.TestCase):
self.assertTrue(type(stats_grab) is list, msg='GPU stats is not a list')
print('INFO: GPU stats: %s' % stats_grab)
+ def test_014_sorted_stats(self):
+ """Check sorted stats method."""
+ print('INFO: [TEST_015] Check sorted stats method')
+ aliases = {
+ "key2": "alias11",
+ "key5": "alias2",
+ }
+ unsorted_stats = [
+ {"key": "key4"},
+ {"key": "key2"},
+ {"key": "key5"},
+ {"key": "key21"},
+ {"key": "key3"},
+ ]
+
+ gp = GlancesPlugin()
+ gp.get_key = lambda: "key"
+ gp.has_alias = aliases.get
+ gp.stats = unsorted_stats
+
+ sorted_stats = gp.sorted_stats()
+ self.assertEqual(len(sorted_stats), 5)
+ self.assertEqual(sorted_stats[0]["key"], "key5")
+ self.assertEqual(sorted_stats[1]["key"], "key2")
+ self.assertEqual(sorted_stats[2]["key"], "key3")
+ self.assertEqual(sorted_stats[3]["key"], "key4")
+ self.assertEqual(sorted_stats[4]["key"], "key21")
+
def test_094_thresholds(self):
"""Test thresholds classes"""
print('INFO: [TEST_094] Thresholds')