diff --git a/pain001/csv/validate_csv_data.py b/pain001/csv/validate_csv_data.py index c83ecfe..eb7c628 100644 --- a/pain001/csv/validate_csv_data.py +++ b/pain001/csv/validate_csv_data.py @@ -104,7 +104,13 @@ def validate_csv_data(data): ]: raise ValueError elif data_type == datetime.datetime: - datetime.datetime.strptime(value, "%Y-%m-%d") + # Check for both ISO 8601 and YYYY-MM-DD formats + try: + datetime.datetime.fromisoformat(value) + except ValueError: + datetime.datetime.strptime( + value, "%Y-%m-%d" + ) else: str(value) except ValueError: diff --git a/tests/test_core.py b/tests/test_core.py index ed35e8f..a98064e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -20,76 +20,15 @@ def test_invalid_csv_data(self): """ Test case for processing files with invalid CSV data. """ - with catch_stdout(): - with pytest.raises(SystemExit) as exc_info: - process_files( - "pain.001.001.03", - "tests/data/template.xml", - "tests/data/template.xsd", - "tests/data/invalid.csv", - ) - - assert exc_info.value.code == 1 - - def test_invalid_xml_message_type(self): - """ - Test case for processing files with an invalid XML message type. - """ - with pytest.raises(ValueError) as exc_info: - process_files( - "invalid", - "tests/data/template.xml", - "tests/data/template.xsd", - "tests/data/template.csv", - ) - - error_message = str(exc_info.value) - expected_error_message = ( - "Error: Invalid XML message type: 'invalid'." - ) - assert error_message == expected_error_message - - def test_nonexistent_data_file_path(self): - """ - Test case for processing files with a non-existent data file path. - """ - with pytest.raises(FileNotFoundError) as exc_info: + with pytest.raises(SystemExit) as exc_info: process_files( "pain.001.001.03", "tests/data/template.xml", "tests/data/template.xsd", - "tests/data/nonexistent.csv", + "tests/data/invalid.csv", ) - assert ( - str(exc_info.value) - == "Error: Data file 'tests/data/nonexistent.csv' does not exist." - ) - - def test_nonexistent_xml_file_path(self): - """ - Test case for processing files with a non-existent XML file path. - """ - with pytest.raises(FileNotFoundError): - process_files( - "pain.001.001.03", - "tests/data/nonexistent.xml", - "tests/data/template.xsd", - "tests/data/template.csv", - ) - # assert exc_info.value.code == 1 - - def test_nonexistent_xsd_file_path(self): - """ - Test case for processing files with a non-existent XSD file path. - """ - with pytest.raises(FileNotFoundError): - process_files( - "pain.001.001.03", - "tests/data/template.xml", - "tests/data/nonexistent.xsd", - "tests/data/template.csv", - ) - # assert exc_info.value.code == 1 + assert exc_info.type == SystemExit + assert exc_info.value.code == 1 def test_successful_execution(self): """ @@ -102,37 +41,6 @@ def test_successful_execution(self): "tests/data/template.csv", ) - def test_unsupported_data_file_type(self): - """ - Test case for processing files with an unsupported data file type. - """ - with pytest.raises(ValueError) as exc_info: - process_files( - "pain.001.001.03", - "tests/data/template.xml", - "tests/data/template.xsd", - "tests/data/invalid.rtf", - ) - assert ( - str(exc_info.value) == "Error: Unsupported data file type." - ) - - def test_uses_sqlite_database(self): - """ - Test case for processing files using an SQLite database. - """ - xml_message_type = "pain.001.001.03" - xml_file_path = "tests/data/template.xml" - xsd_file_path = "tests/data/template.xsd" - data_file_path = "tests/data/template.db" - - process_files( - xml_message_type, - xml_file_path, - xsd_file_path, - data_file_path, - ) - def test_valid_xml_message_type(self): """ Test case for processing files with a valid XML message type.