Skip to content

Commit 1e5f1e4

Browse files
committed
Ruff formatting
1 parent df41adb commit 1e5f1e4

File tree

1 file changed

+146
-102
lines changed

1 file changed

+146
-102
lines changed

tests/test_config.py

Lines changed: 146 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
# Add the src directory to the path so we can import the modules
8-
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
8+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
99

1010
from config import DashboardConfig
1111
from owm.owm import WeatherUnits
@@ -17,26 +17,31 @@ class TestDashboardConfig:
1717
def setup_method(self):
1818
"""Clear any existing global config before each test."""
1919
import config
20+
2021
config._current_config = None
2122

22-
@patch.dict(os.environ, {
23-
'ICS_URL': 'https://example.com/calendar.ics',
24-
'OWM_API_KEY': 'test_api_key',
25-
'LAT': '37.7749',
26-
'LNG': '-122.4194'
27-
}, clear=True)
23+
@patch.dict(
24+
os.environ,
25+
{
26+
"ICS_URL": "https://example.com/calendar.ics",
27+
"OWM_API_KEY": "test_api_key",
28+
"LAT": "37.7749",
29+
"LNG": "-122.4194",
30+
},
31+
clear=True,
32+
)
2833
def test_init_with_minimal_required_env_vars(self):
2934
"""Test DashboardConfig initialization with only required environment variables."""
3035
config = DashboardConfig()
3136

3237
# Required variables
33-
assert config.ICS_URL == 'https://example.com/calendar.ics'
34-
assert config.OWM_API_KEY == 'test_api_key'
38+
assert config.ICS_URL == "https://example.com/calendar.ics"
39+
assert config.OWM_API_KEY == "test_api_key"
3540
assert config.LAT == 37.7749
3641
assert config.LNG == -122.4194
3742

3843
# Default values
39-
assert config.DISPLAY_TZ == 'America/Los_Angeles'
44+
assert config.DISPLAY_TZ == "America/Los_Angeles"
4045
assert config.NUM_CAL_DAYS_TO_QUERY == 30
4146
assert config.IMAGE_WIDTH == 1200
4247
assert config.IMAGE_HEIGHT == 825
@@ -45,29 +50,33 @@ def test_init_with_minimal_required_env_vars(self):
4550
assert config.SHOW_MOON_PHASE == False
4651
assert config.SHOW_CALENDAR_NAME == False
4752

48-
@patch.dict(os.environ, {
49-
'ICS_URL': 'https://example.com/calendar.ics',
50-
'OWM_API_KEY': 'test_api_key',
51-
'LAT': '40.7128',
52-
'LNG': '-74.0060',
53-
'DISPLAY_TZ': 'America/New_York',
54-
'NUM_CAL_DAYS_TO_QUERY': '45',
55-
'IMAGE_WIDTH': '1600',
56-
'IMAGE_HEIGHT': '900',
57-
'WEATHER_UNITS': 'imperial',
58-
'SHOW_ADDITIONAL_WEATHER': 'true',
59-
'SHOW_MOON_PHASE': 'True',
60-
'SHOW_CALENDAR_NAME': 'TRUE'
61-
}, clear=True)
53+
@patch.dict(
54+
os.environ,
55+
{
56+
"ICS_URL": "https://example.com/calendar.ics",
57+
"OWM_API_KEY": "test_api_key",
58+
"LAT": "40.7128",
59+
"LNG": "-74.0060",
60+
"DISPLAY_TZ": "America/New_York",
61+
"NUM_CAL_DAYS_TO_QUERY": "45",
62+
"IMAGE_WIDTH": "1600",
63+
"IMAGE_HEIGHT": "900",
64+
"WEATHER_UNITS": "imperial",
65+
"SHOW_ADDITIONAL_WEATHER": "true",
66+
"SHOW_MOON_PHASE": "True",
67+
"SHOW_CALENDAR_NAME": "TRUE",
68+
},
69+
clear=True,
70+
)
6271
def test_init_with_all_env_vars_set(self):
6372
"""Test DashboardConfig initialization with all environment variables set."""
6473
config = DashboardConfig()
6574

66-
assert config.ICS_URL == 'https://example.com/calendar.ics'
67-
assert config.OWM_API_KEY == 'test_api_key'
75+
assert config.ICS_URL == "https://example.com/calendar.ics"
76+
assert config.OWM_API_KEY == "test_api_key"
6877
assert config.LAT == 40.7128
6978
assert config.LNG == -74.0060
70-
assert config.DISPLAY_TZ == 'America/New_York'
79+
assert config.DISPLAY_TZ == "America/New_York"
7180
assert config.NUM_CAL_DAYS_TO_QUERY == 45
7281
assert config.IMAGE_WIDTH == 1600
7382
assert config.IMAGE_HEIGHT == 900
@@ -77,7 +86,7 @@ def test_init_with_all_env_vars_set(self):
7786
assert config.SHOW_CALENDAR_NAME == True
7887

7988
@patch.dict(os.environ, {}, clear=True)
80-
@patch('config.logger')
89+
@patch("config.logger")
8190
def test_missing_ics_url_exits(self, mock_logger):
8291
"""Test that missing ICS_URL causes system exit."""
8392
with pytest.raises(SystemExit) as exc_info:
@@ -86,10 +95,8 @@ def test_missing_ics_url_exits(self, mock_logger):
8695
assert exc_info.value.code == 1
8796
mock_logger.error.assert_called_with("ICS_URL needs to be set.")
8897

89-
@patch.dict(os.environ, {
90-
'ICS_URL': 'https://example.com/calendar.ics'
91-
}, clear=True)
92-
@patch('config.logger')
98+
@patch.dict(os.environ, {"ICS_URL": "https://example.com/calendar.ics"}, clear=True)
99+
@patch("config.logger")
93100
def test_missing_owm_api_key_exits(self, mock_logger):
94101
"""Test that missing OWM_API_KEY causes system exit."""
95102
with pytest.raises(SystemExit) as exc_info:
@@ -98,11 +105,12 @@ def test_missing_owm_api_key_exits(self, mock_logger):
98105
assert exc_info.value.code == 1
99106
mock_logger.error.assert_called_with("OWM_API_KEY needs to be set.")
100107

101-
@patch.dict(os.environ, {
102-
'ICS_URL': 'https://example.com/calendar.ics',
103-
'OWM_API_KEY': 'test_api_key'
104-
}, clear=True)
105-
@patch('config.logger')
108+
@patch.dict(
109+
os.environ,
110+
{"ICS_URL": "https://example.com/calendar.ics", "OWM_API_KEY": "test_api_key"},
111+
clear=True,
112+
)
113+
@patch("config.logger")
106114
def test_missing_lat_lng_exits(self, mock_logger):
107115
"""Test that missing LAT and LNG causes system exit."""
108116
with pytest.raises(SystemExit) as exc_info:
@@ -111,12 +119,16 @@ def test_missing_lat_lng_exits(self, mock_logger):
111119
assert exc_info.value.code == 1
112120
mock_logger.error.assert_called_with("LAT and LNG need to be set.")
113121

114-
@patch.dict(os.environ, {
115-
'ICS_URL': 'https://example.com/calendar.ics',
116-
'OWM_API_KEY': 'test_api_key',
117-
'LAT': '37.7749'
118-
}, clear=True)
119-
@patch('config.logger')
122+
@patch.dict(
123+
os.environ,
124+
{
125+
"ICS_URL": "https://example.com/calendar.ics",
126+
"OWM_API_KEY": "test_api_key",
127+
"LAT": "37.7749",
128+
},
129+
clear=True,
130+
)
131+
@patch("config.logger")
120132
def test_missing_lng_only_exits(self, mock_logger):
121133
"""Test that missing only LNG (with LAT present) causes system exit."""
122134
with pytest.raises(SystemExit) as exc_info:
@@ -125,12 +137,16 @@ def test_missing_lng_only_exits(self, mock_logger):
125137
assert exc_info.value.code == 1
126138
mock_logger.error.assert_called_with("LAT and LNG need to be set.")
127139

128-
@patch.dict(os.environ, {
129-
'ICS_URL': 'https://example.com/calendar.ics',
130-
'OWM_API_KEY': 'test_api_key',
131-
'LNG': '-122.4194'
132-
}, clear=True)
133-
@patch('config.logger')
140+
@patch.dict(
141+
os.environ,
142+
{
143+
"ICS_URL": "https://example.com/calendar.ics",
144+
"OWM_API_KEY": "test_api_key",
145+
"LNG": "-122.4194",
146+
},
147+
clear=True,
148+
)
149+
@patch("config.logger")
134150
def test_missing_lat_only_exits(self, mock_logger):
135151
"""Test that missing only LAT (with LNG present) causes system exit."""
136152
with pytest.raises(SystemExit) as exc_info:
@@ -139,15 +155,19 @@ def test_missing_lat_only_exits(self, mock_logger):
139155
assert exc_info.value.code == 1
140156
mock_logger.error.assert_called_with("LAT and LNG need to be set.")
141157

142-
@patch.dict(os.environ, {
143-
'ICS_URL': 'https://example.com/calendar.ics',
144-
'OWM_API_KEY': 'test_api_key',
145-
'LAT': '37.7749',
146-
'LNG': '-122.4194',
147-
'SHOW_ADDITIONAL_WEATHER': 'false',
148-
'SHOW_MOON_PHASE': 'False',
149-
'SHOW_CALENDAR_NAME': 'NotTrue'
150-
}, clear=True)
158+
@patch.dict(
159+
os.environ,
160+
{
161+
"ICS_URL": "https://example.com/calendar.ics",
162+
"OWM_API_KEY": "test_api_key",
163+
"LAT": "37.7749",
164+
"LNG": "-122.4194",
165+
"SHOW_ADDITIONAL_WEATHER": "false",
166+
"SHOW_MOON_PHASE": "False",
167+
"SHOW_CALENDAR_NAME": "NotTrue",
168+
},
169+
clear=True,
170+
)
151171
def test_boolean_env_vars_false_values(self):
152172
"""Test boolean environment variables with various false values."""
153173
config = DashboardConfig()
@@ -156,28 +176,36 @@ def test_boolean_env_vars_false_values(self):
156176
assert config.SHOW_MOON_PHASE == False
157177
assert config.SHOW_CALENDAR_NAME == False
158178

159-
@patch.dict(os.environ, {
160-
'ICS_URL': 'https://example.com/calendar.ics',
161-
'OWM_API_KEY': 'test_api_key',
162-
'LAT': '-90.0',
163-
'LNG': '180.0'
164-
}, clear=True)
179+
@patch.dict(
180+
os.environ,
181+
{
182+
"ICS_URL": "https://example.com/calendar.ics",
183+
"OWM_API_KEY": "test_api_key",
184+
"LAT": "-90.0",
185+
"LNG": "180.0",
186+
},
187+
clear=True,
188+
)
165189
def test_extreme_lat_lng_values(self):
166190
"""Test with extreme but valid latitude and longitude values."""
167191
config = DashboardConfig()
168192

169193
assert config.LAT == -90.0
170194
assert config.LNG == 180.0
171195

172-
@patch.dict(os.environ, {
173-
'ICS_URL': 'https://example.com/calendar.ics',
174-
'OWM_API_KEY': 'test_api_key',
175-
'LAT': '37.7749',
176-
'LNG': '-122.4194',
177-
'NUM_CAL_DAYS_TO_QUERY': '0',
178-
'IMAGE_WIDTH': '1',
179-
'IMAGE_HEIGHT': '1'
180-
}, clear=True)
196+
@patch.dict(
197+
os.environ,
198+
{
199+
"ICS_URL": "https://example.com/calendar.ics",
200+
"OWM_API_KEY": "test_api_key",
201+
"LAT": "37.7749",
202+
"LNG": "-122.4194",
203+
"NUM_CAL_DAYS_TO_QUERY": "0",
204+
"IMAGE_WIDTH": "1",
205+
"IMAGE_HEIGHT": "1",
206+
},
207+
clear=True,
208+
)
181209
def test_integer_edge_cases(self):
182210
"""Test integer environment variables with edge case values."""
183211
config = DashboardConfig()
@@ -186,7 +214,7 @@ def test_integer_edge_cases(self):
186214
assert config.IMAGE_WIDTH == 1
187215
assert config.IMAGE_HEIGHT == 1
188216

189-
@patch('config.DashboardConfig.__init__')
217+
@patch("config.DashboardConfig.__init__")
190218
def test_get_config_singleton_pattern(self, mock_init):
191219
"""Test that get_config() implements singleton pattern correctly."""
192220
mock_init.return_value = None
@@ -202,52 +230,68 @@ def test_get_config_singleton_pattern(self, mock_init):
202230

203231
def test_get_config_returns_same_instance(self):
204232
"""Test that get_config returns the same instance on multiple calls."""
205-
with patch.dict(os.environ, {
206-
'ICS_URL': 'https://example.com/calendar.ics',
207-
'OWM_API_KEY': 'test_api_key',
208-
'LAT': '37.7749',
209-
'LNG': '-122.4194'
210-
}, clear=True):
233+
with patch.dict(
234+
os.environ,
235+
{
236+
"ICS_URL": "https://example.com/calendar.ics",
237+
"OWM_API_KEY": "test_api_key",
238+
"LAT": "37.7749",
239+
"LNG": "-122.4194",
240+
},
241+
clear=True,
242+
):
211243
config1 = DashboardConfig.get_config()
212244
config2 = DashboardConfig.get_config()
213245

214246
assert config1 is config2
215247
assert id(config1) == id(config2)
216248

217-
@patch.dict(os.environ, {
218-
'ICS_URL': 'https://example.com/calendar.ics',
219-
'OWM_API_KEY': 'test_api_key',
220-
'LAT': '37.7749',
221-
'LNG': '-122.4194',
222-
'WEATHER_UNITS': 'metric'
223-
}, clear=True)
249+
@patch.dict(
250+
os.environ,
251+
{
252+
"ICS_URL": "https://example.com/calendar.ics",
253+
"OWM_API_KEY": "test_api_key",
254+
"LAT": "37.7749",
255+
"LNG": "-122.4194",
256+
"WEATHER_UNITS": "metric",
257+
},
258+
clear=True,
259+
)
224260
def test_weather_units_metric(self):
225261
"""Test WEATHER_UNITS with metric value."""
226262
config = DashboardConfig()
227263
assert config.WEATHER_UNITS == WeatherUnits.metric
228264

229-
@patch.dict(os.environ, {
230-
'ICS_URL': 'https://example.com/calendar.ics',
231-
'OWM_API_KEY': 'test_api_key',
232-
'LAT': '37.7749',
233-
'LNG': '-122.4194',
234-
'WEATHER_UNITS': 'imperial'
235-
}, clear=True)
265+
@patch.dict(
266+
os.environ,
267+
{
268+
"ICS_URL": "https://example.com/calendar.ics",
269+
"OWM_API_KEY": "test_api_key",
270+
"LAT": "37.7749",
271+
"LNG": "-122.4194",
272+
"WEATHER_UNITS": "imperial",
273+
},
274+
clear=True,
275+
)
236276
def test_weather_units_imperial(self):
237277
"""Test WEATHER_UNITS with imperial value."""
238278
config = DashboardConfig()
239279
assert config.WEATHER_UNITS == WeatherUnits.imperial
240280

241-
@patch.dict(os.environ, {
242-
'ICS_URL': 'https://example.com/calendar.ics',
243-
'OWM_API_KEY': 'test_api_key',
244-
'LAT': '37.7749',
245-
'LNG': '-122.4194',
246-
'NUM_CAL_DAYS_TO_QUERY': ''
247-
}, clear=True)
281+
@patch.dict(
282+
os.environ,
283+
{
284+
"ICS_URL": "https://example.com/calendar.ics",
285+
"OWM_API_KEY": "test_api_key",
286+
"LAT": "37.7749",
287+
"LNG": "-122.4194",
288+
"NUM_CAL_DAYS_TO_QUERY": "",
289+
},
290+
clear=True,
291+
)
248292
def test_empty_string_env_vars_cause_errors(self):
249293
"""Test that empty string environment variables cause errors for numeric fields."""
250-
os.environ['NUM_CAL_DAYS_TO_QUERY'] = ''
294+
os.environ["NUM_CAL_DAYS_TO_QUERY"] = ""
251295

252296
with pytest.raises(ValueError):
253297
DashboardConfig()

0 commit comments

Comments
 (0)