From 0fb4c6018460aca4b58444d5059600c6ca8a5fe1 Mon Sep 17 00:00:00 2001 From: Andrew Ferrier <107015+andrewferrier@users.noreply.github.com> Date: Wed, 22 Nov 2023 12:21:51 +0000 Subject: [PATCH] fix: Ensure we use a common time separator --- normfn | 7 ++++--- tests/Direct/test_Direct_Basic.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/normfn b/normfn index 9a5b70f..ef1b86f 100755 --- a/normfn +++ b/normfn @@ -411,7 +411,8 @@ def datetime_prefix(args, non_extension: str, filename: str): DMY_SEPARATOR_FIRST = r"(?P" + DATE_SEPARATOR + r")" DMY_SEPARATOR_FOLLOWING = r"(?P=dmysep)" MY_SEPARATOR = DATE_SEPARATOR - HMS_SEPARATOR = r"[-_.\s]?" + HMS_SEPARATOR_FIRST = r"(?P[-_.\s]?)" + HMS_SEPARATOR_FOLLOWING = r"(?P=hmssep)" DATE_TIME_SEPARATOR = r"([-_T\s]|\sat\s|,\s)" REGEX = ( @@ -459,8 +460,8 @@ def datetime_prefix(args, non_extension: str, filename: str): + r"(?P" + HOUR + r")" - r"(" + HMS_SEPARATOR + r"(?P" + MINUTE + r")" - r"(" + HMS_SEPARATOR + r"(?P" + SECOND + r"))?)?)?" + r"(" + HMS_SEPARATOR_FIRST + r"(?P" + MINUTE + r")" + r"(" + HMS_SEPARATOR_FOLLOWING + r"(?P" + SECOND + r"))?)?)?" r"(?P.*)$" ) diff --git a/tests/Direct/test_Direct_Basic.py b/tests/Direct/test_Direct_Basic.py index 21868fd..58f61f9 100644 --- a/tests/Direct/test_Direct_Basic.py +++ b/tests/Direct/test_Direct_Basic.py @@ -284,7 +284,7 @@ def test_abbr_month_insensitive_hyphen_name(self): self.assertEqual(1, self.directoryFileCount(self.workingDir)) self.assertEqual('', error) - def test_ensure_common_separator_used(self): + def test_ensure_common_date_separator_used(self): filename = os.path.join(self.workingDir, 'T 1234 2023-11-22.pdf') self.touch(filename) error = self.invokeDirectly([filename]) @@ -293,6 +293,15 @@ def test_ensure_common_separator_used(self): self.assertEqual(1, self.directoryFileCount(self.workingDir)) self.assertEqual('', error) + def test_ensure_common_time_separator_used(self): + filename = os.path.join(self.workingDir, 'ABC 2023-11-05T12-13_08.pdf') + self.touch(filename) + error = self.invokeDirectly([filename]) + self.assertFalse(os.path.exists(filename)) + self.assertTrue(os.path.exists(os.path.join(self.workingDir, '2023-11-05T12-13-ABC _08.pdf'))) + self.assertEqual(1, self.directoryFileCount(self.workingDir)) + self.assertEqual('', error) + def test_earliest(self): filename = os.path.join(self.workingDir, 'blah.txt') self.touch(filename)