Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
pressure("A2995")
with pytest.raises(UnitsError):
pressure("1000", "bars")
with pytest.raises(UnitsError):
pressure(pressure("30.00").value, "psi")
with pytest.raises(UnitsError):
pressure(pressure("32.00").string, "atm")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
speed("10KT")
with pytest.raises(ValueError):
speed("10", "MPS", "=")
with pytest.raises(ValueError):
speed("60", "KT", "gt")
with pytest.raises(UnitsError):
speed("10", "NM")
with pytest.raises(UnitsError):
speed(speed("10").value, "furlongs per fortnight")
with pytest.raises(UnitsError):
speed(speed("5").string, "fps")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
speed("10KT")
with pytest.raises(ValueError):
speed("10", "MPS", "=")
with pytest.raises(ValueError):
speed("60", "KT", "gt")
with pytest.raises(UnitsError):
speed("10", "NM")
with pytest.raises(UnitsError):
speed(speed("10").value, "furlongs per fortnight")
with pytest.raises(UnitsError):
speed(speed("5").string, "fps")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
distance("10SM")
with pytest.raises(ValueError):
distance("M1/2SM")
with pytest.raises(ValueError):
distance("1000", "M", "=")
with pytest.raises(ValueError):
distance("1000", "M", "gt")
with pytest.raises(UnitsError):
distance("10", "NM")
with pytest.raises(UnitsError):
distance(distance("1000").value, "furlongs")
with pytest.raises(UnitsError):
distance(distance("500").string, "yards")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
temperature("32C")
with pytest.raises(ValueError):
temperature("M10F")
with pytest.raises(UnitsError):
temperature("32", "J")
with pytest.raises(UnitsError):
temperature(temperature("32").value, "J")
with pytest.raises(UnitsError):
temperature(temperature("32").string, "J")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
pressure("A2995")
with pytest.raises(UnitsError):
pressure("1000", "bars")
with pytest.raises(UnitsError):
pressure(pressure("30.00").value, "psi")
with pytest.raises(UnitsError):
pressure(pressure("32.00").string, "atm")
def test_error_checking():
"""Test exception raising."""
with pytest.raises(ValueError):
temperature("32C")
with pytest.raises(ValueError):
temperature("M10F")
with pytest.raises(UnitsError):
temperature("32", "J")
with pytest.raises(UnitsError):
temperature(temperature("32").value, "J")
with pytest.raises(UnitsError):
temperature(temperature("32").string, "J")
def string(self, units=None):
"""Return a string representation of the speed in the given units."""
if not units:
units = self._units
else:
if units.upper() not in speed.legal_units:
raise UnitsError("unrecognized speed unit: '" + units + "'")
units = units.upper()
val = self.value(units)
if units == "KMH":
text = "%.0f km/h" % val
elif units == "KT":
text = "%.0f knots" % val
elif units == "MPH":
text = "%.0f mph" % val
elif units == "MPS":
text = "%.0f mps" % val
if self._gtlt == ">":
text = "greater than " + text
elif self._gtlt == "<":
text = "less than " + text
return text
def value(self, units=None):
"""Return the distance in the specified units."""
if not units:
return self._value
else:
if not units.upper() in distance.legal_units:
raise UnitsError("unrecognized distance unit: '" + units + "'")
units = units.upper()
if units == self._units:
return self._value
if self._units == "SM" or self._units == "MI":
m_value = self._value * 1609.344
elif self._units == "FT":
m_value = self._value / 3.28084
elif self._units == "IN":
m_value = self._value / 39.3701
elif self._units == "KM":
m_value = self._value * 1000
else:
m_value = self._value
if units == "SM" or units == "MI":
return m_value / 1609.344
elif units == "FT":
def value(self, units=None):
"""Return the temperature in the specified units."""
if units is None:
return self._value
else:
if not units.upper() in temperature.legal_units:
raise UnitsError("unrecognized temperature unit: '" + units + "'")
units = units.upper()
if self._units == "C":
celsius_value = self._value
elif self._units == "F":
celsius_value = (self._value - 32.0) / 1.8
elif self._units == "K":
celsius_value = self._value - 273.15
if units == "C":
return celsius_value
elif units == "K":
return 273.15 + celsius_value
elif units == "F":
return 32.0 + celsius_value * 1.8