diff --git a/swh/loader/mercurial/tasks.py b/swh/loader/mercurial/tasks.py --- a/swh/loader/mercurial/tasks.py +++ b/swh/loader/mercurial/tasks.py @@ -1,4 +1,4 @@ -# Copyright (C) 2020-2021 The Software Heritage developers +# Copyright (C) 2020-2022 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 @@ -7,7 +7,7 @@ from celery import shared_task -from swh.loader.mercurial.utils import parse_visit_date +from swh.loader.core.utils import parse_visit_date from .loader import HgArchiveLoader, HgLoader diff --git a/swh/loader/mercurial/tests/test_loader.py b/swh/loader/mercurial/tests/test_loader.py --- a/swh/loader/mercurial/tests/test_loader.py +++ b/swh/loader/mercurial/tests/test_loader.py @@ -12,7 +12,7 @@ import attr import pytest -from swh.loader.mercurial.utils import parse_visit_date +from swh.loader.core.utils import parse_visit_date from swh.loader.tests import ( assert_last_visit_matches, check_snapshot, diff --git a/swh/loader/mercurial/tests/test_utils.py b/swh/loader/mercurial/tests/test_utils.py deleted file mode 100644 --- a/swh/loader/mercurial/tests/test_utils.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 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 - -import pytest - -from swh.loader.mercurial.utils import parse_visit_date - -VISIT_DATE_STR = "2021-02-17 15:50:04.518963" -VISIT_DATE = datetime(2021, 2, 17, 15, 50, 4, 518963) - - -@pytest.mark.parametrize( - "input_visit_date,expected_date", - [(None, None), (VISIT_DATE, VISIT_DATE), (VISIT_DATE_STR, VISIT_DATE),], -) -def test_utils_parse_visit_date(input_visit_date, expected_date): - assert parse_visit_date(input_visit_date) == expected_date - - -def test_utils_parse_visit_date_now(): - actual_date = parse_visit_date("now") - assert isinstance(actual_date, datetime) - - -def test_utils_parse_visit_date_fails(): - with pytest.raises(ValueError, match="invalid"): - parse_visit_date(10) # not a string nor a date diff --git a/swh/loader/mercurial/utils.py b/swh/loader/mercurial/utils.py --- a/swh/loader/mercurial/utils.py +++ b/swh/loader/mercurial/utils.py @@ -3,31 +3,8 @@ # 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 os -from typing import Dict, Optional, Union - -from dateutil.parser import parse - - -def parse_visit_date(visit_date: Optional[Union[datetime, str]]) -> Optional[datetime]: - """Convert visit date from either None, a string or a datetime to either None or - datetime. - - """ - if visit_date is None: - return None - - if isinstance(visit_date, datetime): - return visit_date - - if visit_date == "now": - return datetime.now(tz=timezone.utc) - - if isinstance(visit_date, str): - return parse(visit_date) - - raise ValueError(f"invalid visit date {visit_date!r}") +from typing import Dict def get_minimum_env() -> Dict[str, str]: