Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9339477
D6670.id24237.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D6670.id24237.diff
View Options
diff --git a/swh/loader/cvs/tasks.py b/swh/loader/cvs/tasks.py
--- a/swh/loader/cvs/tasks.py
+++ b/swh/loader/cvs/tasks.py
@@ -13,7 +13,10 @@
def convert_to_datetime(date: Optional[str]) -> Optional[datetime]:
+ if date is None:
+ return None
try:
+ assert isinstance(date, str)
return iso8601.parse_date(date)
except Exception:
return None
diff --git a/swh/loader/cvs/tests/test_tasks.py b/swh/loader/cvs/tests/test_tasks.py
new file mode 100644
--- /dev/null
+++ b/swh/loader/cvs/tests/test_tasks.py
@@ -0,0 +1,25 @@
+# Copyright (C) 2019-2021 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+from datetime import datetime, timezone
+
+import pytest
+
+from swh.loader.cvs.tasks import convert_to_datetime
+
+
+@pytest.mark.parametrize(
+ "date,expected_result",
+ [
+ (None, None),
+ (
+ "2021-11-23 09:41:02.434195+00:00",
+ datetime(2021, 11, 23, 9, 41, 2, 434195, tzinfo=timezone.utc),
+ ),
+ ("23112021", None,), # failure to parse
+ ],
+)
+def test_convert_to_datetime(date, expected_result):
+ assert convert_to_datetime(date) == expected_result
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jul 3 2025, 9:42 AM (5 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3217209
Attached To
D6670: cvs.tasks: Fix type
Event Timeline
Log In to Comment