| 1 | import pytest |
| 2 | from meteoclimatic import Station |
| 3 | |
| 4 | |
| 5 | class TestStation: |
| 6 | |
| 7 | _test_dict = {"name": "Reus - Nord (Tarragona)", |
| 8 | "code": "ESCAT4300000043206B", |
| 9 | "url": "http://www.meteoclimatic.net/perfil/ESCAT4300000043206B"} |
| 10 | |
| 11 | def test_init_ok(self): |
| 12 | s = Station(**self._test_dict) |
| 13 | assert s.name == "Reus - Nord (Tarragona)" |
| 14 | assert s.code == "ESCAT4300000043206B" |
| 15 | assert s.url == "http://www.meteoclimatic.net/perfil/ESCAT4300000043206B" |
| 16 | |
| 17 | @pytest.mark.parametrize("field_name,field_value,expected_error", [ |
| 18 | ("name", "", "Station name cannot be empty"), |
| 19 | ("name", None, "Station name cannot be empty"), |
| 20 | ("code", "", "Station code cannot be empty"), |
| 21 | ("code", None, "Station code cannot be empty") |
| 22 | ]) |
| 23 | def test_init_fails_when_wrong_data_provided(self, field_name, field_value, expected_error): |
| 24 | d1 = self._test_dict.copy() |
| 25 | d1[field_name] = field_value |
| 26 | with pytest.raises(ValueError) as error: |
| 27 | Station(**d1) |
| 28 | assert str(error.value) == expected_error |