33
44"""Tests for the microgrid metadata types."""
55
6- from collections .abc import Iterator
7- from unittest .mock import MagicMock , patch
86from zoneinfo import ZoneInfo
97
108import pytest
1311from frequenz .client .microgrid import Location , Metadata
1412
1513
16- @pytest .fixture
17- def timezone_finder () -> Iterator [MagicMock ]:
18- """Return a mock timezone finder."""
19- with patch (
20- "frequenz.client.microgrid._metadata._timezone_finder" , autospec = True
21- ) as mock_timezone_finder :
22- yield mock_timezone_finder
23-
24-
2514@pytest .mark .parametrize (
2615 "latitude, longitude, timezone" ,
2716 [
@@ -32,40 +21,29 @@ def timezone_finder() -> Iterator[MagicMock]:
3221 (52.52 , None , ZoneInfo (key = "UTC" )),
3322 (None , 13.405 , ZoneInfo (key = "UTC" )),
3423 (52.52 , 13.405 , ZoneInfo (key = "UTC" )),
24+ (52.52 , 13.405 , None ),
3525 ],
3626 ids = str ,
3727)
38- def test_location_timezone_not_looked_up_if_not_possible_or_necessary (
39- timezone_finder : MagicMock ,
28+ def test_location_timezone_behavior (
4029 latitude : float | None ,
4130 longitude : float | None ,
4231 timezone : ZoneInfo | None ,
4332) -> None :
44- """Test the location timezone is not looked up if is not necessary or possible."""
45- timezone_finder .timezone_at .return_value = "Europe/Berlin"
46-
33+ """Test the location timezone behavior with different inputs."""
4734 location = Location (latitude = latitude , longitude = longitude , timezone = timezone )
4835
4936 assert location .latitude == latitude
5037 assert location .longitude == longitude
5138 assert location .timezone == timezone
52- timezone_finder .timezone_at .assert_not_called ()
5339
5440
55- @pytest .mark .parametrize ("timezone" , [None , "Europe/Berlin" ], ids = str )
56- def test_location_timezone_lookup (
57- timezone_finder : MagicMock , timezone : str | None
58- ) -> None :
59- """Test the location timezone is looked up if not provided and there is enough info."""
60- timezone_finder .timezone_at .return_value = timezone
61-
41+ def test_location_timezone_remains_none_when_not_provided () -> None :
42+ """Test that timezone remains None when not explicitly provided, even with lat/lng."""
6243 location = Location (latitude = 52.52 , longitude = 13.405 )
63-
64- if timezone is None :
65- assert location .timezone is None
66- else :
67- assert location .timezone == ZoneInfo (key = timezone )
68- timezone_finder .timezone_at .assert_called_once_with (lat = 52.52 , lng = 13.405 )
44+
45+ # Timezone should remain None since automatic lookup is no longer performed
46+ assert location .timezone is None
6947
7048
7149def test_metadata_initialization () -> None :
@@ -81,11 +59,12 @@ def test_metadata_initialization() -> None:
8159 assert metadata .microgrid_id == microgrid_id
8260 assert metadata .location is None
8361
84- # Test with only location
62+ # Test with only location - timezone should be None even with lat/lng
8563 location = Location (latitude = 52.52 , longitude = 13.405 )
8664 metadata = Metadata (location = location )
8765 assert metadata .microgrid_id is None
8866 assert metadata .location == location
67+ assert metadata .location .timezone is None
8968
9069 # Test with both parameters
9170 metadata = Metadata (microgrid_id = microgrid_id , location = location )
0 commit comments