hitl_tester.test_cases.bms.test_thermal_chamber
This test case runs through all the thermal chamber functions available to the HITL, and functioning correctly.
Used in these test plans:
- chamber_test ⠀⠀⠀(bms/chamber_test.plan)
Example Command (warning: test plan may run other test cases):
./hitl_tester.py chamber_test
1""" 2This test case runs through all the thermal chamber functions available to the HITL, and functioning correctly. 3""" 4 5import datetime 6 7import pytest 8 9from hitl_tester.modules.bms.bms_hw import BMSHardware 10 11bms_hardware = BMSHardware(pytest.flags) # type: ignore[arg-type] 12bms_hardware.init() 13 14 15def raise_thermal_chamber_temperature(higher_temperature): 16 """Set and wait for a higher temperature to be reached.""" 17 bms_hardware.thermal_chamber.set_point_temperature = higher_temperature # Test writing the set point temperature 18 assert ( 19 bms_hardware.thermal_chamber.set_point_temperature == higher_temperature 20 ) # Test reading the set point temperature 21 bms_hardware.thermal_chamber.block_until_set_point_reached() # Wait until the set temperature has been reached 22 assert ( 23 higher_temperature - 2 <= bms_hardware.thermal_chamber.air_temperature <= higher_temperature + 2 24 ) # Test reading the air temperature (chamber rated for -68C to 180C), and that it's within 2 Celsius 25 26 27def lower_thermal_chamber_temperature(lower_temperature): 28 """Set and wait for a lower temperature to be reached.""" 29 bms_hardware.thermal_chamber.set_point_temperature = lower_temperature # Test writing the set point temperature 30 assert ( 31 bms_hardware.thermal_chamber.set_point_temperature == lower_temperature 32 ) # Test reading the set point temperature 33 bms_hardware.thermal_chamber.block_until_set_point_reached() # Wait until the set temperature has been reached 34 assert ( 35 lower_temperature - 2 <= bms_hardware.thermal_chamber.air_temperature <= lower_temperature + 2 36 ) # Test reading the air temperature (chamber rated for -68C to 180C), and that it's within 2 Celsius 37 38 39def test_thermal_chamber(capsys): 40 """Run all the thermal chamber functions and confirm they're responding appropriately.""" 41 with capsys.disabled(): # Enable I/O 42 # Test writing/reading temperature units 43 print(f"Current status 1: {bms_hardware.thermal_chamber.status}") 44 45 print(f"Current units 1: {bms_hardware.thermal_chamber.internal_units}", end="") 46 print(f" {bms_hardware.thermal_chamber.display_units}") 47 bms_hardware.thermal_chamber.internal_units = "F" 48 bms_hardware.thermal_chamber.display_units = "F" 49 bms_hardware.delay(5) 50 assert bms_hardware.thermal_chamber.internal_units == "F" 51 assert bms_hardware.thermal_chamber.display_units == "F" 52 print(f"Current units 2: {bms_hardware.thermal_chamber.internal_units}", end="") 53 print(f" {bms_hardware.thermal_chamber.display_units}") 54 bms_hardware.thermal_chamber.internal_units = "C" 55 bms_hardware.thermal_chamber.display_units = "C" 56 bms_hardware.delay(5) 57 assert bms_hardware.thermal_chamber.internal_units == "C" 58 assert bms_hardware.thermal_chamber.display_units == "C" 59 print(f"Current units 3: {bms_hardware.thermal_chamber.internal_units}", end="") 60 print(f" {bms_hardware.thermal_chamber.display_units}") 61 62 # Test writing/reading controller date 63 print(f"Current date {bms_hardware.thermal_chamber.date_and_time}", end="") 64 print(f" - {bms_hardware.thermal_chamber.date_and_time.date()}") 65 # bms_hardware.thermal_chamber.date_and_time = datetime.datetime.now() 66 assert bms_hardware.thermal_chamber.date_and_time.date() == datetime.date.today() 67 68 # Test raising and lowering the thermal chamber temperature 69 temperature_delta = 10 70 current_temperature = bms_hardware.thermal_chamber.air_temperature 71 print(f"Current temp 1: {current_temperature}") 72 if current_temperature + temperature_delta <= 180: # Stay within the rated limits of the chamber 73 with pytest.raises(TimeoutError): 74 bms_hardware.thermal_chamber.set_point_temperature = current_temperature + temperature_delta 75 bms_hardware.thermal_chamber.block_until_set_point_reached(timeout=1) 76 print("Caught timeout!") 77 raise_thermal_chamber_temperature(current_temperature + temperature_delta) 78 print(f"Current temp 2: {bms_hardware.thermal_chamber.air_temperature}") 79 lower_thermal_chamber_temperature(current_temperature) 80 print(f"Current temp 3: {bms_hardware.thermal_chamber.air_temperature}") 81 else: 82 with pytest.raises(TimeoutError): 83 bms_hardware.thermal_chamber.set_point_temperature = current_temperature - temperature_delta 84 bms_hardware.thermal_chamber.block_until_set_point_reached(timeout=1) 85 print("Caught timeout!") 86 lower_thermal_chamber_temperature(current_temperature - temperature_delta) 87 print(f"Current temp 2: {bms_hardware.thermal_chamber.air_temperature}") 88 raise_thermal_chamber_temperature(current_temperature) 89 print(f"Current temp 3: {bms_hardware.thermal_chamber.air_temperature}") 90 91 # Check controller status can be read correctly 92 print(f"Current status 2: {bms_hardware.thermal_chamber.status}") 93 assert bms_hardware.thermal_chamber.status in ( 94 "Program Running", 95 "Program Paused", 96 "Constant", 97 "Standby", 98 "Alarm", 99 )
bms_hardware =
<hitl_tester.modules.bms.bms_hw.BMSHardware object>
def
raise_thermal_chamber_temperature(higher_temperature):
16def raise_thermal_chamber_temperature(higher_temperature): 17 """Set and wait for a higher temperature to be reached.""" 18 bms_hardware.thermal_chamber.set_point_temperature = higher_temperature # Test writing the set point temperature 19 assert ( 20 bms_hardware.thermal_chamber.set_point_temperature == higher_temperature 21 ) # Test reading the set point temperature 22 bms_hardware.thermal_chamber.block_until_set_point_reached() # Wait until the set temperature has been reached 23 assert ( 24 higher_temperature - 2 <= bms_hardware.thermal_chamber.air_temperature <= higher_temperature + 2 25 ) # Test reading the air temperature (chamber rated for -68C to 180C), and that it's within 2 Celsius
Set and wait for a higher temperature to be reached.
def
lower_thermal_chamber_temperature(lower_temperature):
28def lower_thermal_chamber_temperature(lower_temperature): 29 """Set and wait for a lower temperature to be reached.""" 30 bms_hardware.thermal_chamber.set_point_temperature = lower_temperature # Test writing the set point temperature 31 assert ( 32 bms_hardware.thermal_chamber.set_point_temperature == lower_temperature 33 ) # Test reading the set point temperature 34 bms_hardware.thermal_chamber.block_until_set_point_reached() # Wait until the set temperature has been reached 35 assert ( 36 lower_temperature - 2 <= bms_hardware.thermal_chamber.air_temperature <= lower_temperature + 2 37 ) # Test reading the air temperature (chamber rated for -68C to 180C), and that it's within 2 Celsius
Set and wait for a lower temperature to be reached.
def
test_thermal_chamber(capsys):
40def test_thermal_chamber(capsys): 41 """Run all the thermal chamber functions and confirm they're responding appropriately.""" 42 with capsys.disabled(): # Enable I/O 43 # Test writing/reading temperature units 44 print(f"Current status 1: {bms_hardware.thermal_chamber.status}") 45 46 print(f"Current units 1: {bms_hardware.thermal_chamber.internal_units}", end="") 47 print(f" {bms_hardware.thermal_chamber.display_units}") 48 bms_hardware.thermal_chamber.internal_units = "F" 49 bms_hardware.thermal_chamber.display_units = "F" 50 bms_hardware.delay(5) 51 assert bms_hardware.thermal_chamber.internal_units == "F" 52 assert bms_hardware.thermal_chamber.display_units == "F" 53 print(f"Current units 2: {bms_hardware.thermal_chamber.internal_units}", end="") 54 print(f" {bms_hardware.thermal_chamber.display_units}") 55 bms_hardware.thermal_chamber.internal_units = "C" 56 bms_hardware.thermal_chamber.display_units = "C" 57 bms_hardware.delay(5) 58 assert bms_hardware.thermal_chamber.internal_units == "C" 59 assert bms_hardware.thermal_chamber.display_units == "C" 60 print(f"Current units 3: {bms_hardware.thermal_chamber.internal_units}", end="") 61 print(f" {bms_hardware.thermal_chamber.display_units}") 62 63 # Test writing/reading controller date 64 print(f"Current date {bms_hardware.thermal_chamber.date_and_time}", end="") 65 print(f" - {bms_hardware.thermal_chamber.date_and_time.date()}") 66 # bms_hardware.thermal_chamber.date_and_time = datetime.datetime.now() 67 assert bms_hardware.thermal_chamber.date_and_time.date() == datetime.date.today() 68 69 # Test raising and lowering the thermal chamber temperature 70 temperature_delta = 10 71 current_temperature = bms_hardware.thermal_chamber.air_temperature 72 print(f"Current temp 1: {current_temperature}") 73 if current_temperature + temperature_delta <= 180: # Stay within the rated limits of the chamber 74 with pytest.raises(TimeoutError): 75 bms_hardware.thermal_chamber.set_point_temperature = current_temperature + temperature_delta 76 bms_hardware.thermal_chamber.block_until_set_point_reached(timeout=1) 77 print("Caught timeout!") 78 raise_thermal_chamber_temperature(current_temperature + temperature_delta) 79 print(f"Current temp 2: {bms_hardware.thermal_chamber.air_temperature}") 80 lower_thermal_chamber_temperature(current_temperature) 81 print(f"Current temp 3: {bms_hardware.thermal_chamber.air_temperature}") 82 else: 83 with pytest.raises(TimeoutError): 84 bms_hardware.thermal_chamber.set_point_temperature = current_temperature - temperature_delta 85 bms_hardware.thermal_chamber.block_until_set_point_reached(timeout=1) 86 print("Caught timeout!") 87 lower_thermal_chamber_temperature(current_temperature - temperature_delta) 88 print(f"Current temp 2: {bms_hardware.thermal_chamber.air_temperature}") 89 raise_thermal_chamber_temperature(current_temperature) 90 print(f"Current temp 3: {bms_hardware.thermal_chamber.air_temperature}") 91 92 # Check controller status can be read correctly 93 print(f"Current status 2: {bms_hardware.thermal_chamber.status}") 94 assert bms_hardware.thermal_chamber.status in ( 95 "Program Running", 96 "Program Paused", 97 "Constant", 98 "Standby", 99 "Alarm", 100 )
Run all the thermal chamber functions and confirm they're responding appropriately.