def test_eq(): temp1 = Variable("temperature", 13.5, "celsius") temp2 = Variable("temperature", 13.5, "celsius") temp3 = Variable("temperature", 10, "celsius") wind1 = Variable("wind_speed", 13.5, "m/s") temp_fahrenheit = Variable("temperature", 13.5, "fahrenheit") assert temp1 == temp2 assert temp1 != temp3 assert temp1 != wind1 assert temp1 != temp_fahrenheit
def test_lt(): temp1 = Variable("temperature", 13.5, "celsius") temp2 = Variable("temperature", 13.5, "celsius") temp3 = Variable("temperature", 15, "celsius") wind1 = Variable("wind_speed", 13.5, "m/s") temp_fahrenheit = Variable("temperature", 15, "fahrenheit") assert temp1 <= temp2 # type: ignore assert temp1 < 14 assert temp1 < temp3 assert temp3 > temp1 with pytest.raises(TypeError): temp1 < wind1 with pytest.raises(TypeError): temp1 < temp_fahrenheit
def generic_interval_copy(): start = dt.datetime(year=2020, month=1, day=1, hour=12) end = dt.datetime(year=2020, month=1, day=1, hour=16) symbol_code = "cloudy" var1 = Variable("temperature", 12.5, "celsius") var2 = Variable("wind_speed", 3.2, "m/s") var3 = Variable("wind_direction", 90, "degrees") variables = { "temperature": var1, "wind_speed": var2, "wind_direction": var3, } return Interval(start, end, symbol_code, variables)
def test_sub(): temp1 = Variable("temperature", 2, "celsius") temp2 = Variable("temperature", 3, "celsius") temp3 = Variable("temperature", 10.5, "celsius") wind1 = Variable("wind_speed", 13.5, "m/s") temp_fahrenheit = Variable("temperature", 13.5, "fahrenheit") assert Variable("temperature", -1, "celsius") == temp1 - temp2 assert Variable("temperature", -8.5, "celsius") == temp1 - temp3 with pytest.raises(TypeError): temp1 - wind1 with pytest.raises(TypeError): temp1 - temp_fahrenheit
def test_mps_to_kph(): zero = Variable("speed", 0, "m/s") slow = Variable("speed", 3, "m/s") fast = Variable("speed", 15.2, "m/s") error = Variable("", 0, "other") zero._mps_to_kph() slow._mps_to_kph() fast._mps_to_kph() assert zero.value == 0.0 assert slow.value == 10.8 assert fast.value == 54.72 assert zero.units == "km/h" with pytest.raises(ValueError): error._mps_to_kph()
def test_celsius_to_fahrenheit(): freezing = Variable("temperature", 0, "celsius") boiling = Variable("temperature", 100, "celsius") other = Variable("temperature", 37.5, "celsius") error = Variable("", 0, "other") freezing._celsius_to_fahrenheit() boiling._celsius_to_fahrenheit() other._celsius_to_fahrenheit() assert freezing.value == 32.0 assert boiling.value == 212.0 assert other.value == 99.5 assert freezing.units == "fahrenheit" with pytest.raises(ValueError): error._celsius_to_fahrenheit()
def test_repr(): temperature = Variable("temperature", 13.5, "celsius") assert repr(temperature) == "Variable(temperature, 13.5, celsius)"
def ten_mps(self): return Variable("speed", 10, "m/s")
def zero_celsius(self): return Variable("temperature", 0, "celsius")
def test_str(): temperature = Variable("temperature", 13.5, "celsius") assert str(temperature) == "temperature: 13.5celsius"