@@ -33,29 +33,39 @@ def test_set_presence(self):
3333 mock_logger = mock .MagicMock ()
3434 mock_psu = MockPsu ("PSU 1" , 0 , True , True )
3535
36- psu_status = psud .PsuStatus (mock_logger , mock_psu )
36+ psu_status = psud .PsuStatus (mock_logger , mock_psu , 1 )
37+ assert psu_status .presence is True
38+
39+ # Test toggling presence to False
40+ ret = psu_status .set_presence (False )
41+ assert ret == True
3742 assert psu_status .presence == False
3843
3944 # Test toggling presence to True
4045 ret = psu_status .set_presence (True )
4146 assert ret == True
4247 assert psu_status .presence == True
4348
44- # Test toggling presence to False
45- ret = psu_status .set_presence (False )
46- assert ret == True
47- assert psu_status .presence == False
48-
4949 # Test attempting to set presence to the same as the current value
50- ret = psu_status .set_presence (False )
50+ ret = psu_status .set_presence (True )
5151 assert ret == False
52- assert psu_status .presence == False
52+ assert psu_status .presence == True
5353
5454 def test_set_power_good (self ):
5555 mock_logger = mock .MagicMock ()
5656 mock_psu = MockPsu ("PSU 1" , 0 , True , True )
5757
58- psu_status = psud .PsuStatus (mock_logger , mock_psu )
58+ psu_status = psud .PsuStatus (mock_logger , mock_psu , 1 )
59+ assert psu_status .power_good is True
60+
61+ # Test toggling power_good to False
62+ ret = psu_status .set_power_good (False )
63+ assert ret == True
64+ assert psu_status .power_good == False
65+
66+ # Test attempting to set power_good to the same as the current value (return value should be False)
67+ ret = psu_status .set_power_good (False )
68+ assert ret == False
5969 assert psu_status .power_good == False
6070
6171 # Test toggling power_good to True
@@ -68,32 +78,13 @@ def test_set_power_good(self):
6878 assert ret == False
6979 assert psu_status .power_good == True
7080
71- # Test toggling power_good to False
72- ret = psu_status .set_power_good (False )
73- assert ret == True
74- assert psu_status .power_good == False
75-
76- # Test attempting to set power_good to the same as the current value (return value should be False)
77- ret = psu_status .set_power_good (False )
78- assert ret == False
79- assert psu_status .power_good == False
8081
8182 def test_set_voltage (self ):
8283 mock_logger = mock .MagicMock ()
8384 mock_psu = MockPsu ("PSU 1" , 0 , True , True )
8485
85- psu_status = psud .PsuStatus (mock_logger , mock_psu )
86- assert psu_status .voltage_good == False
87-
88- # Pass in a good voltage
89- ret = psu_status .set_voltage (12.0 , 12.5 , 11.5 )
90- assert ret == True
91- assert psu_status .voltage_good == True
92-
93- # Pass in a another good voltage successively (return value should be False)
94- ret = psu_status .set_voltage (11.9 , 12.5 , 11.5 )
95- assert ret == False
96- assert psu_status .voltage_good == True
86+ psu_status = psud .PsuStatus (mock_logger , mock_psu , 1 )
87+ assert psu_status .voltage_good is True
9788
9889 # Pass in a high voltage
9990 ret = psu_status .set_voltage (12.6 , 12.5 , 11.5 )
@@ -110,6 +101,11 @@ def test_set_voltage(self):
110101 assert ret == True
111102 assert psu_status .voltage_good == True
112103
104+ # Pass in a another good voltage successively (return value should be False)
105+ ret = psu_status .set_voltage (11.9 , 12.5 , 11.5 )
106+ assert ret == False
107+ assert psu_status .voltage_good == True
108+
113109 # Pass in a low voltage
114110 ret = psu_status .set_voltage (11.4 , 12.5 , 11.5 )
115111 assert ret == True
@@ -149,18 +145,8 @@ def test_set_temperature(self):
149145 mock_logger = mock .MagicMock ()
150146 mock_psu = MockPsu ("PSU 1" , 0 , True , True )
151147
152- psu_status = psud .PsuStatus (mock_logger , mock_psu )
153- assert psu_status .temperature_good == False
154-
155- # Pass in a good temperature
156- ret = psu_status .set_temperature (20.123 , 50.0 )
157- assert ret == True
158- assert psu_status .temperature_good == True
159-
160- # Pass in a another good temperature successively (return value should be False)
161- ret = psu_status .set_temperature (31.456 , 50.0 )
162- assert ret == False
163- assert psu_status .temperature_good == True
148+ psu_status = psud .PsuStatus (mock_logger , mock_psu , 1 )
149+ assert psu_status .temperature_good is True
164150
165151 # Pass in a high temperature
166152 ret = psu_status .set_temperature (50.001 , 50.0 )
@@ -177,6 +163,11 @@ def test_set_temperature(self):
177163 assert ret == True
178164 assert psu_status .temperature_good == True
179165
166+ # Pass in a another good temperature successively (return value should be False)
167+ ret = psu_status .set_temperature (31.456 , 50.0 )
168+ assert ret == False
169+ assert psu_status .temperature_good == True
170+
180171 # Test passing parameters as None when temperature_good == True
181172 ret = psu_status .set_temperature (psud .NOT_AVAILABLE , 50.0 )
182173 assert ret == False
@@ -199,11 +190,7 @@ def test_is_ok(self):
199190 mock_logger = mock .MagicMock ()
200191 mock_psu = MockPsu ("PSU 1" , 0 , True , True )
201192
202- psu_status = psud .PsuStatus (mock_logger , mock_psu )
203- psu_status .presence = True
204- psu_status .power_good = True
205- psu_status .voltage_good = True
206- psu_status .temperature_good = True
193+ psu_status = psud .PsuStatus (mock_logger , mock_psu , 1 )
207194 ret = psu_status .is_ok ()
208195 assert ret == True
209196
0 commit comments