From 25803a7231c70a5700382a5cc430ac2164d2eb07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <h.tomwoerden@indiscale.com> Date: Tue, 10 Dec 2024 13:02:23 +0100 Subject: [PATCH] ENH: raise an Error instead of just warning when timestamp file has bad content --- src/caoscrawler/converters/converters.py | 6 +++--- unittests/test_converters.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/caoscrawler/converters/converters.py b/src/caoscrawler/converters/converters.py index da752f68..df0d77b1 100644 --- a/src/caoscrawler/converters/converters.py +++ b/src/caoscrawler/converters/converters.py @@ -831,13 +831,13 @@ class DirectoryConverter(Converter): stamp_str = ref_file.readline().strip() try: return datetime.datetime.fromisoformat(stamp_str) - except ValueError: - logger.warn( + except ValueError as e: + logger.error( f"Reference file in {self.definition['match_newer_than_file']} " "doesn't contain a ISO formatted datetime in its first line. " "Match regardless of modification times." ) - return datetime.datetime.min + raise e class SimpleFileConverter(Converter): diff --git a/unittests/test_converters.py b/unittests/test_converters.py index 7b22aa84..e4b442d9 100644 --- a/unittests/test_converters.py +++ b/unittests/test_converters.py @@ -1113,9 +1113,10 @@ def test_directory_converter_change_date(caplog, converter_registry): # Match but warn with open(tmpfi.name, "w") as fi: fi.write(f"This is garbage.\n") - assert dc.match(test_dir_element) is not None + with pytest.raises(ValueError): + dc.match(test_dir_element) assert len(caplog.record_tuples) == 1 - assert caplog.record_tuples[0][1] == logging.WARNING + assert caplog.record_tuples[0][1] == logging.ERROR assert tmpfi.name in caplog.record_tuples[0][2] assert "doesn't contain a ISO formatted datetime in its first line" in caplog.record_tuples[0][2] -- GitLab