|
| 1 | +import unittest |
| 2 | +from Util_Functions import wind_degree_to_direction, unix_timestamp_to_localtime, convert_temperature |
| 3 | + |
| 4 | + |
| 5 | +class MyTestCase(unittest.TestCase): |
| 6 | + def test_wind_degree_to_direction(self): |
| 7 | + self.assertEqual("ENE", wind_degree_to_direction("60")) |
| 8 | + self.assertEqual("SE", wind_degree_to_direction("130")) |
| 9 | + self.assertEqual("W", wind_degree_to_direction("280")) |
| 10 | + |
| 11 | + def test_wind_degree_to_direction_parameter_format_error(self): |
| 12 | + self.assertEqual("API Wind Degree data format error!", |
| 13 | + wind_degree_to_direction("abc")) |
| 14 | + |
| 15 | + def test_unix_timestamp_to_localtime(self): |
| 16 | + self.assertEqual("2024-06-07 07:11:56", |
| 17 | + unix_timestamp_to_localtime("1717715516", "28800")) |
| 18 | + |
| 19 | + def test_unix_timestamp_to_localtime_unix_timestamp_format_error(self): |
| 20 | + self.assertEqual("API sunset/sunrise data format error!", |
| 21 | + unix_timestamp_to_localtime("abc", "28800")) |
| 22 | + |
| 23 | + def test_unix_timestamp_to_localtime_timezone_format_error(self): |
| 24 | + self.assertEqual("API timezone data format error!", |
| 25 | + unix_timestamp_to_localtime("1717715516", "abc")) |
| 26 | + |
| 27 | + def test_convert_temperature_to_celsius(self): |
| 28 | + self.assertEqual("15.44 °C", |
| 29 | + convert_temperature("288.59", "C")) |
| 30 | + |
| 31 | + def test_convert_temperature_to_fahrenheit(self): |
| 32 | + self.assertEqual("59.79 °F", |
| 33 | + convert_temperature("288.59", "F")) |
| 34 | + |
| 35 | + def test_convert_temperature_temperature_format_error(self): |
| 36 | + self.assertEqual("API temperature data format error!", |
| 37 | + convert_temperature("abc", "F")) |
| 38 | + |
| 39 | + def test_convert_temperature_temperature_unit_error(self): |
| 40 | + self.assertEqual("Temperature unit must either be 'C' or be 'F'!", |
| 41 | + convert_temperature("288.59", "H")) |
| 42 | + |
| 43 | + |
| 44 | +if __name__ == '__main__': |
| 45 | + unittest.main() |
0 commit comments