Esempio n. 1
0
    def add_volume(self, vol: Unit):
        """
        Updates the volume of the well

        Parameters
        ----------
        vol : str, Unit
            Theoretical volume to indicate for a Well.

        Returns
        -------
        Unit
            the updated volume of the Well

        Raises
        ------
        TypeError
            Error when input does not match expected type or dimensionality
        ValueError
            Volume set exceeds maximum well volume
        """

        v = parse_unit(vol)

        if self.volume:
            self.volume += v
        else:
            self.volume = v
        return self.volume
Esempio n. 2
0
    def set_mass(self, mass):
        """
        Set the theoretical mass of contents in a Well.

        Parameters
        ----------
        mass : str, Unit
            Theoretical mass to indicate for a Well.

        Returns
        -------
        Well
            Well with modified mass

        Raises
        ------
        TypeError
            Incorrect input-type given
        """
        if mass is None:
            # Set mass as None if no mass is known, as this is different from a mass of 0:mg
            self.mass = None
            return self

        if not isinstance(mass, str) and not isinstance(mass, Unit):
            raise TypeError(
                f"Mass {mass} is of type {type(mass)}, it should be either "
                f"'str' or 'Unit'.")
        m = parse_unit(mass)
        self.mass = m

        return self
Esempio n. 3
0
    def __new__(cls, name, volume):
        """
        Parameters
        ----------
        name : str
          Full name describing a TipType.
        volume : Unit
          The maximum capacity of the TipType.

        Returns
        -------
        TipType
            A tip type compatible with LiquidHandleMethods

        Raises
        ------
        TypeError
            if the name is not a str

        See Also
        --------
        :py:class: `autoprotocol.LiquidHandleMethod._get_tip_types`
        """
        if not isinstance(name, str):
            raise TypeError("TipType name {} was not a str.".format(name))
        volume = parse_unit(volume, "uL")
        return super(TipType, cls).__new__(cls, name, volume)
    def test_accepted_unit(self):
        assert Unit("1:ul") == parse_unit("1:ul", "ml")
        assert Unit("1:ul") == parse_unit("1:ul", "milliliter")
        assert Unit("1:ul") == parse_unit("1:ul", "1:ml")
        assert Unit("1:ul") == parse_unit("1:ul", ["kg", "ml"])

        assert Unit("1:ul") == parse_unit(Unit("1:ul"), "ml")

        with pytest.raises(TypeError):
            parse_unit("1:ul", "second")

        with pytest.raises(TypeError):
            parse_unit("1:ul", ["second", "kg"])
    def test_casting_to_unit(self):
        assert Unit("1:second") == parse_unit("1:second")
        assert Unit("1:ul") == parse_unit("1:microliter")

        with pytest.raises(TypeError):
            parse_unit("1 second")