Skip to content

Commit 34f24f2

Browse files
tests: Address PR comments by removing redundant test functions
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 9a20e6f commit 34f24f2

File tree

1 file changed

+0
-82
lines changed

1 file changed

+0
-82
lines changed

unit_tests/utils/test_datetime_helpers.py

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,6 @@ def py_datetime():
329329
monkeypatch.setattr("airbyte_cdk.utils.datetime_helpers.Instant", MockInstant)
330330
monkeypatch.setattr("airbyte_cdk.utils.datetime_helpers.parser.parse", spy_parser_parse)
331331

332-
# Skip formats that would be rejected by validation checks
333-
if isinstance(input_value, str) and "March" in input_value:
334-
# Skip this test case as it would be rejected by validation
335-
return
336-
337332
# Parse the datetime
338333
ab_datetime_parse(input_value)
339334

@@ -344,80 +339,3 @@ def py_datetime():
344339
else:
345340
assert dateutil_called, f"Expected dateutil parser to be used for {input_value}"
346341
assert not whenever_called, f"Did not expect whenever parser to be used for {input_value}"
347-
348-
349-
def test_whenever_parser_for_iso_formats(monkeypatch):
350-
"""Test that the whenever parser is used for certain formats even when dateutil is unavailable."""
351-
352-
# Create a mock dateutil.parser.parse that always raises an exception
353-
def mock_parser_parse(dt_str, **kwargs):
354-
raise ValueError("dateutil parser is unavailable")
355-
356-
# Apply the mock at the module level
357-
monkeypatch.setattr("airbyte_cdk.utils.datetime_helpers.parser.parse", mock_parser_parse)
358-
359-
# These formats should still parse correctly using the whenever parser
360-
whenever_formats = [
361-
"2023-03-14", # Date-only format
362-
1678806566, # Unix timestamp
363-
]
364-
365-
for dt_str in whenever_formats:
366-
# This should not raise an exception because the whenever parser should be used
367-
result = ab_datetime_parse(dt_str)
368-
assert isinstance(result, AirbyteDateTime)
369-
370-
371-
def test_dateutil_fallback_for_non_iso_formats(monkeypatch):
372-
"""Test that the dateutil parser is used as a fallback for non-ISO/RFC compliant formats."""
373-
# Create tracking variables
374-
whenever_called = False
375-
dateutil_called = False
376-
377-
# Store original functions
378-
original_instant_module = __import__("whenever").Instant
379-
original_parser_parse = parser.parse
380-
381-
# Create a mock Instant class with methods that always raise exceptions
382-
class MockInstant:
383-
@staticmethod
384-
def from_timestamp(*args, **kwargs):
385-
nonlocal whenever_called
386-
whenever_called = True
387-
raise ValueError("whenever parser is unavailable")
388-
389-
@staticmethod
390-
def from_utc(*args, **kwargs):
391-
nonlocal whenever_called
392-
whenever_called = True
393-
raise ValueError("whenever parser is unavailable")
394-
395-
# Create a spy for parser.parse
396-
def spy_parser_parse(*args, **kwargs):
397-
nonlocal dateutil_called
398-
dateutil_called = True
399-
return original_parser_parse(*args, **kwargs)
400-
401-
# Apply the mocks at the module level
402-
monkeypatch.setattr("airbyte_cdk.utils.datetime_helpers.Instant", MockInstant)
403-
monkeypatch.setattr("airbyte_cdk.utils.datetime_helpers.parser.parse", spy_parser_parse)
404-
405-
# These non-ISO/RFC formats should use the dateutil parser
406-
non_iso_formats = [
407-
"2023-03-14T15:09:26Z", # ISO format with T delimiter
408-
"2023-03-14T15:09:26+00:00", # ISO format with timezone
409-
"2023-03-14 15:09:26", # Missing T delimiter
410-
"14/03/2023 15:09:26", # Different date format
411-
]
412-
413-
for dt_str in non_iso_formats:
414-
# Skip formats that would be rejected by validation checks
415-
if "March" in dt_str:
416-
continue
417-
418-
# This should not raise an exception because the dateutil parser should be used
419-
result = ab_datetime_parse(dt_str)
420-
assert isinstance(result, AirbyteDateTime)
421-
assert dateutil_called, f"Expected dateutil parser to be used for {dt_str}"
422-
# Reset the flag for the next iteration
423-
dateutil_called = False

0 commit comments

Comments
 (0)