Skip to content

Commit 3018281

Browse files
Keng Susumpowclaude
andcommitted
Fix code formatting in tests with Black and isort
Apply Black and isort formatting to test_epiweek.py to resolve CI formatting issues. Changes include consistent quote style, import ordering, and line formatting. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 37ea70a commit 3018281

File tree

1 file changed

+115
-85
lines changed

1 file changed

+115
-85
lines changed

tests/test_epiweek.py

Lines changed: 115 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import pytest
21
from datetime import datetime
2+
3+
import pytest
4+
35
import epydem
46
from epydem.epiweek import _verify_date_str
57

@@ -11,59 +13,65 @@ def test_basic_calculation(self):
1113
"""Test basic epidemiological week calculation."""
1214
# 2024: January 1st is Monday, first Thursday is January 4th
1315
# Week 1 starts on Sunday December 31st, 2023
14-
assert epydem.calculate('2024-01-01') == 1
15-
assert epydem.calculate('2024-01-04') == 1 # First Thursday
16-
assert epydem.calculate('2024-01-07') == 1 # First Sunday
17-
assert epydem.calculate('2024-01-08') == 2 # Second Monday
16+
assert epydem.calculate("2024-01-01") == 1
17+
assert epydem.calculate("2024-01-04") == 1 # First Thursday
18+
assert epydem.calculate("2024-01-07") == 1 # First Sunday
19+
assert epydem.calculate("2024-01-08") == 2 # Second Monday
1820

1921
def test_week_boundaries(self):
2022
"""Test week boundary calculations."""
2123
# Test various days within the same week
22-
assert epydem.calculate('2024-01-01') == 1 # Monday
23-
assert epydem.calculate('2024-01-02') == 1 # Tuesday
24-
assert epydem.calculate('2024-01-03') == 1 # Wednesday
25-
assert epydem.calculate('2024-01-04') == 1 # Thursday
26-
assert epydem.calculate('2024-01-05') == 1 # Friday
27-
assert epydem.calculate('2024-01-06') == 1 # Saturday
28-
assert epydem.calculate('2024-01-07') == 1 # Sunday
24+
assert epydem.calculate("2024-01-01") == 1 # Monday
25+
assert epydem.calculate("2024-01-02") == 1 # Tuesday
26+
assert epydem.calculate("2024-01-03") == 1 # Wednesday
27+
assert epydem.calculate("2024-01-04") == 1 # Thursday
28+
assert epydem.calculate("2024-01-05") == 1 # Friday
29+
assert epydem.calculate("2024-01-06") == 1 # Saturday
30+
assert epydem.calculate("2024-01-07") == 1 # Sunday
2931

3032
def test_different_years(self):
3133
"""Test calculations for different years."""
3234
# Test different year scenarios
33-
assert epydem.calculate('2023-01-01') == 0 # 2023: Jan 1st is Sunday, before epi week 1
34-
assert epydem.calculate('2025-01-01') == 1 # 2025: Jan 1st is Wednesday, in epi week 1
35-
assert epydem.calculate('2022-01-01') == 0 # 2022: Jan 1st is Saturday, before epi year
35+
assert (
36+
epydem.calculate("2023-01-01") == 0
37+
) # 2023: Jan 1st is Sunday, before epi week 1
38+
assert (
39+
epydem.calculate("2025-01-01") == 1
40+
) # 2025: Jan 1st is Wednesday, in epi week 1
41+
assert (
42+
epydem.calculate("2022-01-01") == 0
43+
) # 2022: Jan 1st is Saturday, before epi year
3644

3745
def test_year_end_scenarios(self):
3846
"""Test end of year scenarios."""
3947
# December dates that might be in the next year's epi week 1
40-
assert epydem.calculate('2023-12-31') == 52 # Late in 2023's epi year
41-
48+
assert epydem.calculate("2023-12-31") == 52 # Late in 2023's epi year
49+
4250
def test_week_zero_cases(self):
4351
"""Test cases that should return week 0."""
4452
# Dates before the epidemiological year starts
45-
assert epydem.calculate('2022-01-01') == 0 # Saturday, before epi year
46-
assert epydem.calculate('2022-01-02') == 0 # Sunday, week 1 starts Jan 3rd
53+
assert epydem.calculate("2022-01-01") == 0 # Saturday, before epi year
54+
assert epydem.calculate("2022-01-02") == 0 # Sunday, week 1 starts Jan 3rd
4755

4856
def test_mid_year_calculations(self):
4957
"""Test calculations for various dates throughout the year."""
5058
# Test some mid-year dates
51-
assert epydem.calculate('2024-06-01') > 20 # Should be in the 20s
52-
assert epydem.calculate('2024-12-01') > 45 # Should be in the 40s or 50s
59+
assert epydem.calculate("2024-06-01") > 20 # Should be in the 20s
60+
assert epydem.calculate("2024-12-01") > 45 # Should be in the 40s or 50s
5361

5462
def test_leap_year(self):
5563
"""Test leap year handling."""
5664
# 2024 is a leap year
57-
assert epydem.calculate('2024-02-29') > 0 # Should handle leap day
58-
assert epydem.calculate('2024-03-01') > 0
65+
assert epydem.calculate("2024-02-29") > 0 # Should handle leap day
66+
assert epydem.calculate("2024-03-01") > 0
5967

6068
def test_consistent_week_progression(self):
6169
"""Test that week numbers progress consistently."""
6270
# Test a sequence of dates to ensure proper progression
63-
week1 = epydem.calculate('2024-01-01')
64-
week2 = epydem.calculate('2024-01-08')
65-
week3 = epydem.calculate('2024-01-15')
66-
71+
week1 = epydem.calculate("2024-01-01")
72+
week2 = epydem.calculate("2024-01-08")
73+
week3 = epydem.calculate("2024-01-15")
74+
6775
assert week2 == week1 + 1
6876
assert week3 == week2 + 1
6977

@@ -74,49 +82,49 @@ class TestVerifyDateStr:
7482
def test_valid_date_formats(self):
7583
"""Test valid date string formats."""
7684
# These should not raise exceptions
77-
epydem.calculate('2024-01-01')
78-
epydem.calculate('2024-12-31')
79-
epydem.calculate('2023-02-28')
80-
epydem.calculate('2024-02-29') # Leap year
85+
epydem.calculate("2024-01-01")
86+
epydem.calculate("2024-12-31")
87+
epydem.calculate("2023-02-28")
88+
epydem.calculate("2024-02-29") # Leap year
8189

8290
def test_invalid_date_formats(self):
8391
"""Test invalid date string formats."""
8492
with pytest.raises(ValueError, match="Invalid date format"):
85-
epydem.calculate('24-01-01') # Wrong year format
86-
93+
epydem.calculate("24-01-01") # Wrong year format
94+
8795
with pytest.raises(ValueError, match="Invalid date format"):
88-
epydem.calculate('2024-1-1') # Wrong month/day format
89-
96+
epydem.calculate("2024-1-1") # Wrong month/day format
97+
9098
with pytest.raises(ValueError, match="Invalid date format"):
91-
epydem.calculate('2024/01/01') # Wrong separator
92-
99+
epydem.calculate("2024/01/01") # Wrong separator
100+
93101
with pytest.raises(ValueError, match="Invalid date format"):
94-
epydem.calculate('01-01-2024') # Wrong order
95-
102+
epydem.calculate("01-01-2024") # Wrong order
103+
96104
with pytest.raises(ValueError):
97-
epydem.calculate('2024-01-32') # Invalid day
98-
105+
epydem.calculate("2024-01-32") # Invalid day
106+
99107
with pytest.raises(ValueError):
100-
epydem.calculate('2024-13-01') # Invalid month
108+
epydem.calculate("2024-13-01") # Invalid month
101109

102110
def test_invalid_types(self):
103111
"""Test invalid input types."""
104112
with pytest.raises((AttributeError, TypeError)):
105113
epydem.calculate(20240101) # Integer instead of string
106-
114+
107115
with pytest.raises((AttributeError, TypeError)):
108116
epydem.calculate(None) # None instead of string
109117

110118
def test_empty_and_malformed_strings(self):
111119
"""Test empty and malformed strings."""
112120
with pytest.raises(ValueError, match="Invalid date format"):
113-
epydem.calculate('') # Empty string
114-
121+
epydem.calculate("") # Empty string
122+
115123
with pytest.raises(ValueError, match="Invalid date format"):
116-
epydem.calculate('not-a-date') # Random string
117-
124+
epydem.calculate("not-a-date") # Random string
125+
118126
with pytest.raises(ValueError, match="Invalid date format"):
119-
epydem.calculate('2024-01-01 10:30:00') # Too much info
127+
epydem.calculate("2024-01-01 10:30:00") # Too much info
120128

121129

122130
class TestEdgeCases:
@@ -126,67 +134,75 @@ def test_first_day_scenarios(self):
126134
"""Test first day of year scenarios for different weekdays."""
127135
# Test years where Jan 1st falls on different weekdays
128136
test_cases = [
129-
('2023-01-01', 0), # Sunday - before epi week 1
130-
('2024-01-01', 1), # Monday - in epi week 1
131-
('2025-01-01', 1), # Wednesday - in epi week 1
137+
("2023-01-01", 0), # Sunday - before epi week 1
138+
("2024-01-01", 1), # Monday - in epi week 1
139+
("2025-01-01", 1), # Wednesday - in epi week 1
132140
]
133-
141+
134142
for date_str, expected_week in test_cases:
135143
assert epydem.calculate(date_str) == expected_week
136144

137145
def test_year_transition(self):
138146
"""Test the transition between epidemiological years."""
139147
# The end of 2023's epi year and start of 2024's
140-
assert epydem.calculate('2023-12-30') >= 52 # Late in 2023's epi year
141-
assert epydem.calculate('2023-12-31') == 52 # Late in 2023's epi year
142-
assert epydem.calculate('2024-01-01') == 1 # Start of 2024's week 1
148+
assert epydem.calculate("2023-12-30") >= 52 # Late in 2023's epi year
149+
assert epydem.calculate("2023-12-31") == 52 # Late in 2023's epi year
150+
assert epydem.calculate("2024-01-01") == 1 # Start of 2024's week 1
143151

144152
def test_maximum_week_numbers(self):
145153
"""Test that week numbers don't exceed expected maximums."""
146154
# Test various dates to ensure no week number is > 53
147155
test_dates = [
148-
'2024-12-31', '2024-12-30', '2024-12-29',
149-
'2023-12-31', '2023-12-30', '2023-12-29',
150-
'2025-12-31', '2025-12-30', '2025-12-29'
156+
"2024-12-31",
157+
"2024-12-30",
158+
"2024-12-29",
159+
"2023-12-31",
160+
"2023-12-30",
161+
"2023-12-29",
162+
"2025-12-31",
163+
"2025-12-30",
164+
"2025-12-29",
151165
]
152-
166+
153167
for date_str in test_dates:
154168
week_num = epydem.calculate(date_str)
155-
assert 0 <= week_num <= 53, f"Week number {week_num} out of range for {date_str}"
169+
assert (
170+
0 <= week_num <= 53
171+
), f"Week number {week_num} out of range for {date_str}"
156172

157173

158174
class TestPrivateVerifyFunction:
159175
"""Test cases for the private _verify_date_str function."""
160-
176+
161177
def test_verify_valid_formats(self):
162178
"""Test that _verify_date_str accepts valid formats."""
163179
assert _verify_date_str("2024-01-01") == True
164180
assert _verify_date_str("2023-12-31") == True
165181
assert _verify_date_str("2000-02-29") == True # Leap year
166182
assert _verify_date_str("1999-01-01") == True
167-
183+
168184
def test_verify_invalid_formats(self):
169185
"""Test that _verify_date_str rejects invalid formats."""
170186
invalid_formats = [
171-
"24-01-01", # Wrong year format
172-
"2024-1-01", # Wrong month format
173-
"2024-01-1", # Wrong day format
174-
"2024/01/01", # Wrong separator
175-
"2024-01", # Missing day
176-
"01-01-2024", # Wrong order
177-
"not-a-date", # Not a date
178-
"", # Empty string
179-
"2024-01-01T10:30", # With time
187+
"24-01-01", # Wrong year format
188+
"2024-1-01", # Wrong month format
189+
"2024-01-1", # Wrong day format
190+
"2024/01/01", # Wrong separator
191+
"2024-01", # Missing day
192+
"01-01-2024", # Wrong order
193+
"not-a-date", # Not a date
194+
"", # Empty string
195+
"2024-01-01T10:30", # With time
180196
]
181-
197+
182198
for invalid_date in invalid_formats:
183199
with pytest.raises(ValueError, match="Invalid date format"):
184200
_verify_date_str(invalid_date)
185201

186202

187203
class TestSpecificYearScenarios:
188204
"""Test specific year scenarios to ensure accuracy."""
189-
205+
190206
def test_2023_specific_dates(self):
191207
"""Test specific dates for 2023 (Jan 1 is Sunday)."""
192208
# 2023: Jan 1 is Sunday, first Thursday is Jan 5
@@ -195,7 +211,7 @@ def test_2023_specific_dates(self):
195211
assert epydem.calculate("2023-01-02") == 1 # Monday - week 1 start
196212
assert epydem.calculate("2023-01-05") == 1 # Thursday of week 1
197213
assert epydem.calculate("2023-01-08") == 1 # Sunday of week 1
198-
214+
199215
def test_2024_specific_dates(self):
200216
"""Test specific dates for 2024 (Jan 1 is Monday)."""
201217
# 2024: Jan 1 is Monday, first Thursday is Jan 4
@@ -204,7 +220,7 @@ def test_2024_specific_dates(self):
204220
assert epydem.calculate("2024-01-04") == 1 # Thursday of week 1
205221
assert epydem.calculate("2024-01-07") == 1 # Sunday of week 1
206222
assert epydem.calculate("2024-01-08") == 2 # Monday - week 2 start
207-
223+
208224
def test_2022_specific_dates(self):
209225
"""Test specific dates for 2022 (Jan 1 is Saturday)."""
210226
# 2022: Jan 1 is Saturday, first Thursday is Jan 6
@@ -218,36 +234,50 @@ def test_2022_specific_dates(self):
218234

219235
class TestComprehensiveValidation:
220236
"""Comprehensive validation tests."""
221-
237+
222238
def test_all_months_valid(self):
223239
"""Test that all months work correctly."""
224-
months = ["01", "02", "03", "04", "05", "06",
225-
"07", "08", "09", "10", "11", "12"]
226-
240+
months = [
241+
"01",
242+
"02",
243+
"03",
244+
"04",
245+
"05",
246+
"06",
247+
"07",
248+
"08",
249+
"09",
250+
"10",
251+
"11",
252+
"12",
253+
]
254+
227255
for month in months:
228256
date_str = f"2024-{month}-15"
229257
result = epydem.calculate(date_str)
230258
assert 1 <= result <= 53, f"Invalid week {result} for {date_str}"
231-
259+
232260
def test_sequential_days_progression(self):
233261
"""Test that sequential days show proper week progression."""
234262
# Test a full week transition
235263
dates_and_expected = [
236264
("2024-01-07", 1), # Sunday of week 1
237-
("2024-01-08", 2), # Monday of week 2
265+
("2024-01-08", 2), # Monday of week 2
238266
("2024-01-14", 2), # Sunday of week 2
239267
("2024-01-15", 3), # Monday of week 3
240268
]
241-
269+
242270
for date_str, expected_week in dates_and_expected:
243271
assert epydem.calculate(date_str) == expected_week
244-
272+
245273
def test_different_years_july_first(self):
246274
"""Test July 1st across different years for consistency."""
247275
years = ["2020", "2021", "2022", "2023", "2024", "2025"]
248-
276+
249277
for year in years:
250278
date_str = f"{year}-07-01"
251279
result = epydem.calculate(date_str)
252280
# July 1st should always be in week 26-28 range
253-
assert 25 <= result <= 29, f"Week {result} for {date_str} seems out of range"
281+
assert (
282+
25 <= result <= 29
283+
), f"Week {result} for {date_str} seems out of range"

0 commit comments

Comments
 (0)