diff options
author | Alessio Sergi <al3hex@gmail.com> | 2014-06-13 20:06:13 +0200 |
---|---|---|
committer | Alessio Sergi <al3hex@gmail.com> | 2014-06-13 20:06:13 +0200 |
commit | 4c4279eccb3f502162d48d415cdcd9577c57254b (patch) | |
tree | 67a038a93df4c21e70677deb16835c6f6afda23a /unitest.py | |
parent | b5cac27e99b8f899e39ba9b0826cbcf35eda3bc3 (diff) |
Fix unitary tests
Fix python3 compat.
Diffstat (limited to 'unitest.py')
-rwxr-xr-x | unitest.py | 79 |
1 files changed, 36 insertions, 43 deletions
@@ -20,23 +20,16 @@ """Glances unitary tests suite.""" -import os -import sys -import time import gettext import locale +import sys +import time import unittest from glances.core.glances_globals import ( - __appname__, - __version__, - is_bsd, + appname, is_linux, - is_mac, - is_py3, - is_windows, - sys_prefix, - work_path + version ) # Global variables @@ -47,7 +40,7 @@ if not is_linux: print('ERROR: Unitaries tests should be ran on GNU/Linux operating system') sys.exit(2) else: - print('{} {} {}'.format('Unitary tests for', __appname__, __version__)) + print('Unitary tests for {0} {1}'.format(appname, version)) # Import local settings from glances.core.glances_globals import gettext_domain, locale_dir @@ -65,17 +58,17 @@ if not core.is_standalone(): from glances.core.glances_stats import GlancesStats stats = GlancesStats() + # Unitest class # ============== - -class testGlances(unittest.TestCase): +class TestGlances(unittest.TestCase): """Test Glances class.""" def setUp(self): """The function is called *every time* before test_*.""" - print('\n' + '='*78) + print('\n' + '=' * 78) def test_000_update(self): """Update stats (mandatory step for all the stats). @@ -99,69 +92,69 @@ class testGlances(unittest.TestCase): def test_001_plugins(self): """Check mandatory plugins.""" - plug_to_check = [ 'system', 'cpu', 'load', 'mem', 'memswap', 'network', 'diskio', 'fs' ] - print('INFO: [TEST_001] Check the mandatory plugins list: %s' % ', '.join(plug_to_check)) - plug_list = stats.getAllPlugins() - for p in plug_to_check: - self.assertTrue(p in plug_list) + plugins_to_check = ['system', 'cpu', 'load', 'mem', 'memswap', 'network', 'diskio', 'fs'] + print('INFO: [TEST_001] Check the mandatory plugins list: %s' % ', '.join(plugins_to_check)) + plugins_list = stats.getAllPlugins() + for plugin in plugins_to_check: + self.assertTrue(plugin in plugins_list) def test_002_cpu(self): """Check SYSTEM plugin.""" - stats_to_check = [ 'hostname', 'os_name' ] + stats_to_check = ['hostname', 'os_name'] print('INFO: [TEST_002] Check SYSTEM stats: %s' % ', '.join(stats_to_check)) stats_grab = stats.get_plugin('system').get_raw() - for s in stats_to_check: + for stat in stats_to_check: # Check that the key exist - self.assertTrue(stats_grab.has_key(s), msg='Can not find key: %s' % s) + self.assertTrue(stat in stats_grab, msg='Cannot find key: %s' % stat) print('INFO: SYSTEM stats: %s' % stats_grab) def test_003_cpu(self): """Check CPU plugin.""" - stats_to_check = [ 'system', 'user', 'idle' ] + stats_to_check = ['system', 'user', 'idle'] print('INFO: [TEST_003] Check mandatory CPU stats: %s' % ', '.join(stats_to_check)) stats_grab = stats.get_plugin('cpu').get_raw() - for s in stats_to_check: + for stat in stats_to_check: # Check that the key exist - self.assertTrue(stats_grab.has_key(s), msg='Can not find key: %s' % s) + self.assertTrue(stat in stats_grab, msg='Cannot find key: %s' % stat) # Check that % is > 0 and < 100 - self.assertGreaterEqual(stats_grab[s], 0) - self.assertLessEqual(stats_grab[s], 100) + self.assertGreaterEqual(stats_grab[stat], 0) + self.assertLessEqual(stats_grab[stat], 100) print('INFO: CPU stats: %s' % stats_grab) def test_004_load(self): """Check LOAD plugin.""" - stats_to_check = [ 'cpucore', 'min1', 'min5', 'min15' ] + stats_to_check = ['cpucore', 'min1', 'min5', 'min15'] print('INFO: [TEST_004] Check LOAD stats: %s' % ', '.join(stats_to_check)) stats_grab = stats.get_plugin('load').get_raw() - for s in stats_to_check: + for stat in stats_to_check: # Check that the key exist - self.assertTrue(stats_grab.has_key(s), msg='Can not find key: %s' % s) + self.assertTrue(stat in stats_grab, msg='Cannot find key: %s' % stat) # Check that % is > 0 - self.assertGreaterEqual(stats_grab[s], 0) + self.assertGreaterEqual(stats_grab[stat], 0) print('INFO: LOAD stats: %s' % stats_grab) def test_005_mem(self): """Check MEM plugin.""" - stats_to_check = [ 'available', 'used', 'free', 'total' ] + stats_to_check = ['available', 'used', 'free', 'total'] print('INFO: [TEST_005] Check MEM stats: %s' % ', '.join(stats_to_check)) stats_grab = stats.get_plugin('mem').get_raw() - for s in stats_to_check: + for stat in stats_to_check: # Check that the key exist - self.assertTrue(stats_grab.has_key(s), msg='Can not find key: %s' % s) + self.assertTrue(stat in stats_grab, msg='Cannot find key: %s' % stat) # Check that % is > 0 - self.assertGreaterEqual(stats_grab[s], 0) + self.assertGreaterEqual(stats_grab[stat], 0) print('INFO: MEM stats: %s' % stats_grab) def test_006_swap(self): """Check MEMSWAP plugin.""" - stats_to_check = [ 'used', 'free', 'total' ] + stats_to_check = ['used', 'free', 'total'] print('INFO: [TEST_006] Check SWAP stats: %s' % ', '.join(stats_to_check)) stats_grab = stats.get_plugin('memswap').get_raw() - for s in stats_to_check: + for stat in stats_to_check: # Check that the key exist - self.assertTrue(stats_grab.has_key(s), msg='Can not find key: %s' % s) + self.assertTrue(stat in stats_grab, msg='Cannot find key: %s' % stat) # Check that % is > 0 - self.assertGreaterEqual(stats_grab[s], 0) + self.assertGreaterEqual(stats_grab[stat], 0) print('INFO: SWAP stats: %s' % stats_grab) def test_007_network(self): @@ -180,7 +173,7 @@ class testGlances(unittest.TestCase): def test_009_fs(self): """Check File System plugin.""" - stats_to_check = [ ] + # stats_to_check = [ ] print('INFO: [TEST_009] Check FS stats') stats_grab = stats.get_plugin('fs').get_raw() self.assertTrue(type(stats_grab) is list, msg='FileSystem stats is not a list') @@ -188,10 +181,10 @@ class testGlances(unittest.TestCase): def test_010_processes(self): """Check Process plugin.""" - stats_to_check = [ ] + # stats_to_check = [ ] print('INFO: [TEST_010] Check PROCESS stats') stats_grab = stats.get_plugin('processcount').get_raw() - total = stats_grab['total'] + # total = stats_grab['total'] self.assertTrue(type(stats_grab) is dict, msg='Process count stats is not a dict') print('INFO: PROCESS count stats: %s' % stats_grab) stats_grab = stats.get_plugin('processlist').get_raw() |