Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import unittest
2from unittest import mock
3from pi3bar.plugins.load import get_loadavg_dict, LoadAvg
6class GetLoadAvgDictTestCase(unittest.TestCase):
7 @mock.patch('pi3bar.plugins.load.os')
8 def test(self, mock_os):
9 mock_os.getloadavg.return_value = (0.42, 3.1, 13.37)
10 res = get_loadavg_dict()
11 self.assertEqual(0.42, res[1])
12 self.assertEqual(3.1, res[5])
13 self.assertEqual(13.37, res[15])
16class LoadAvgInitTestCase(unittest.TestCase):
17 def test_default_values(self):
18 plugin = LoadAvg()
19 self.assertTrue(plugin.show_1)
20 self.assertTrue(plugin.show_5)
21 self.assertTrue(plugin.show_15)
22 self.assertEqual(1, plugin.short)
23 self.assertEqual(6, plugin.warning)
24 self.assertEqual(12, plugin.critical)
25 self.assertEqual('#ffff00', plugin.warning_color)
26 self.assertIsNone(plugin.warning_background)
27 self.assertIsNone(plugin.critical_color)
28 self.assertEqual('#ff0000', plugin.critical_background)
30 def test_show_1_false(self):
31 plugin = LoadAvg(show_1=False)
32 self.assertFalse(plugin.show_1)
34 def test_show_5_false(self):
35 plugin = LoadAvg(show_1=False)
36 self.assertFalse(plugin.show_1)
38 def test_show_15_false(self):
39 plugin = LoadAvg(show_1=False)
40 self.assertFalse(plugin.show_1)
42 def test_short(self):
43 plugin = LoadAvg(short=5)
44 self.assertEqual(5, plugin.short)
46 def test_warning(self):
47 plugin = LoadAvg(warning=10)
48 self.assertEqual(10, plugin.warning)
50 def test_critical(self):
51 plugin = LoadAvg(critical=15)
52 self.assertEqual(15, plugin.critical)
55_loadavg_dict = {1: 0.42, 5: 3.1, 15: 13.37}
56@mock.patch('pi3bar.plugins.load.get_loadavg_dict', return_value=_loadavg_dict)
57class LoadAvgCycleTestCase(unittest.TestCase):
58 def setUp(self):
59 self.plugin = LoadAvg()
61 def test(self, mock_get_loadavg_dict):
62 self.plugin.cycle()
64 self.assertEqual('0.42 3.10 13.37', self.plugin.full_text)
65 self.assertEqual('0.42', self.plugin.short_text)
66 self.assertIsNone(self.plugin.color)
67 self.assertIsNone(self.plugin.background)
69 def test_show_1_false(self, mock_get_loadavg_dict):
70 self.plugin.show_1 = False
71 self.plugin.cycle()
73 self.assertEqual('3.10 13.37', self.plugin.full_text)
75 def test_show_5_false(self, mock_get_loadavg_dict):
76 self.plugin.show_5 = False
77 self.plugin.cycle()
79 self.assertEqual('0.42 13.37', self.plugin.full_text)
81 def test_show_15_false(self, mock_get_loadavg_dict):
82 self.plugin.show_15 = False
83 self.plugin.cycle()
85 self.assertEqual('0.42 3.10', self.plugin.full_text)
87 def test_alternative(self, mock_get_loadavg_dict):
88 mock_get_loadavg_dict.return_value = {
89 1: 0,
90 5: 0.1,
91 15: 1
92 }
93 self.plugin.cycle()
95 self.assertEqual('0.00 0.10 1.00', self.plugin.full_text)
96 self.assertEqual('0.00', self.plugin.short_text)
98 def test_critical(self, mock_get_loadavg_dict):
99 mock_get_loadavg_dict.return_value = {
100 1: 14,
101 5: 0,
102 15: 0
103 }
104 self.plugin.cycle()
106 self.assertEqual('14.00 0.00 0.00', self.plugin.full_text)
107 self.assertEqual('14.00', self.plugin.short_text)
108 self.assertEqual(self.plugin.critical_color, self.plugin.color)
109 self.assertEqual(self.plugin.critical_background, self.plugin.background)
110 self.assertIsNone(self.plugin.color)
111 self.assertEqual('#ff0000', self.plugin.background)
113 def test_warning(self, mock_get_loadavg_dict):
114 mock_get_loadavg_dict.return_value = {
115 1: 9,
116 5: 0,
117 15: 0
118 }
119 self.plugin.cycle()
121 self.assertEqual('9.00 0.00 0.00', self.plugin.full_text)
122 self.assertEqual('9.00', self.plugin.short_text)
123 self.assertEqual(self.plugin.warning_color, self.plugin.color)
124 self.assertEqual(self.plugin.warning_background, self.plugin.background)
125 self.assertEqual('#ffff00', self.plugin.color)
126 self.assertIsNone(self.plugin.background)