From f20cf4b6d6d9a3a4e14ad44751e80b0a4e099cc0 Mon Sep 17 00:00:00 2001 From: jennmald Date: Fri, 22 Nov 2024 16:00:31 -0500 Subject: [PATCH] fix all tests with matching capital enum values --- system_tests/epics/eiger/test_eiger_system.py | 2 +- tests/conftest.py | 2 +- tests/core/test_flyer.py | 38 ++++++------ tests/core/test_soft_signal_backend.py | 14 ++--- tests/core/test_subset_enum.py | 12 ++-- tests/epics/adaravis/test_aravis.py | 4 +- tests/epics/adcore/test_drivers.py | 6 +- tests/epics/adcore/test_scans.py | 2 +- tests/epics/adcore/test_single_trigger.py | 4 +- tests/epics/adkinetix/test_kinetix.py | 10 ++-- tests/epics/adpilatus/test_pilatus.py | 24 ++++---- tests/epics/adsimdetector/test_sim.py | 10 ++-- tests/epics/advimba/test_vimba.py | 14 ++--- tests/epics/demo/test_demo.py | 6 +- tests/epics/eiger/test_eiger_detector.py | 2 +- tests/epics/signal/test_signals.py | 58 +++++++++---------- tests/fastcs/panda/test_panda_control.py | 6 +- tests/fastcs/panda/test_trigger.py | 2 +- 18 files changed, 108 insertions(+), 108 deletions(-) diff --git a/system_tests/epics/eiger/test_eiger_system.py b/system_tests/epics/eiger/test_eiger_system.py index 4cfc81dae3..8a27c41689 100644 --- a/system_tests/epics/eiger/test_eiger_system.py +++ b/system_tests/epics/eiger/test_eiger_system.py @@ -72,7 +72,7 @@ async def test_trigger_saves_file(test_eiger: EigerDetector, setup_device: Setup single_shot = EigerTriggerInfo( frame_timeout=None, number_of_triggers=1, - trigger=DetectorTrigger.internal, + trigger=DetectorTrigger.INTERNAL, deadtime=None, livetime=None, energy_ev=10000, diff --git a/tests/conftest.py b/tests/conftest.py index 8e0cf546f8..ce62218413 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -231,7 +231,7 @@ def one_shot_trigger_info() -> TriggerInfo: return TriggerInfo( frame_timeout=None, number_of_triggers=1, - trigger=DetectorTrigger.internal, + trigger=DetectorTrigger.INTERNAL, deadtime=None, livetime=None, ) diff --git a/tests/core/test_flyer.py b/tests/core/test_flyer.py index 6c894974b2..44b353534a 100644 --- a/tests/core/test_flyer.py +++ b/tests/core/test_flyer.py @@ -28,28 +28,28 @@ class TriggerState(StrictEnum): - null = "null" - preparing = "preparing" - starting = "starting" - stopping = "stopping" + NULL = "null" + PREPARING = "preparing" + STARTING = "starting" + STOPPING = "stopping" class DummyTriggerLogic(FlyerController[int]): def __init__(self): - self.state = TriggerState.null + self.state = TriggerState.NULL async def prepare(self, value: int): - self.state = TriggerState.preparing + self.state = TriggerState.PREPARING return value async def kickoff(self): - self.state = TriggerState.starting + self.state = TriggerState.STARTING async def complete(self): - self.state = TriggerState.null + self.state = TriggerState.NULL async def stop(self): - self.state = TriggerState.stopping + self.state = TriggerState.STOPPING class DummyWriter(DetectorWriter): @@ -160,7 +160,7 @@ def append_and_print(name, doc): def flying_plan(): yield from bps.stage_all(*detectors, flyer) - assert flyer._trigger_logic.state == TriggerState.stopping + assert flyer._trigger_logic.state == TriggerState.STOPPING # move the flyer to the correct place, before fly scanning. # Prepare the flyer first to get the trigger info for the detectors @@ -172,14 +172,14 @@ def flying_plan(): detector, TriggerInfo( number_of_triggers=number_of_triggers, - trigger=DetectorTrigger.constant_gate, + trigger=DetectorTrigger.CONSTANT_GATE, deadtime=2, livetime=2, ), wait=True, ) - assert flyer._trigger_logic.state == TriggerState.preparing + assert flyer._trigger_logic.state == TriggerState.PREPARING for detector in detectors: detector.controller.disarm.assert_called_once() # type: ignore @@ -195,7 +195,7 @@ def flying_plan(): for detector in detectors: yield from bps.complete(detector, wait=False, group="complete") - assert flyer._trigger_logic.state == TriggerState.null + assert flyer._trigger_logic.state == TriggerState.NULL # Manually increment the index as if a frame was taken frames_completed += frames @@ -227,7 +227,7 @@ def flying_plan(): yield from bps.unstage_all(flyer, *detectors) for detector in detectors: assert detector.controller.disarm.called # type: ignore - assert trigger_logic.state == TriggerState.stopping + assert trigger_logic.state == TriggerState.STOPPING # fly scan RE(flying_plan()) @@ -282,14 +282,14 @@ async def test_hardware_triggered_flyable_too_many_kickoffs( flyer = StandardFlyer(trigger_logic, name="flyer") trigger_info = TriggerInfo( number_of_triggers=number_of_triggers, - trigger=DetectorTrigger.constant_gate, + trigger=DetectorTrigger.CONSTANT_GATE, deadtime=2, livetime=2, ) def flying_plan(): yield from bps.stage_all(*detectors, flyer) - assert flyer._trigger_logic.state == TriggerState.stopping + assert flyer._trigger_logic.state == TriggerState.STOPPING # move the flyer to the correct place, before fly scanning. # Prepare the flyer first to get the trigger info for the detectors @@ -316,7 +316,7 @@ def flying_plan(): for detector in detectors: yield from bps.complete(detector, wait=False, group="complete") - assert flyer._trigger_logic.state == TriggerState.null + assert flyer._trigger_logic.state == TriggerState.NULL # Manually increment the index as if a frame was taken for detector in detectors: @@ -367,7 +367,7 @@ def flying_plan(): ( { "number_of_triggers": 1, - "trigger": DetectorTrigger.constant_gate, + "trigger": DetectorTrigger.CONSTANT_GATE, "deadtime": 2, "livetime": 2, "frame_timeout": "a", @@ -388,7 +388,7 @@ def flying_plan(): ( { "number_of_triggers": 1, - "trigger": DetectorTrigger.internal, + "trigger": DetectorTrigger.INTERNAL, "deadtime": 2, "livetime": 1, "frame_timeout": -1, diff --git a/tests/core/test_soft_signal_backend.py b/tests/core/test_soft_signal_backend.py index 89eb87cc36..f5c0b15c88 100644 --- a/tests/core/test_soft_signal_backend.py +++ b/tests/core/test_soft_signal_backend.py @@ -19,9 +19,9 @@ class MyEnum(StrictEnum): - a = "Aaa" - b = "Bbb" - c = "Ccc" + A = "Aaa" + B = "Bbb" + C = "Ccc" def integer_d(value): @@ -80,7 +80,7 @@ def close(self): (int, 0, 43, integer_d, default_int_type), (float, 0.0, 43.5, number_d, " adpilatus.PilatusDetector: async def test_deadtime_overridable(test_adpilatus: adpilatus.PilatusDetector): pilatus_controller = test_adpilatus._controller - pilatus_controller._readout_time = adpilatus.PilatusReadoutTime.pilatus2 + pilatus_controller._readout_time = adpilatus.PilatusReadoutTime.PILATUS2 # deadtime invariant with exposure time assert pilatus_controller.get_deadtime(0) == 2.28e-3 @@ -37,9 +37,9 @@ async def test_deadtime_invariant( @pytest.mark.parametrize( "detector_trigger,expected_trigger_mode", [ - (DetectorTrigger.internal, adpilatus.PilatusTriggerMode.internal), - (DetectorTrigger.internal, adpilatus.PilatusTriggerMode.internal), - (DetectorTrigger.internal, adpilatus.PilatusTriggerMode.internal), + (DetectorTrigger.INTERNAL, adpilatus.PilatusTriggerMode.INTERNAL), + (DetectorTrigger.INTERNAL, adpilatus.PilatusTriggerMode.INTERNAL), + (DetectorTrigger.INTERNAL, adpilatus.PilatusTriggerMode.INTERNAL), ], ) async def test_trigger_mode_set( @@ -63,7 +63,7 @@ async def test_trigger_mode_set_without_armed_pv( ): async def trigger_and_complete(): await test_adpilatus.controller.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.internal) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.INTERNAL) ) await test_adpilatus.controller.arm() await test_adpilatus.controller.wait_for_idle() @@ -75,7 +75,7 @@ async def trigger_and_complete(): with pytest.raises(asyncio.TimeoutError): await _trigger( test_adpilatus, - adpilatus.PilatusTriggerMode.internal, + adpilatus.PilatusTriggerMode.INTERNAL, trigger_and_complete, ) @@ -88,7 +88,7 @@ async def _trigger( # Default TriggerMode assert ( await test_adpilatus.drv.trigger_mode.get_value() - ) == adpilatus.PilatusTriggerMode.internal + ) == adpilatus.PilatusTriggerMode.INTERNAL await trigger_and_complete() @@ -109,7 +109,7 @@ async def test_unsupported_trigger_excepts(test_adpilatus: adpilatus.PilatusDete await test_adpilatus.prepare( TriggerInfo( number_of_triggers=1, - trigger=DetectorTrigger.edge_trigger, + trigger=DetectorTrigger.EDGE_TRIGGER, deadtime=1.0, livetime=1.0, ) @@ -127,7 +127,7 @@ async def dummy_open(multiplier: int = 0): await test_adpilatus.prepare( TriggerInfo( number_of_triggers=1, - trigger=DetectorTrigger.internal, + trigger=DetectorTrigger.INTERNAL, deadtime=1.0, livetime=1.0, ) @@ -141,16 +141,16 @@ async def test_pilatus_controller(test_adpilatus: adpilatus.PilatusDetector): pilatus_driver = pilatus._drv set_mock_value(pilatus_driver.armed, True) await pilatus.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.constant_gate) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.CONSTANT_GATE) ) await pilatus.arm() await pilatus.wait_for_idle() assert await pilatus_driver.num_images.get_value() == 1 - assert await pilatus_driver.image_mode.get_value() == adcore.ImageMode.multiple + assert await pilatus_driver.image_mode.get_value() == adcore.ImageMode.MULTIPLE assert ( await pilatus_driver.trigger_mode.get_value() - == adpilatus.PilatusTriggerMode.ext_enable + == adpilatus.PilatusTriggerMode.EXT_ENABLE ) assert await pilatus_driver.acquire.get_value() is True diff --git a/tests/epics/adsimdetector/test_sim.py b/tests/epics/adsimdetector/test_sim.py index ecb446a6e1..5ab7dea121 100644 --- a/tests/epics/adsimdetector/test_sim.py +++ b/tests/epics/adsimdetector/test_sim.py @@ -78,7 +78,7 @@ async def test_two_detectors_fly_different_rate( ): trigger_info = TriggerInfo( number_of_triggers=15, - trigger=DetectorTrigger.internal, + trigger=DetectorTrigger.INTERNAL, ) docs = defaultdict(list) @@ -166,13 +166,13 @@ def plan(): drv = controller_a.driver assert False is (yield from bps.rd(drv.acquire)) - assert adcore.ImageMode.multiple == (yield from bps.rd(drv.image_mode)) + assert adcore.ImageMode.MULTIPLE == (yield from bps.rd(drv.image_mode)) hdfb = writer_b.hdf assert True is (yield from bps.rd(hdfb.lazy_open)) assert True is (yield from bps.rd(hdfb.swmr_mode)) assert 0 == (yield from bps.rd(hdfb.num_capture)) - assert adcore.FileWriteMode.stream == (yield from bps.rd(hdfb.file_write_mode)) + assert adcore.FileWriteMode.STREAM == (yield from bps.rd(hdfb.file_write_mode)) assert (yield from bps.rd(writer_a.hdf.file_path)) == str(info_a.directory_path) file_name_a = yield from bps.rd(writer_a.hdf.file_name) @@ -364,14 +364,14 @@ async def test_ad_sim_controller(test_adsimdetector: adsimdetector.SimDetector): ad = test_adsimdetector._controller with patch("ophyd_async.core._signal.wait_for_value", return_value=None): await ad.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.internal) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.INTERNAL) ) await ad.arm() await ad.wait_for_idle() driver = ad.driver assert await driver.num_images.get_value() == 1 - assert await driver.image_mode.get_value() == adcore.ImageMode.multiple + assert await driver.image_mode.get_value() == adcore.ImageMode.MULTIPLE assert await driver.acquire.get_value() is True await ad.disarm() diff --git a/tests/epics/advimba/test_vimba.py b/tests/epics/advimba/test_vimba.py index 2e9c484bc5..adede5f362 100644 --- a/tests/epics/advimba/test_vimba.py +++ b/tests/epics/advimba/test_vimba.py @@ -27,9 +27,9 @@ async def test_get_deadtime( async def test_arming_trig_modes(test_advimba: advimba.VimbaDetector): - set_mock_value(test_advimba.drv.trigger_source, VimbaTriggerSource.freerun) - set_mock_value(test_advimba.drv.trigger_mode, VimbaOnOff.off) - set_mock_value(test_advimba.drv.exposure_mode, VimbaExposeOutMode.timed) + set_mock_value(test_advimba.drv.trigger_source, VimbaTriggerSource.FREERUN) + set_mock_value(test_advimba.drv.trigger_mode, VimbaOnOff.OFF) + set_mock_value(test_advimba.drv.exposure_mode, VimbaExposeOutMode.TIMED) async def setup_trigger_mode(trig_mode: DetectorTrigger): await test_advimba.controller.prepare( @@ -45,22 +45,22 @@ async def setup_trigger_mode(trig_mode: DetectorTrigger): assert (await test_advimba.drv.trigger_mode.get_value()) == "Off" assert (await test_advimba.drv.exposure_mode.get_value()) == "Timed" - await setup_trigger_mode(DetectorTrigger.edge_trigger) + await setup_trigger_mode(DetectorTrigger.EDGE_TRIGGER) assert (await test_advimba.drv.trigger_source.get_value()) == "Line1" assert (await test_advimba.drv.trigger_mode.get_value()) == "On" assert (await test_advimba.drv.exposure_mode.get_value()) == "Timed" - await setup_trigger_mode(DetectorTrigger.constant_gate) + await setup_trigger_mode(DetectorTrigger.CONSTANT_GATE) assert (await test_advimba.drv.trigger_source.get_value()) == "Line1" assert (await test_advimba.drv.trigger_mode.get_value()) == "On" assert (await test_advimba.drv.exposure_mode.get_value()) == "TriggerWidth" - await setup_trigger_mode(DetectorTrigger.internal) + await setup_trigger_mode(DetectorTrigger.INTERNAL) assert (await test_advimba.drv.trigger_source.get_value()) == "Freerun" assert (await test_advimba.drv.trigger_mode.get_value()) == "Off" assert (await test_advimba.drv.exposure_mode.get_value()) == "Timed" - await setup_trigger_mode(DetectorTrigger.variable_gate) + await setup_trigger_mode(DetectorTrigger.VARIABLE_GATE) assert (await test_advimba.drv.trigger_source.get_value()) == "Line1" assert (await test_advimba.drv.trigger_mode.get_value()) == "On" assert (await test_advimba.drv.exposure_mode.get_value()) == "TriggerWidth" diff --git a/tests/epics/demo/test_demo.py b/tests/epics/demo/test_demo.py index e29e13bf29..333d1a78a7 100644 --- a/tests/epics/demo/test_demo.py +++ b/tests/epics/demo/test_demo.py @@ -279,14 +279,14 @@ async def test_read_sensor(mock_sensor: demo.Sensor): assert (await mock_sensor.read())["mock_sensor-value"]["value"] == 0 assert (await mock_sensor.read_configuration())["mock_sensor-mode"][ "value" - ] == demo.EnergyMode.low + ] == demo.EnergyMode.LOW desc = (await mock_sensor.describe_configuration())["mock_sensor-mode"] assert desc["dtype"] == "string" assert desc["choices"] == ["Low Energy", "High Energy"] - set_mock_value(mock_sensor.mode, demo.EnergyMode.high) + set_mock_value(mock_sensor.mode, demo.EnergyMode.HIGH) assert (await mock_sensor.read_configuration())["mock_sensor-mode"][ "value" - ] == demo.EnergyMode.high + ] == demo.EnergyMode.HIGH async def test_sensor_in_plan(RE: RunEngine, mock_sensor: demo.Sensor): diff --git a/tests/epics/eiger/test_eiger_detector.py b/tests/epics/eiger/test_eiger_detector.py index 5fe6ebc836..422da84cf1 100644 --- a/tests/epics/eiger/test_eiger_detector.py +++ b/tests/epics/eiger/test_eiger_detector.py @@ -26,7 +26,7 @@ async def test_when_prepared_with_energy_then_energy_set_on_detector(detector): EigerTriggerInfo( frame_timeout=None, number_of_triggers=1, - trigger=DetectorTrigger.internal, + trigger=DetectorTrigger.INTERNAL, deadtime=None, livetime=None, energy_ev=10000, diff --git a/tests/epics/signal/test_signals.py b/tests/epics/signal/test_signals.py index 07e8a21950..fce394d7fa 100644 --- a/tests/epics/signal/test_signals.py +++ b/tests/epics/signal/test_signals.py @@ -49,9 +49,9 @@ class MySubsetEnum(SubsetEnum): - a = "Aaa" - b = "Bbb" - c = "Ccc" + A = "Aaa" + B = "Bbb" + C = "Ccc" Protocol = Literal["ca", "pva"] @@ -307,7 +307,7 @@ async def assert_backend_get_put_monitor( (int, "my_int", 42, 43), (float, "my_float", 3.141, 43.5), (str, "my_str", "hello", "goodbye"), - (ExampleEnum, "enum", ExampleEnum.b, ExampleEnum.c), + (ExampleEnum, "enum", ExampleEnum.B, ExampleEnum.C), # numpy arrays of numpy types ( Array1D[np.uint8], @@ -495,9 +495,9 @@ async def test_error_raised_on_disconnected_PV(ioc, protocol) -> None: class BadEnum(StrictEnum): - a = "Aaa" - b = "B" - c = "Ccc" + A = "Aaa" + B = "B" + C = "Ccc" def test_enum_equality(): @@ -507,39 +507,39 @@ def test_enum_equality(): """ class GeneratedChoices(StrictEnum): - a = "Aaa" - b = "B" - c = "Ccc" + A = "Aaa" + B = "B" + C = "Ccc" class ExtendedGeneratedChoices(StrictEnum): - a = "Aaa" - b = "B" - c = "Ccc" - d = "Ddd" + A = "Aaa" + B = "B" + C = "Ccc" + D = "Ddd" for enum_class in (GeneratedChoices, ExtendedGeneratedChoices): - assert BadEnum.a == enum_class.a - assert BadEnum.a.value == enum_class.a - assert BadEnum.a.value == enum_class.a.value - assert BadEnum(enum_class.a) is BadEnum.a - assert BadEnum(enum_class.a.value) is BadEnum.a + assert BadEnum.A == enum_class.A + assert BadEnum.A.value == enum_class.A + assert BadEnum.A.value == enum_class.A.value + assert BadEnum(enum_class.A) is BadEnum.A + assert BadEnum(enum_class.A.value) is BadEnum.A assert not BadEnum == enum_class # We will always PUT BadEnum by String, and GET GeneratedChoices by index, # so shouldn't ever run across this from conversion code, but may occur if # casting returned values or passing as enum rather than value. with pytest.raises(ValueError): - BadEnum(ExtendedGeneratedChoices.d) + BadEnum(ExtendedGeneratedChoices.D) class EnumNoString(Enum): - a = "Aaa" + A = "Aaa" class SubsetEnumWrongChoices(SubsetEnum): - a = "Aaa" - b = "B" - c = "Ccc" + A = "Aaa" + B = "B" + C = "Ccc" @PARAMETERISE_PROTOCOLS @@ -612,7 +612,7 @@ async def test_backend_put_enum_string(ioc, protocol) -> None: backend = device.enum2._connector.backend # Don't do this in production code, but allow on CLI await backend.put("Ccc", wait=True) # type: ignore - assert ExampleEnum.c == await backend.get_value() + assert ExampleEnum.C == await backend.get_value() @PARAMETERISE_PROTOCOLS @@ -626,7 +626,7 @@ async def test_backend_get_setpoint(ioc, protocol) -> None: device = await connect_example_device(ioc, protocol) backend = device.enum2._connector.backend await backend.put("Ccc", wait=True) - assert await backend.get_setpoint() == ExampleEnum.c + assert await backend.get_setpoint() == ExampleEnum.C def approx_table(datatype: type[Table], table: Table): @@ -647,14 +647,14 @@ async def test_pva_table(ioc) -> None: int=np.array([1, 8, -9, 32], np.int32), float=np.array([1.8, 8.2, -6, 32.9887], np.float64), str=["Hello", "World", "Foo", "Bar"], - enum=[ExampleEnum.a, ExampleEnum.b, ExampleEnum.a, ExampleEnum.c], + enum=[ExampleEnum.A, ExampleEnum.B, ExampleEnum.A, ExampleEnum.C], ) put = ExampleTable( bool=np.array([True, False], np.bool_), int=np.array([-5, 32], np.int32), float=np.array([8.5, -6.97], np.float64), str=["Hello", "Bat"], - enum=[ExampleEnum.c, ExampleEnum.b], + enum=[ExampleEnum.C, ExampleEnum.B], ) # Make and connect the backend for t, i, p in [(ExampleTable, initial, put), (None, put, initial)]: @@ -775,7 +775,7 @@ async def test_str_enum_returns_enum(ioc, protocol): device = await connect_example_device(ioc, protocol) val = await device.enum.get_value() assert repr(val) == "" - assert val is ExampleEnum.b + assert val is ExampleEnum.B assert val == "Bbb" diff --git a/tests/fastcs/panda/test_panda_control.py b/tests/fastcs/panda/test_panda_control.py index 4f9bb8c546..867d97330a 100644 --- a/tests/fastcs/panda/test_panda_control.py +++ b/tests/fastcs/panda/test_panda_control.py @@ -30,7 +30,7 @@ class PcapBlock(Device): with patch("ophyd_async.fastcs.panda._control.wait_for_value", return_value=None): with pytest.raises(AttributeError) as exc: await pandaController.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.constant_gate) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.CONSTANT_GATE) ) await pandaController.arm() assert ("'PcapBlock' object has no attribute 'arm'") in str(exc.value) @@ -40,7 +40,7 @@ async def test_panda_controller_arm_disarm(mock_panda): pandaController = PandaPcapController(mock_panda.pcap) with patch("ophyd_async.fastcs.panda._control.wait_for_value", return_value=None): await pandaController.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.constant_gate) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.CONSTANT_GATE) ) await pandaController.arm() await pandaController.wait_for_idle() @@ -51,5 +51,5 @@ async def test_panda_controller_wrong_trigger(): pandaController = PandaPcapController(None) with pytest.raises(AssertionError): await pandaController.prepare( - TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.internal) + TriggerInfo(number_of_triggers=1, trigger=DetectorTrigger.INTERNAL) ) diff --git a/tests/fastcs/panda/test_trigger.py b/tests/fastcs/panda/test_trigger.py index f12b5f6051..af92c817f2 100644 --- a/tests/fastcs/panda/test_trigger.py +++ b/tests/fastcs/panda/test_trigger.py @@ -57,7 +57,7 @@ async def test_pcomp_trigger_logic(mock_panda): pulse_width=1, rising_edge_step=1, number_of_pulses=5, - direction=PcompDirection.positive, + direction=PcompDirection.POSITIVE, ) async def set_active(value: bool):