Files
doczyai-pipelines/fieldExtraction/tests/qa_qc/date_format_test.py
T
Alex Galarce 53b38ea15c Merged in refactor/split-investment-and-client (pull request #347)
Refactor/split investment and client

* refactor: clean up tests

* Renamed tests/qcqa to tests/qa_qc for consistency

* comment out faulty test - see docstring note at top

* split to client/investment

* add __init__.py to investment and client to avoid mypy confusion

* fix imports

* update imports for consistency across investment module

* move back to one config

* try changing import to relative

* add init.py to src

* try relative import

* try one more sys.path.append

* fix path for client main

* fix imports in file_processing

* make prompts common

* move keywords out to `src`

* move smart_chunking_funcs to `src`

* fix mypy error

* start moving to explicit imports

* remove old keywords and fix imports for keywords and prompts

* change all imports to full paths

* fix unit tests

* add readme for new way of running things

* isort after all that import work

* remove unused sys.path.append from some tests


Approved-by: Katon Minhas
2025-01-08 21:59:47 +00:00

82 lines
2.5 KiB
Python

import pytest
from src.qa_qc.qa_qc_utils import date_format_check
def test_valid_date_formats():
"""Test valid date formats are correctly validated"""
valid_dates = {
"01/01/2024" : '1/1/2024',
"12/31/2023" : '12/31/2023',
"02/29/2024" : '2/29/2024', # Leap year
"07/04/1776" : '7/4/1776',
"09/08/2024" : '9/8/2024'
}
for date in valid_dates.keys():
result, is_valid = date_format_check(date)
assert result == valid_dates[date]
assert is_valid is True
def test_invalid_date_formats():
"""Test various invalid date formats"""
invalid_dates = [
"13/01/2024", # Invalid month
"01/32/2024", # Invalid day
"02/29/2023", # Not a leap year
"00/01/2024", # Zero month
"01/00/2024", # Zero day
"01-01-2024", # Wrong separator
"2024/01/01", # Wrong order
"01/01/24", # Two-digit year
"Jan/01/2024", # Text month
]
for date in invalid_dates:
result, is_valid = date_format_check(date)
assert result == date
assert is_valid is False
def test_non_string_inputs():
"""Test handling of non-string inputs"""
test_cases = [
(20240101, "20240101"),
(None, None),
(1.234, "1.234"),
(["01/01/2024"], "['01/01/2024']"),
({"date": "01/01/2024"}, "{'date': '01/01/2024'}"),
]
for input_val, expected_str in test_cases:
result, is_valid = date_format_check(input_val)
assert result == str(input_val)
assert is_valid is False
def test_edge_cases():
"""Test edge cases with valid-looking but incorrect formats"""
test_cases = [
"01/01/2024 ", # Extra space at end
" 01/01/2024", # Extra space at start
"01/01/2024\n", # Newline at end
"01 /01/2024", # Space in middle
"01/01/ 2024", # Space in middle
]
for date in test_cases:
result, is_valid = date_format_check(date)
assert result == date
assert is_valid is False
def test_special_dates():
"""Test boundary cases for dates"""
test_cases = [
("12/31/9999", True), # Far future
("2/28/2024", True), # Day before leap day
("3/1/2024", True), # Day after leap day
("12/31/2023", True), # Last day of year
("1/1/2024", True), # First day of year
]
for date, expected_valid in test_cases:
result, is_valid = date_format_check(date)
assert result == date
assert is_valid == expected_valid