diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/test/conftest.py | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py index 3d9f9429dc..d579fe616f 100644 --- a/lib/spack/spack/test/conftest.py +++ b/lib/spack/spack/test/conftest.py @@ -4,6 +4,7 @@ # SPDX-License-Identifier: (Apache-2.0 OR MIT) import collections +import datetime import errno import inspect import itertools @@ -15,21 +16,13 @@ import shutil import tempfile import xml.etree.ElementTree -try: - # CVS outputs dates in different formats on different systems. We are using - # the dateutil package to parse these dates. This package does not exist - # for Python <2.7. That means that we cannot test checkouts "by date" for - # CVS respositories. (We can still use CVS repos with all features, only - # our tests break.) - from dateutil.parser import parse as parse_date -except ImportError: - def parse_date(string): # type: ignore - pytest.skip("dateutil package not available") +import py +import pytest import archspec.cpu.microarchitecture import archspec.cpu.schema -import py -import pytest + +from llnl.util.filesystem import mkdirp, remove_linked_tree, working_dir import spack.architecture import spack.caches @@ -49,9 +42,7 @@ import spack.subprocess_context import spack.util.executable import spack.util.gpg import spack.util.spack_yaml as syaml -from llnl.util.filesystem import mkdirp, remove_linked_tree, working_dir -from spack.fetch_strategy import FetchError -from spack.fetch_strategy import FetchStrategyComposite, URLFetchStrategy +from spack.fetch_strategy import FetchError, FetchStrategyComposite, URLFetchStrategy from spack.util.pattern import Bunch @@ -917,6 +908,19 @@ def mock_archive(request, tmpdir_factory): expanded_archive_basedir=spack.stage._source_path_subdir) +def _parse_cvs_date(line): + """Turn a CVS log date into a datetime.datetime""" + # dates in CVS logs can have slashes or dashes and may omit the time zone: + # date: 2021-07-07 02:43:33 -0700; ... + # date: 2021-07-07 02:43:33; ... + # date: 2021/07/07 02:43:33; ... + m = re.search(r'date:\s+(\d+)[/-](\d+)[/-](\d+)\s+(\d+):(\d+):(\d+)', line) + if not m: + return None + year, month, day, hour, minute, second = [int(g) for g in m.groups()] + return datetime.datetime(year, month, day, hour, minute, second) + + @pytest.fixture(scope='session') def mock_cvs_repository(tmpdir_factory): """Creates a very simple CVS repository with two commits and a branch.""" @@ -943,9 +947,8 @@ def mock_cvs_repository(tmpdir_factory): """Find the most recent CVS time stamp in a `cvs log` output""" latest_timestamp = None for line in output.splitlines(): - m = re.search(r'date:\s+([^;]*);', line) - if m: - timestamp = parse_date(m.group(1)) + timestamp = _parse_cvs_date(line) + if timestamp: if latest_timestamp is None: latest_timestamp = timestamp else: |