def test_unlimited(self):
        n = Ints()

        for v in self.ints:
            n.validate(v)

        for v in self.not_ints:
            with self.assertRaises(TypeError):
                n.validate(v)
Esempio n. 2
0
def test_unlimited():
    n = Ints()
    n.validate(n.valid_values[0])

    for v in ints:
        n.validate(v)

    for v in not_ints:
        with pytest.raises(TypeError):
            n.validate(v)
    def test_max(self):
        for max_val in self.ints:
            n = Ints(max_value=max_val)
            for v in self.ints:
                if v <= max_val:
                    n.validate(v)
                else:
                    with self.assertRaises(ValueError):
                        n.validate(v)

        for v in self.not_ints:
            with self.assertRaises(TypeError):
                n.validate(v)
Esempio n. 4
0
def test_max():
    for max_val in ints:
        n = Ints(max_value=max_val)
        for v in ints:
            if v <= max_val:
                n.validate(v)
            else:
                with pytest.raises(ValueError):
                    n.validate(v)

    for v in not_ints:
        with pytest.raises(TypeError):
            n.validate(v)
    def test_range(self):
        n = Ints(0, 10)

        for v in self.ints:
            if 0 <= v <= 10:
                n.validate(v)
            else:
                with self.assertRaises(ValueError):
                    n.validate(v)

        for v in self.not_ints:
            with self.assertRaises(TypeError):
                n.validate(v)

        self.assertEqual(repr(n), '<Ints 0<=v<=10>')
        self.assertTrue(n.is_numeric)
Esempio n. 6
0
def test_range():
    n = Ints(0, 10)

    for v in ints:
        if 0 <= v <= 10:
            n.validate(v)
        else:
            with pytest.raises(ValueError):
                n.validate(v)

    for v in not_ints:
        with pytest.raises(TypeError):
            n.validate(v)

    assert repr(n) == '<Ints 0<=v<=10>'
    assert n.is_numeric
Esempio n. 7
0
class VectorMode(InstrumentChannel):
    """
    Class to control motors in vector mode
    """
    def __init__(self, parent: "DMC4133Controller", name: str,
                 **kwargs: Any) -> None:
        """
        Initializes the vector mode submodule for the controller

        Args:
            parent: an instance of DMC4133Controller
            name: name of the vector mode plane
        """
        super().__init__(parent, name, **kwargs)
        self._plane = name
        self._vector_position_validator = Ints(min_value=-2147483648,
                                               max_value=2147483647)

        self.add_parameter(
            "coordinate_system",
            get_cmd="CA ?",
            get_parser=self._parse_coordinate_system_active,
            set_cmd="CA {}",
            vals=Enum("S", "T"),
            docstring="activates coordinate system for the motion. Two "
            " coordinate systems are possible with values "
            "'S' and 'T'. All vector mode commands will apply to "
            "the active coordinate system.",
        )

        self.add_parameter(
            "vector_acceleration",
            get_cmd="VA ?",
            get_parser=lambda s: int(float(s)),
            set_cmd="VA {}",
            vals=Multiples(min_value=1024, max_value=1073740800, divisor=1024),
            unit="counts/sec2",
            docstring="sets and gets the defined vector's acceleration",
        )

        self.add_parameter(
            "vector_deceleration",
            get_cmd="VD ?",
            get_parser=lambda s: int(float(s)),
            set_cmd="VD {}",
            vals=Multiples(min_value=1024, max_value=1073740800, divisor=1024),
            unit="counts/sec2",
            docstring="sets and gets the defined vector's deceleration",
        )

        self.add_parameter(
            "vector_speed",
            get_cmd="VS ?",
            get_parser=lambda s: int(float(s)),
            set_cmd="VS {}",
            vals=Multiples(min_value=2, max_value=15000000, divisor=2),
            unit="counts/sec",
            docstring="sets and gets defined vector's speed",
        )

    @staticmethod
    def _parse_coordinate_system_active(val: str) -> str:
        """
        parses the current active coordinate system
        """
        if int(float(val)):
            return "T"
        else:
            return "S"

    def activate(self) -> None:
        """
        activate plane of motion
        """
        self.write(f"VM {self._plane}")

    def vector_position(self, first_coord: int, second_coord: int) -> None:
        """
        sets the final vector position for the motion considering current
        position as the origin
        """
        self._vector_position_validator.validate(first_coord)
        self._vector_position_validator.validate(second_coord)

        self.write(f"VP {first_coord},{second_coord}")

    def vector_seq_end(self) -> None:
        """
        indicates to the controller that the end of the vector is coming up.
        is required to exit the vector mode gracefully
        """
        self.write("VE")

    def begin_seq(self) -> None:
        """
        begins motion of the motor
        """
        self.write("BG S")

    def after_seq_motion(self) -> None:
        """
        wait till motion ends
        """
        self.write("AM S")

    def clear_sequence(self, coord_sys: str) -> None:
        """
        clears vectors specified in the given coordinate system
        """
        if coord_sys not in ["S", "T"]:
            raise RuntimeError(f"possible coordinate systems are 'S' or 'T'. "
                               f"you provided the following value instead: "
                               f" '{coord_sys}'")

        self.write(f"CS {coord_sys}")
Esempio n. 8
0
 def test_valid_values(self):
     val = Ints()
     for vval in val.valid_values:
         val.validate(vval)