import pytest from nucon import Nucon, NuconConfig, PumpStatus, PumpDryStatus, PumpOverloadStatus, BreakerStatus @pytest.fixture(scope="module") def nucon_setup(): Nucon.set_dummy_mode(True) Nucon.set_base_url("http://localhost:8080/") yield Nucon.set_dummy_mode(False) def test_read_all_parameters(nucon_setup): all_params = Nucon.get_all() assert len(all_params) == len(Nucon) for param, value in all_params.items(): assert isinstance(value, param.param_type) def test_write_writable_parameters(nucon_setup): writable_params = Nucon.get_all_writable() for param in writable_params: current_value = param.value param.value = current_value assert param.value == current_value def test_enum_parameters(nucon_setup): pump_status = Nucon.COOLANT_CORE_CIRCULATION_PUMP_0_STATUS.value assert isinstance(pump_status, PumpStatus) dry_status = Nucon.COOLANT_CORE_CIRCULATION_PUMP_0_DRY_STATUS.value assert isinstance(dry_status, PumpDryStatus) overload_status = Nucon.COOLANT_CORE_CIRCULATION_PUMP_0_OVERLOAD_STATUS.value assert isinstance(overload_status, PumpOverloadStatus) breaker_status = Nucon.GENERATOR_0_BREAKER.value assert isinstance(breaker_status, BreakerStatus) def test_custom_truthy_values(nucon_setup): assert bool(PumpStatus.ACTIVE_NO_SPEED_REACHED) == True assert bool(PumpStatus.ACTIVE_SPEED_REACHED) == True assert bool(PumpStatus.INACTIVE) == False assert bool(PumpDryStatus.INACTIVE_OR_ACTIVE_WITH_FLUID) == True assert bool(PumpDryStatus.ACTIVE_WITHOUT_FLUID) == False assert bool(PumpOverloadStatus.INACTIVE_OR_ACTIVE_NO_OVERLOAD) == True assert bool(PumpOverloadStatus.ACTIVE_AND_OVERLOAD) == False assert bool(BreakerStatus.OPEN) == True assert bool(BreakerStatus.CLOSED) == False def test_get_multiple_parameters(nucon_setup): params_to_get = [Nucon.CORE_TEMP, Nucon.CORE_PRESSURE, Nucon.RODS_POS_ACTUAL] multiple_params = Nucon.get_multiple(params_to_get) assert len(multiple_params) == len(params_to_get) for param, value in multiple_params.items(): assert isinstance(value, param.param_type) def test_dummy_mode(nucon_setup): Nucon.set_dummy_mode(False) Nucon.set_base_url("http://localhost:8081/") # Change to a non-existent URL to trigger an exception with pytest.raises(Exception): Nucon.CORE_TEMP.value Nucon.set_dummy_mode(True) Nucon.set_base_url("http://localhost:8080/") assert isinstance(Nucon.CORE_TEMP.value, Nucon.CORE_TEMP.param_type) def test_base_url_setting(): original_url = NuconConfig.base_url new_url = "http://newlocalhost:9090/" Nucon.set_base_url(new_url) assert NuconConfig.base_url == new_url Nucon.set_base_url(original_url) def test_error_on_writing_readonly_parameter(nucon_setup): with pytest.raises(ValueError): Nucon.CORE_TEMP.value = 100.0 if __name__ == "__main__": pytest.main()