Skip to content

Commit cfe0c0f

Browse files
authored
Merge pull request opendatacube#1825 from pjonsson/test-query-midnight
tests: fix midnight bug
2 parents 67b1528 + 1fb74ea commit cfe0c0f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

docs/about/whats_new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Next Version
2222
- fields: type annotate offset parameter :pull:`1809`
2323
- postgis: inherit instead of decorate :pull:`1801`
2424
- Dependabot: make one pull request for everything :pull:`1816`
25+
- tests: fix midnight bug :pull:`1825`
2526
- geometry: stop misusing constructor :pull:`1826`
2627
- Various lint fixes :pull:`1824`
2728
- CI: use the right project slug :pull:`1823`

tests/api/test_query.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ def format_test(start_out, end_out):
173173
((datetime.date(2008, 1, 1)),
174174
format_test('2008-01-01T00:00:00', '2008-01-01T23:59:59.999999')),
175175
((datetime.date(2008, 1, 1), None),
176-
format_test('2008-01-01T00:00:00', datetime.datetime.now().strftime("%Y-%m-%dT23:59:59.999999"))),
176+
# Starting the tests before midnight and finishing after will cause test failure
177+
# since datetime.now() is evaluated before midnight and the test runs after midnight.
178+
# Put the result behind a function that is evaluated inside the test instead.
179+
lambda _: format_test('2008-01-01T00:00:00', datetime.datetime.now().strftime("%Y-%m-%dT23:59:59.999999"))),
177180
((None, '2008'),
178181
format_test(datetime.datetime.fromtimestamp(0).strftime("%Y-%m-%dT%H:%M:%S"), '2008-12-31T23:59:59.999999')),
179182
]
@@ -183,7 +186,7 @@ def format_test(start_out, end_out):
183186
def test_time_handling(time_param, expected):
184187
query = Query(time=time_param)
185188
assert 'time' in query.search_terms
186-
assert query.search_terms['time'] == expected
189+
assert query.search_terms['time'] == (expected if isinstance(expected, Range) else expected("now"))
187190

188191

189192
def test_time_handling_int():

0 commit comments

Comments
 (0)