Debian Codegraph @

tests/test_weather.py

raw symbols SCIP
1 import datetime
2 import pytest
3 from meteoclimatic import Condition, Weather
4
5
6 class TestWeather:
7
8 _test_dict = {'reference_time': datetime.datetime(2020, 6, 9, 10, 30, 56, tzinfo=datetime.timezone.utc),
9 'condition': Condition.suncloud,
10 'temp_current': 20.9,
11 'temp_max': 21.0,
12 'temp_min': 13.7,
13 'humidity_current': 55.0,
14 'humidity_max': 80.0,
15 'humidity_min': 54.0,
16 'pressure_current': 1015.3,
17 'pressure_max': 1015.3,
18 'pressure_min': 1014.0,
19 'wind_current': 16.0,
20 'wind_max': 31.0,
21 'wind_bearing': 268.0,
22 'rain': 0.2}
23
24 def test_init_ok(self):
25 w = Weather(**self._test_dict)
26 assert w.wind_current == 16.0
27 assert w.condition == Condition.suncloud
28
29 @pytest.mark.parametrize("field_name,field_value,expected_error", [
30 ('reference_time', 123, 'reference_time is not an instance of datetime.datetime'),
31 ('humidity_current', -1.0, 'humidity must be between 0 and 100'),
32 ('humidity_current', 101.0, 'humidity must be between 0 and 100'),
33 ('humidity_max', -1.0, 'humidity must be between 0 and 100'),
34 ('humidity_max', 101.0, 'humidity must be between 0 and 100'),
35 ('humidity_min', -1.0, 'humidity must be between 0 and 100'),
36 ('humidity_min', 101.0, 'humidity must be between 0 and 100'),
37 ('wind_current', -1.0, 'wind must be greatear than 0'),
38 ('wind_max', -1.0, 'wind must be greatear than 0'),
39 ('wind_bearing', -0.1, 'wind bearing must be between 0 and 360'),
40 ('wind_bearing', 360.1, 'wind bearing must be between 0 and 360'),
41 ('rain', -1.0, 'rain must be greatear than 0')
42 ])
43 def test_init_fails_when_wrong_data_provided(self, field_name, field_value, expected_error):
44 d1 = self._test_dict.copy()
45 d1[field_name] = field_value
46 with pytest.raises(ValueError) as error:
47 Weather(**d1)
48 assert str(error.value) == expected_error
49
50 def test_init_when_data_fields_are_none(self):
51 d1 = self._test_dict.copy()
52 for k in d1.keys():
53 if k != 'reference_time':
54 d1[k] = None
55 w = Weather(**d1)
56 assert w.wind_bearing is None