Coverage for tests/test_download_excel.py: 100%
12 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 17:30 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-04 17:30 +0000
1import pytest
2from datetime import datetime
3from src.download_excel import generate_name_of_file_google
6@pytest.mark.parametrize(
7 "mock_now, expected",
8 [
9 # Case: First week of the year, previous year is different
10 (datetime(year=2025, month=1, day=1), ["1.2025", "2.2025"]),
11 # Case: Middle of the year
12 (datetime(year=2025, month=6, day=15), ["24.2025", "25.2025"]),
13 # Case: End of the, year end day last year in 1 week
14 (datetime(year=2025, month=12, day=31), ["1.2026", "2.2026"]),
15 # Case: End of the year
16 (datetime(year=2025, month=12, day=30), ["1.2026", "2.2026"]),
17 # Case: End of the year
18 (datetime(year=2025, month=12, day=29), ["1.2026", "2.2026"]),
19 # Case: End of the year
20 (datetime(year=2025, month=12, day=28), ["52.2025", "1.2026"]),
21 # Case: End of the year
22 (datetime(year=2024, month=12, day=29), ["52.2024", "1.2025"]),
23 # Case: End of the year
24 (datetime(year=2024, month=12, day=30), ["1.2025", "2.2025"]),
25 # Case: End of the year
26 (datetime(year=2024, month=12, day=23), ["52.2024", "1.2025"]),
27 # Case: End of the year
28 (datetime(year=2024, month=12, day=22), ["51.2024", "52.2024"]),
29 # Case: First week of the year, same year
30 (datetime(year=2026, month=1, day=2), ["1.2026", "2.2026"]),
31 ],
32)
33def test_generate_name_of_file_google(monkeypatch, mock_now, expected):
34 # Mock datetime.now() to return the mock_now value
35 class MockDateTime(datetime):
36 @classmethod
37 def now(cls):
38 return mock_now
40 monkeypatch.setattr("src.download_excel.datetime", MockDateTime)
42 # Call the function and assert the result
43 result = generate_name_of_file_google()
44 assert result == expected