Skip to content
Browse files

re-added unit tests in new modules

  • Loading branch information...
1 parent 75edab3 commit e713edc29c35dba47c3ed57f627053d645b08ce4 @cgoldberg committed Apr 1, 2012
View
88 linux_metrics/cpu_stat_tests.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2010-2012 Corey Goldberg (http://goldb.org)
+#
+# This file is part of linux-metrics
+#
+# License :: OSI Approved :: MIT License:
+# http://www.opensource.org/licenses/mit-license
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+
+
+import cpu_stat
+import unittest
+
+
+
+class TestCPUStats(unittest.TestCase):
+
+ def setUp(self):
+ self.sample_duration = .1 # secs
+
+ def test_cpu_info(self):
+ values = cpu_stat.cpu_info()
+ self.assertTrue(len(values) > 0, values)
+
+ def test_cpu_percent_idle(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['idle']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_iowait(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['iowait']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_irq(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['irq']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_nice(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['nice']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_softirq(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['softirq']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_system(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['system']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percent_user(self):
+ value = cpu_stat.cpu_percents(self.sample_duration)['user']
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_cpu_percents(self):
+ values = cpu_stat.cpu_percents(self.sample_duration)
+ self.assertTrue(len(values) == 7, values)
+
+ def test_cpu_times(self):
+ values = cpu_stat.cpu_times()
+ self.assertTrue(len(values) >= 7, values)
+
+ def test_procs_blocked(self):
+ value = cpu_stat.procs_blocked()
+ self.assertTrue(value >= 0, value)
+
+ def test_procs_running(self):
+ value = cpu_stat.procs_running()
+ self.assertTrue(value >= 0, value)
+
+ def test_load_avg(self):
+ values = cpu_stat.load_avg()
+ self.assertTrue(len(values) == 3, values)
+
+
+
+if __name__ == '__main__':
+ test_suite = unittest.TestLoader().loadTestsFromTestCase(TestCPUStats)
+ unittest.TextTestRunner(verbosity=2).run(test_suite)
View
83 linux_metrics/disk_stat_tests.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2010-2012 Corey Goldberg (http://goldb.org)
+#
+# This file is part of linux-metrics
+#
+# License :: OSI Approved :: MIT License:
+# http://www.opensource.org/licenses/mit-license
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+
+
+import disk_stat
+import unittest
+
+
+
+# configuration
+DISK_DEVICE = 'sda1'
+
+
+
+class TestDiskStats(unittest.TestCase):
+
+ def setUp(self):
+ self.device = DISK_DEVICE
+ self.sample_duration = .1 # secs
+
+ def test_disk_busy(self):
+ value = disk_stat.disk_busy(
+ self.device,
+ self.sample_duration
+ )
+ self.assertTrue(0.0 <= value <= 100.0, value)
+
+ def test_disk_reads(self):
+ value, _ = disk_stat.disk_reads_writes(
+ self.device
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_disk_reads_persec(self):
+ value, _ = disk_stat.disk_reads_writes_persec(
+ self.device,
+ self.sample_duration
+ )
+ self.assertTrue(value >= 0.0, value)
+
+ def test_disk_writes(self):
+ _, value = disk_stat.disk_reads_writes(
+ self.device
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_disk_writes_persec(self):
+ _, value = disk_stat.disk_reads_writes_persec(
+ self.device,
+ self.sample_duration
+ )
+ self.assertTrue(value >= 0.0, value)
+
+ def test_invalid_disk_interface(self):
+ self.assertRaises(
+ disk_stat.DiskError,
+ disk_stat.disk_busy,
+ 'invalid_device',
+ 0
+ )
+
+
+
+if __name__ == '__main__':
+ test_suite = unittest.TestLoader().loadTestsFromTestCase(TestDiskStats)
+ unittest.TextTestRunner(verbosity=2).run(test_suite)
View
41 linux_metrics/mem_stat_tests.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2010-2012 Corey Goldberg (http://goldb.org)
+#
+# This file is part of linux-metrics
+#
+# License :: OSI Approved :: MIT License:
+# http://www.opensource.org/licenses/mit-license
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+
+
+import mem_stat
+import unittest
+
+
+
+class TestMemoryStats(unittest.TestCase):
+
+ def test_mem_used(self):
+ value, _ = mem_stat.mem_stats()
+ self.assertTrue(value > 0, value)
+
+ def test_mem_total(self):
+ _, value = mem_stat.mem_stats()
+ self.assertTrue(value > 0, value)
+
+
+
+if __name__ == '__main__':
+ test_suite = unittest.TestLoader().loadTestsFromTestCase(TestMemoryStats)
+ unittest.TextTestRunner(verbosity=2).run(test_suite)
View
72 linux_metrics/net_stat_tests.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2010-2012 Corey Goldberg (http://goldb.org)
+#
+# This file is part of linux-metrics
+#
+# License :: OSI Approved :: MIT License:
+# http://www.opensource.org/licenses/mit-license
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+
+
+import net_stat
+import unittest
+
+
+
+# configuration
+NETWORK_INTERFACE = 'eth1'
+
+
+
+class TestNetworkStats(unittest.TestCase):
+
+ def setUp(self):
+ self.interface = NETWORK_INTERFACE
+
+ def test_rx_bytes(self):
+ value, _ = net_stat.rx_tx_bytes(
+ self.interface
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_tx_bytes(self):
+ _, value = net_stat.rx_tx_bytes(
+ self.interface
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_rx_bits(self):
+ value, _ = net_stat.rx_tx_bits(
+ self.interface
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_tx_bits(self):
+ _, value = net_stat.rx_tx_bits(
+ self.interface
+ )
+ self.assertTrue(value >= 0, value)
+
+ def test_invalid_net_interface(self):
+ self.assertRaises(
+ net_stat.NetError,
+ net_stat.rx_tx_bytes,
+ 'invalid_interface'
+ )
+
+
+
+if __name__ == '__main__':
+ test_suite = unittest.TestLoader().loadTestsFromTestCase(TestNetworkStats)
+ unittest.TextTestRunner(verbosity=2).run(test_suite)

0 comments on commit e713edc

Please sign in to comment.
Something went wrong with that request. Please try again.