Ejemplo n.º 1
0
def current_driver(magnet_axes_instances):
    """
    Instantiate AMI430_3D instrument with the three mock instruments
    representing current drivers for the x, y, and z directions.
    """
    mag_x, mag_y, mag_z = magnet_axes_instances

    driver = AMI430_3D("AMI430-3D", mag_x, mag_y, mag_z, field_limit)

    yield driver

    driver.close()
Ejemplo n.º 2
0
def test_instantiation_from_name_of_nonexistent_ami_instrument(
        magnet_axes_instances, request):
    mag_x, mag_y, mag_z = magnet_axes_instances
    request.addfinalizer(AMI430_3D.close_all)

    non_existent_instrument = mag_y.name + "foo"

    with pytest.raises(
            KeyError,
            match=f"with name {non_existent_instrument} does not exist"):
        AMI430_3D("AMI430-3D", mag_x.name, non_existent_instrument, mag_z.name,
                  field_limit)
Ejemplo n.º 3
0
def test_numeric_field_limit(magnet_axes_instances, field_limit, request):
    mag_x, mag_y, mag_z = magnet_axes_instances
    ami = AMI430_3D("AMI430-3D", mag_x, mag_y, mag_z, field_limit)
    request.addfinalizer(ami.close)

    assert isinstance(ami._field_limit, float)

    target_within_limit = (field_limit * 0.95, 0, 0)
    ami.cartesian(target_within_limit)

    target_outside_limit = (field_limit * 1.05, 0, 0)
    with pytest.raises(ValueError,
                       match="_set_fields aborted; field would exceed limit"):
        ami.cartesian(target_outside_limit)
Ejemplo n.º 4
0
def test_instantiation_from_names(magnet_axes_instances, request):
    """
    Instantiate AMI430_3D instrument from the three mock instruments
    representing current drivers for the x, y, and z directions by their
    names as opposed from their instances.
    """
    mag_x, mag_y, mag_z = magnet_axes_instances
    request.addfinalizer(AMI430_3D.close_all)

    driver = AMI430_3D("AMI430-3D", mag_x.name, mag_y.name, mag_z.name,
                       field_limit)

    assert driver._instrument_x is mag_x
    assert driver._instrument_y is mag_y
    assert driver._instrument_z is mag_z
Ejemplo n.º 5
0
def test_instantiation_from_badly_typed_argument(magnet_axes_instances,
                                                 request):
    mag_x, mag_y, mag_z = magnet_axes_instances
    request.addfinalizer(AMI430_3D.close_all)

    badly_typed_instrument_z_argument = 123

    with pytest.raises(ValueError,
                       match="instrument_z argument is neither of those"):
        AMI430_3D(
            "AMI430-3D",
            mag_x.name,
            mag_y,
            badly_typed_instrument_z_argument,
            field_limit,
        )
Ejemplo n.º 6
0
def test_instantiation_from_name_of_existing_non_ami_instrument(
        magnet_axes_instances, request):
    mag_x, mag_y, mag_z = magnet_axes_instances
    request.addfinalizer(AMI430_3D.close_all)

    non_ami_existing_instrument = Instrument("foo")

    with pytest.raises(
            TypeError,
            match=re.escape(
                f"Instrument {non_ami_existing_instrument.name} is "
                f"{type(non_ami_existing_instrument)} but {AMI430} "
                f"was requested"),
    ):
        AMI430_3D(
            "AMI430-3D",
            mag_x.name,
            non_ami_existing_instrument.name,
            mag_z.name,
            field_limit,
        )