From de0aea98051f9d99f237e7edd27ae3e5c6bf1489 Mon Sep 17 00:00:00 2001 From: Jad Chaar Date: Mon, 11 Sep 2023 22:30:56 -0700 Subject: [PATCH] Fix failing builds and drop Py36 and 37 support (#1163) --- .github/workflows/continuous_integration.yml | 23 +-- .pre-commit-config.yaml | 14 +- .readthedocs.yaml | 29 +++ LICENSE | 2 +- Makefile | 7 +- arrow/arrow.py | 21 +- arrow/factory.py | 3 - arrow/formatter.py | 4 - arrow/locales.py | 17 +- arrow/parser.py | 16 +- docs/conf.py | 2 +- requirements/requirements-docs.txt | 4 +- requirements/requirements.txt | 1 - setup.py | 10 +- tests/test_arrow.py | 199 ------------------- tests/test_factory.py | 41 ---- tests/test_formatter.py | 13 -- tests/test_locales.py | 42 ---- tests/test_parser.py | 66 ------ tox.ini | 3 +- 20 files changed, 74 insertions(+), 443 deletions(-) create mode 100644 .readthedocs.yaml diff --git a/.github/workflows/continuous_integration.yml b/.github/workflows/continuous_integration.yml index 34d9c4f26..29b8df6d8 100644 --- a/.github/workflows/continuous_integration.yml +++ b/.github/workflows/continuous_integration.yml @@ -9,18 +9,18 @@ on: - cron: "0 0 1 * *" jobs: - test: + unit-tests: name: ${{ matrix.os }} (${{ matrix.python-version }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - python-version: ["pypy-3.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["pypy-3.9", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] os: [ubuntu-latest, macos-latest, windows-latest] exclude: # pypy3 randomly fails on Windows builds - os: windows-latest - python-version: "pypy-3.7" + python-version: "pypy-3.9" include: - os: ubuntu-latest path: ~/.cache/pip @@ -51,26 +51,25 @@ jobs: with: file: coverage.xml - lint: + linting: + name: Linting runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v4 - with: - python-version: "3.10" - - name: Cache pip - uses: actions/cache@v3 + - uses: actions/cache@v3 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }} restore-keys: ${{ runner.os }}-pip- - - name: Cache pre-commit - uses: actions/cache@v3 + - uses: actions/cache@v3 with: path: ~/.cache/pre-commit key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }} restore-keys: ${{ runner.os }}-pre-commit- + - name: Set up Python ${{ runner.python-version }} + uses: actions/setup-python@v4 + with: + python-version: "3.11" - name: Install dependencies run: | pip install -U pip setuptools wheel diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b035115ab..b8a60a2c1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-ast - id: check-yaml @@ -18,16 +18,16 @@ repos: args: [requirements/requirements.txt, requirements/requirements-docs.txt, requirements/requirements-tests.txt] - id: trailing-whitespace - repo: https://github.com/timothycrosley/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 + rev: v3.10.1 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.9.0 + rev: v1.10.0 hooks: - id: python-no-eval - id: python-check-blanket-noqa @@ -38,17 +38,17 @@ repos: - id: rst-inline-touching-normal - id: text-unicode-replacement-char - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.9.1 hooks: - id: black args: [--safe, --quiet, --target-version=py36] - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 + rev: 6.1.0 hooks: - id: flake8 additional_dependencies: [flake8-bugbear,flake8-annotations] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.5.1 hooks: - id: mypy additional_dependencies: [types-python-dateutil] diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 000000000..57f8dd088 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,29 @@ +# Read the Docs configuration file for Sphinx projects +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +version: 2 + +build: + os: ubuntu-22.04 + tools: + python: "3.11" + +# Build documentation in the "docs/" directory with Sphinx +sphinx: + configuration: docs/conf.py + # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs + # builder: "dirhtml" + # Fail on all warnings to avoid broken references + # fail_on_warning: true + +# Optionally build your docs in additional formats such as PDF and ePub +# formats: +# - pdf +# - epub + +# Optional but recommended, declare the Python requirements required +# to build your documentation +# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html +python: + install: + - requirements: requirements/requirements-docs.txt diff --git a/LICENSE b/LICENSE index 4f9eea5d1..ff864f3ba 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2021 Chris Smith + Copyright 2023 Chris Smith Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index f55a3dce9..27d5cbe47 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,14 @@ .PHONY: auto test docs clean -auto: build310 +auto: build311 -build36: PYTHON_VER = python3.6 -build37: PYTHON_VER = python3.7 build38: PYTHON_VER = python3.8 build39: PYTHON_VER = python3.9 build310: PYTHON_VER = python3.10 build311: PYTHON_VER = python3.11 +build312: PYTHON_VER = python3.12 -build36 build37 build38 build39 build310: clean +build36 build37 build38 build39 build310 build311 build312: clean $(PYTHON_VER) -m venv venv . venv/bin/activate; \ pip install -U pip setuptools wheel; \ diff --git a/arrow/arrow.py b/arrow/arrow.py index e855eee0c..8d329efd8 100644 --- a/arrow/arrow.py +++ b/arrow/arrow.py @@ -168,9 +168,9 @@ def __init__( isinstance(tzinfo, dt_tzinfo) and hasattr(tzinfo, "localize") and hasattr(tzinfo, "zone") - and tzinfo.zone # type: ignore[attr-defined] + and tzinfo.zone ): - tzinfo = parser.TzinfoParser.parse(tzinfo.zone) # type: ignore[attr-defined] + tzinfo = parser.TzinfoParser.parse(tzinfo.zone) elif isinstance(tzinfo, str): tzinfo = parser.TzinfoParser.parse(tzinfo) @@ -792,7 +792,6 @@ def __str__(self) -> str: return self._datetime.isoformat() def __format__(self, formatstr: str) -> str: - if len(formatstr) > 0: return self.format(formatstr) @@ -804,7 +803,6 @@ def __hash__(self) -> int: # attributes and properties def __getattr__(self, name: str) -> int: - if name == "week": return self.isocalendar()[1] @@ -965,7 +963,6 @@ def replace(self, **kwargs: Any) -> "Arrow": absolute_kwargs = {} for key, value in kwargs.items(): - if key in self._ATTRS: absolute_kwargs[key] = value elif key in ["week", "quarter"]: @@ -1022,7 +1019,6 @@ def shift(self, **kwargs: Any) -> "Arrow": additional_attrs = ["weeks", "quarters", "weekday"] for key, value in kwargs.items(): - if key in self._ATTRS_PLURAL or key in additional_attrs: relative_kwargs[key] = value else: @@ -1263,7 +1259,6 @@ def humanize( return locale.describe(granularity, delta, only_distance=only_distance) else: - if not granularity: raise ValueError( "Empty granularity list provided. " @@ -1367,7 +1362,6 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow": # Search input string for each time unit within locale for unit, unit_object in locale_obj.timeframes.items(): - # Need to check the type of unit_object to create the correct dictionary if isinstance(unit_object, Mapping): strings_to_search = unit_object @@ -1378,7 +1372,6 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow": # Needs to cycle all through strings as some locales have strings that # could overlap in a regex match, since input validation isn't being performed. for time_delta, time_string in strings_to_search.items(): - # Replace {0} with regex \d representing digits search_string = str(time_string) search_string = search_string.format(r"\d+") @@ -1718,7 +1711,6 @@ def for_json(self) -> str: # math def __add__(self, other: Any) -> "Arrow": - if isinstance(other, (timedelta, relativedelta)): return self.fromdatetime(self._datetime + other, self._datetime.tzinfo) @@ -1736,7 +1728,6 @@ def __sub__(self, other: Union[dt_datetime, "Arrow"]) -> timedelta: pass # pragma: no cover def __sub__(self, other: Any) -> Union[timedelta, "Arrow"]: - if isinstance(other, (timedelta, relativedelta)): return self.fromdatetime(self._datetime - other, self._datetime.tzinfo) @@ -1749,7 +1740,6 @@ def __sub__(self, other: Any) -> Union[timedelta, "Arrow"]: return NotImplemented def __rsub__(self, other: Any) -> timedelta: - if isinstance(other, dt_datetime): return other - self._datetime @@ -1758,42 +1748,36 @@ def __rsub__(self, other: Any) -> timedelta: # comparisons def __eq__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return False return self._datetime == self._get_datetime(other) def __ne__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return True return not self.__eq__(other) def __gt__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return NotImplemented return self._datetime > self._get_datetime(other) def __ge__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return NotImplemented return self._datetime >= self._get_datetime(other) def __lt__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return NotImplemented return self._datetime < self._get_datetime(other) def __le__(self, other: Any) -> bool: - if not isinstance(other, (Arrow, dt_datetime)): return NotImplemented @@ -1865,7 +1849,6 @@ def _get_frames(cls, name: _T_FRAMES) -> Tuple[str, str, int]: def _get_iteration_params(cls, end: Any, limit: Optional[int]) -> Tuple[Any, int]: """Sets default end and limit values for range method.""" if end is None: - if limit is None: raise ValueError("One of 'end' or 'limit' is required.") diff --git a/arrow/factory.py b/arrow/factory.py index aad4af8bd..f35085f1c 100644 --- a/arrow/factory.py +++ b/arrow/factory.py @@ -267,11 +267,9 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: raise TypeError(f"Cannot parse single argument of type {type(arg)!r}.") elif arg_count == 2: - arg_1, arg_2 = args[0], args[1] if isinstance(arg_1, datetime): - # (datetime, tzinfo/str) -> fromdatetime @ tzinfo if isinstance(arg_2, (dt_tzinfo, str)): return self.type.fromdatetime(arg_1, tzinfo=arg_2) @@ -281,7 +279,6 @@ def get(self, *args: Any, **kwargs: Any) -> Arrow: ) elif isinstance(arg_1, date): - # (date, tzinfo/str) -> fromdate @ tzinfo if isinstance(arg_2, (dt_tzinfo, str)): return self.type.fromdate(arg_1, tzinfo=arg_2) diff --git a/arrow/formatter.py b/arrow/formatter.py index 728bea1aa..d45f71539 100644 --- a/arrow/formatter.py +++ b/arrow/formatter.py @@ -29,7 +29,6 @@ class DateTimeFormatter: - # This pattern matches characters enclosed in square brackets are matched as # an atomic group. For more info on atomic groups and how to they are # emulated in Python's re library, see https://stackoverflow.com/a/13577411/2701578 @@ -41,18 +40,15 @@ class DateTimeFormatter: locale: locales.Locale def __init__(self, locale: str = DEFAULT_LOCALE) -> None: - self.locale = locales.get_locale(locale) def format(cls, dt: datetime, fmt: str) -> str: - # FIXME: _format_token() is nullable return cls._FORMAT_RE.sub( lambda m: cast(str, cls._format_token(dt, m.group(0))), fmt ) def _format_token(self, dt: datetime, token: Optional[str]) -> Optional[str]: - if token and token.startswith("[") and token.endswith("]"): return token[1:-1] diff --git a/arrow/locales.py b/arrow/locales.py index ea4c84b2a..b2e7ee03f 100644 --- a/arrow/locales.py +++ b/arrow/locales.py @@ -129,7 +129,6 @@ def __init_subclass__(cls, **kwargs: Any) -> None: _locale_map[locale_name.lower().replace("_", "-")] = cls def __init__(self) -> None: - self._month_name_to_ordinal = None def describe( @@ -174,7 +173,7 @@ def describe_multi( # Needed to determine the correct relative string to use timeframe_value = 0 - for _unit_name, unit_value in timeframes: + for _, unit_value in timeframes: if trunc(unit_value) != 0: timeframe_value = trunc(unit_value) break @@ -285,7 +284,6 @@ def _format_relative( timeframe: TimeFrameLiteral, delta: Union[float, int], ) -> str: - if timeframe == "now": return humanized @@ -1887,7 +1885,7 @@ class GermanBaseLocale(Locale): future = "in {0}" and_word = "und" - timeframes = { + timeframes: ClassVar[Dict[TimeFrameLiteral, str]] = { "now": "gerade eben", "second": "einer Sekunde", "seconds": "{0} Sekunden", @@ -1982,7 +1980,9 @@ def describe( return super().describe(timeframe, delta, only_distance) # German uses a different case without 'in' or 'ago' - humanized = self.timeframes_only_distance[timeframe].format(trunc(abs(delta))) + humanized: str = self.timeframes_only_distance[timeframe].format( + trunc(abs(delta)) + ) return humanized @@ -3936,7 +3936,6 @@ def _format_relative( class LaotianLocale(Locale): - names = ["lo", "lo-la"] past = "{0} ກ່ອນຫນ້ານີ້" @@ -5404,7 +5403,7 @@ class LuxembourgishLocale(Locale): future = "an {0}" and_word = "an" - timeframes = { + timeframes: ClassVar[Dict[TimeFrameLiteral, str]] = { "now": "just elo", "second": "enger Sekonn", "seconds": "{0} Sekonnen", @@ -5492,7 +5491,9 @@ def describe( return super().describe(timeframe, delta, only_distance) # Luxembourgish uses a different case without 'in' or 'ago' - humanized = self.timeframes_only_distance[timeframe].format(trunc(abs(delta))) + humanized: str = self.timeframes_only_distance[timeframe].format( + trunc(abs(delta)) + ) return humanized diff --git a/arrow/parser.py b/arrow/parser.py index ee31a5bc9..645e3da74 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -159,7 +159,6 @@ class DateTimeParser: _input_re_map: Dict[_FORMAT_TYPE, Pattern[str]] def __init__(self, locale: str = DEFAULT_LOCALE, cache_size: int = 0) -> None: - self.locale = locales.get_locale(locale) self._input_re_map = self._BASE_INPUT_RE_MAP.copy() self._input_re_map.update( @@ -187,7 +186,7 @@ def __init__(self, locale: str = DEFAULT_LOCALE, cache_size: int = 0) -> None: } ) if cache_size > 0: - self._generate_pattern_re = lru_cache(maxsize=cache_size)( # type: ignore[assignment] + self._generate_pattern_re = lru_cache(maxsize=cache_size)( # type: ignore self._generate_pattern_re ) @@ -196,7 +195,6 @@ def __init__(self, locale: str = DEFAULT_LOCALE, cache_size: int = 0) -> None: def parse_iso( self, datetime_string: str, normalize_whitespace: bool = False ) -> datetime: - if normalize_whitespace: datetime_string = re.sub(r"\s+", " ", datetime_string.strip()) @@ -236,13 +234,14 @@ def parse_iso( ] if has_time: - if has_space_divider: date_string, time_string = datetime_string.split(" ", 1) else: date_string, time_string = datetime_string.split("T", 1) - time_parts = re.split(r"[\+\-Z]", time_string, 1, re.IGNORECASE) + time_parts = re.split( + r"[\+\-Z]", time_string, maxsplit=1, flags=re.IGNORECASE + ) time_components: Optional[Match[str]] = self._TIME_RE.match(time_parts[0]) @@ -303,7 +302,6 @@ def parse( fmt: Union[List[str], str], normalize_whitespace: bool = False, ) -> datetime: - if normalize_whitespace: datetime_string = re.sub(r"\s+", " ", datetime_string) @@ -346,7 +344,6 @@ def parse( return self._build_datetime(parts) def _generate_pattern_re(self, fmt: str) -> Tuple[List[_FORMAT_TYPE], Pattern[str]]: - # fmt is a string of tokens like 'YYYY-MM-DD' # we construct a new string by replacing each # token by its pattern: @@ -498,7 +495,6 @@ def _parse_token( value: Any, parts: _Parts, ) -> None: - if token == "YYYY": parts["year"] = int(value) @@ -588,7 +584,6 @@ def _build_datetime(parts: _Parts) -> datetime: weekdate = parts.get("weekdate") if weekdate is not None: - year, week = int(weekdate[0]), int(weekdate[1]) if weekdate[2] is not None: @@ -712,7 +707,6 @@ def _build_datetime(parts: _Parts) -> datetime: ) def _parse_multiformat(self, string: str, formats: Iterable[str]) -> datetime: - _datetime: Optional[datetime] = None for fmt in formats: @@ -745,7 +739,6 @@ class TzinfoParser: @classmethod def parse(cls, tzinfo_string: str) -> dt_tzinfo: - tzinfo: Optional[dt_tzinfo] = None if tzinfo_string == "local": @@ -755,7 +748,6 @@ def parse(cls, tzinfo_string: str) -> dt_tzinfo: tzinfo = tz.tzutc() else: - iso_match = cls._TZINFO_RE.match(tzinfo_string) if iso_match: diff --git a/docs/conf.py b/docs/conf.py index dee714701..aa6fb4440 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -13,7 +13,7 @@ # -- Project information ----------------------------------------------------- project = "Arrow 🏹" -copyright = "2021, Chris Smith" +copyright = "2023, Chris Smith" author = "Chris Smith" release = about["__version__"] diff --git a/requirements/requirements-docs.txt b/requirements/requirements-docs.txt index abc47b28d..35ca4ded4 100644 --- a/requirements/requirements-docs.txt +++ b/requirements/requirements-docs.txt @@ -1,6 +1,6 @@ -r requirements.txt doc8 -sphinx +sphinx>=7.0.0 sphinx-autobuild sphinx-autodoc-typehints -sphinx_rtd_theme +sphinx_rtd_theme>=1.3.0 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index bcdff0e86..65134a19a 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,2 +1 @@ python-dateutil>=2.7.0 -typing_extensions; python_version < '3.8' diff --git a/setup.py b/setup.py index 52563cf9a..a2d8921eb 100644 --- a/setup.py +++ b/setup.py @@ -21,11 +21,8 @@ packages=["arrow"], package_data={"arrow": ["py.typed"]}, zip_safe=False, - python_requires=">=3.6", - install_requires=[ - "python-dateutil>=2.7.0", - "typing_extensions; python_version<'3.8'", - ], + python_requires=">=3.8", + install_requires=["python-dateutil>=2.7.0"], classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", @@ -33,12 +30,11 @@ "Topic :: Software Development :: Libraries :: Python Modules", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], keywords="arrow date time datetime timestamp timezone humanize", project_urls={ diff --git a/tests/test_arrow.py b/tests/test_arrow.py index 5cd12c827..507c1ab0f 100644 --- a/tests/test_arrow.py +++ b/tests/test_arrow.py @@ -18,7 +18,6 @@ class TestTestArrowInit: def test_init_bad_input(self): - with pytest.raises(TypeError): arrow.Arrow(2013) @@ -29,7 +28,6 @@ def test_init_bad_input(self): arrow.Arrow(2013, 2, 2, 12, 30, 45, 9999999) def test_init(self): - result = arrow.Arrow(2013, 2, 2) self.expected = datetime(2013, 2, 2, tzinfo=tz.tzutc()) assert result._datetime == self.expected @@ -60,7 +58,6 @@ def test_init(self): # regression tests for issue #626 def test_init_pytz_timezone(self): - result = arrow.Arrow( 2013, 2, 2, 12, 30, 45, 999999, tzinfo=pytz.timezone("Europe/Paris") ) @@ -84,7 +81,6 @@ def test_init_with_fold(self): class TestTestArrowFactory: def test_now(self): - result = arrow.Arrow.now() assert_datetime_equality( @@ -92,7 +88,6 @@ def test_now(self): ) def test_utcnow(self): - result = arrow.Arrow.utcnow() assert_datetime_equality( @@ -102,7 +97,6 @@ def test_utcnow(self): assert result.fold == 0 def test_fromtimestamp(self): - timestamp = time.time() result = arrow.Arrow.fromtimestamp(timestamp) @@ -126,7 +120,6 @@ def test_fromtimestamp(self): arrow.Arrow.fromtimestamp("invalid timestamp") def test_utcfromtimestamp(self): - timestamp = time.time() result = arrow.Arrow.utcfromtimestamp(timestamp) @@ -138,7 +131,6 @@ def test_utcfromtimestamp(self): arrow.Arrow.utcfromtimestamp("invalid timestamp") def test_fromdatetime(self): - dt = datetime(2013, 2, 3, 12, 30, 45, 1) result = arrow.Arrow.fromdatetime(dt) @@ -146,7 +138,6 @@ def test_fromdatetime(self): assert result._datetime == dt.replace(tzinfo=tz.tzutc()) def test_fromdatetime_dt_tzinfo(self): - dt = datetime(2013, 2, 3, 12, 30, 45, 1, tzinfo=tz.gettz("US/Pacific")) result = arrow.Arrow.fromdatetime(dt) @@ -154,7 +145,6 @@ def test_fromdatetime_dt_tzinfo(self): assert result._datetime == dt.replace(tzinfo=tz.gettz("US/Pacific")) def test_fromdatetime_tzinfo_arg(self): - dt = datetime(2013, 2, 3, 12, 30, 45, 1) result = arrow.Arrow.fromdatetime(dt, tz.gettz("US/Pacific")) @@ -162,7 +152,6 @@ def test_fromdatetime_tzinfo_arg(self): assert result._datetime == dt.replace(tzinfo=tz.gettz("US/Pacific")) def test_fromdate(self): - dt = date(2013, 2, 3) result = arrow.Arrow.fromdate(dt, tz.gettz("US/Pacific")) @@ -170,7 +159,6 @@ def test_fromdate(self): assert result._datetime == datetime(2013, 2, 3, tzinfo=tz.gettz("US/Pacific")) def test_strptime(self): - formatted = datetime(2013, 2, 3, 12, 30, 45).strftime("%Y-%m-%d %H:%M:%S") result = arrow.Arrow.strptime(formatted, "%Y-%m-%d %H:%M:%S") @@ -184,7 +172,6 @@ def test_strptime(self): ) def test_fromordinal(self): - timestamp = 1607066909.937968 with pytest.raises(TypeError): arrow.Arrow.fromordinal(timestamp) @@ -205,43 +192,36 @@ def test_fromordinal(self): @pytest.mark.usefixtures("time_2013_02_03") class TestTestArrowRepresentation: def test_repr(self): - result = self.arrow.__repr__() assert result == f"" def test_str(self): - result = self.arrow.__str__() assert result == self.arrow._datetime.isoformat() def test_hash(self): - result = self.arrow.__hash__() assert result == self.arrow._datetime.__hash__() def test_format(self): - result = f"{self.arrow:YYYY-MM-DD}" assert result == "2013-02-03" def test_bare_format(self): - result = self.arrow.format() assert result == "2013-02-03 12:30:45+00:00" def test_format_no_format_string(self): - result = f"{self.arrow}" assert result == str(self.arrow) def test_clone(self): - result = self.arrow.clone() assert result is not self.arrow @@ -251,12 +231,10 @@ def test_clone(self): @pytest.mark.usefixtures("time_2013_01_01") class TestArrowAttribute: def test_getattr_base(self): - with pytest.raises(AttributeError): self.arrow.prop def test_getattr_week(self): - assert self.arrow.week == 1 def test_getattr_quarter(self): @@ -281,31 +259,24 @@ def test_getattr_quarter(self): assert q4.quarter == 4 def test_getattr_dt_value(self): - assert self.arrow.year == 2013 def test_tzinfo(self): - assert self.arrow.tzinfo == tz.tzutc() def test_naive(self): - assert self.arrow.naive == self.arrow._datetime.replace(tzinfo=None) def test_timestamp(self): - assert self.arrow.timestamp() == self.arrow._datetime.timestamp() def test_int_timestamp(self): - assert self.arrow.int_timestamp == int(self.arrow._datetime.timestamp()) def test_float_timestamp(self): - assert self.arrow.float_timestamp == self.arrow._datetime.timestamp() def test_getattr_fold(self): - # UTC is always unambiguous assert self.now.fold == 0 @@ -318,7 +289,6 @@ def test_getattr_fold(self): ambiguous_dt.fold = 0 def test_getattr_ambiguous(self): - assert not self.now.ambiguous ambiguous_dt = arrow.Arrow(2017, 10, 29, 2, 0, tzinfo="Europe/Stockholm") @@ -326,7 +296,6 @@ def test_getattr_ambiguous(self): assert ambiguous_dt.ambiguous def test_getattr_imaginary(self): - assert not self.now.imaginary imaginary_dt = arrow.Arrow(2013, 3, 31, 2, 30, tzinfo="Europe/Paris") @@ -337,19 +306,16 @@ def test_getattr_imaginary(self): @pytest.mark.usefixtures("time_utcnow") class TestArrowComparison: def test_eq(self): - assert self.arrow == self.arrow assert self.arrow == self.arrow.datetime assert not (self.arrow == "abc") def test_ne(self): - assert not (self.arrow != self.arrow) assert not (self.arrow != self.arrow.datetime) assert self.arrow != "abc" def test_gt(self): - arrow_cmp = self.arrow.shift(minutes=1) assert not (self.arrow > self.arrow) @@ -362,7 +328,6 @@ def test_gt(self): assert self.arrow < arrow_cmp.datetime def test_ge(self): - with pytest.raises(TypeError): self.arrow >= "abc" # noqa: B015 @@ -370,7 +335,6 @@ def test_ge(self): assert self.arrow >= self.arrow.datetime def test_lt(self): - arrow_cmp = self.arrow.shift(minutes=1) assert not (self.arrow < self.arrow) @@ -383,7 +347,6 @@ def test_lt(self): assert self.arrow < arrow_cmp.datetime def test_le(self): - with pytest.raises(TypeError): self.arrow <= "abc" # noqa: B015 @@ -394,53 +357,44 @@ def test_le(self): @pytest.mark.usefixtures("time_2013_01_01") class TestArrowMath: def test_add_timedelta(self): - result = self.arrow.__add__(timedelta(days=1)) assert result._datetime == datetime(2013, 1, 2, tzinfo=tz.tzutc()) def test_add_other(self): - with pytest.raises(TypeError): self.arrow + 1 def test_radd(self): - result = self.arrow.__radd__(timedelta(days=1)) assert result._datetime == datetime(2013, 1, 2, tzinfo=tz.tzutc()) def test_sub_timedelta(self): - result = self.arrow.__sub__(timedelta(days=1)) assert result._datetime == datetime(2012, 12, 31, tzinfo=tz.tzutc()) def test_sub_datetime(self): - result = self.arrow.__sub__(datetime(2012, 12, 21, tzinfo=tz.tzutc())) assert result == timedelta(days=11) def test_sub_arrow(self): - result = self.arrow.__sub__(arrow.Arrow(2012, 12, 21, tzinfo=tz.tzutc())) assert result == timedelta(days=11) def test_sub_other(self): - with pytest.raises(TypeError): self.arrow - object() def test_rsub_datetime(self): - result = self.arrow.__rsub__(datetime(2012, 12, 21, tzinfo=tz.tzutc())) assert result == timedelta(days=-11) def test_rsub_other(self): - with pytest.raises(TypeError): timedelta(days=1) - self.arrow @@ -448,25 +402,21 @@ def test_rsub_other(self): @pytest.mark.usefixtures("time_utcnow") class TestArrowDatetimeInterface: def test_date(self): - result = self.arrow.date() assert result == self.arrow._datetime.date() def test_time(self): - result = self.arrow.time() assert result == self.arrow._datetime.time() def test_timetz(self): - result = self.arrow.timetz() assert result == self.arrow._datetime.timetz() def test_astimezone(self): - other_tz = tz.gettz("US/Pacific") result = self.arrow.astimezone(other_tz) @@ -474,61 +424,51 @@ def test_astimezone(self): assert result == self.arrow._datetime.astimezone(other_tz) def test_utcoffset(self): - result = self.arrow.utcoffset() assert result == self.arrow._datetime.utcoffset() def test_dst(self): - result = self.arrow.dst() assert result == self.arrow._datetime.dst() def test_timetuple(self): - result = self.arrow.timetuple() assert result == self.arrow._datetime.timetuple() def test_utctimetuple(self): - result = self.arrow.utctimetuple() assert result == self.arrow._datetime.utctimetuple() def test_toordinal(self): - result = self.arrow.toordinal() assert result == self.arrow._datetime.toordinal() def test_weekday(self): - result = self.arrow.weekday() assert result == self.arrow._datetime.weekday() def test_isoweekday(self): - result = self.arrow.isoweekday() assert result == self.arrow._datetime.isoweekday() def test_isocalendar(self): - result = self.arrow.isocalendar() assert result == self.arrow._datetime.isocalendar() def test_isoformat(self): - result = self.arrow.isoformat() assert result == self.arrow._datetime.isoformat() def test_isoformat_timespec(self): - result = self.arrow.isoformat(timespec="hours") assert result == self.arrow._datetime.isoformat(timespec="hours") @@ -542,19 +482,16 @@ def test_isoformat_timespec(self): assert result == self.arrow._datetime.isoformat(sep="x", timespec="seconds") def test_simplejson(self): - result = json.dumps({"v": self.arrow.for_json()}, for_json=True) assert json.loads(result)["v"] == self.arrow._datetime.isoformat() def test_ctime(self): - result = self.arrow.ctime() assert result == self.arrow._datetime.ctime() def test_strftime(self): - result = self.arrow.strftime("%Y") assert result == self.arrow._datetime.strftime("%Y") @@ -609,7 +546,6 @@ def test_dst(self): class TestArrowConversion: def test_to(self): - dt_from = datetime.now() arrow_from = arrow.Arrow.fromdatetime(dt_from, tz.gettz("US/Pacific")) @@ -632,7 +568,6 @@ def test_to_amsterdam_then_utc(self): # regression test for #690 def test_to_israel_same_offset(self): - result = arrow.Arrow(2019, 10, 27, 2, 21, 1, tzinfo="+03:00").to("Israel") expected = arrow.Arrow(2019, 10, 27, 1, 21, 1, tzinfo="Israel") @@ -648,7 +583,6 @@ def test_anchorage_dst(self): # issue 476 def test_chicago_fall(self): - result = arrow.Arrow(2017, 11, 5, 2, 1, tzinfo="-05:00").to("America/Chicago") expected = arrow.Arrow(2017, 11, 5, 1, 1, tzinfo="America/Chicago") @@ -656,7 +590,6 @@ def test_chicago_fall(self): assert result.utcoffset() != expected.utcoffset() def test_toronto_gap(self): - before = arrow.Arrow(2011, 3, 13, 6, 30, tzinfo="UTC").to("America/Toronto") after = arrow.Arrow(2011, 3, 13, 7, 30, tzinfo="UTC").to("America/Toronto") @@ -666,7 +599,6 @@ def test_toronto_gap(self): assert before.utcoffset() != after.utcoffset() def test_sydney_gap(self): - before = arrow.Arrow(2012, 10, 6, 15, 30, tzinfo="UTC").to("Australia/Sydney") after = arrow.Arrow(2012, 10, 6, 16, 30, tzinfo="UTC").to("Australia/Sydney") @@ -678,7 +610,6 @@ def test_sydney_gap(self): class TestArrowPickling: def test_pickle_and_unpickle(self): - dt = arrow.Arrow.utcnow() pickled = pickle.dumps(dt) @@ -690,12 +621,10 @@ def test_pickle_and_unpickle(self): class TestArrowReplace: def test_not_attr(self): - with pytest.raises(ValueError): arrow.Arrow.utcnow().replace(abc=1) def test_replace(self): - arw = arrow.Arrow(2013, 5, 5, 12, 30, 45) assert arw.replace(year=2012) == arrow.Arrow(2012, 5, 5, 12, 30, 45) @@ -706,7 +635,6 @@ def test_replace(self): assert arw.replace(second=1) == arrow.Arrow(2013, 5, 5, 12, 30, 1) def test_replace_tzinfo(self): - arw = arrow.Arrow.utcnow().to("US/Eastern") result = arw.replace(tzinfo=tz.gettz("US/Pacific")) @@ -714,7 +642,6 @@ def test_replace_tzinfo(self): assert result == arw.datetime.replace(tzinfo=tz.gettz("US/Pacific")) def test_replace_fold(self): - before = arrow.Arrow(2017, 11, 5, 1, tzinfo="America/New_York") after = before.replace(fold=1) @@ -724,19 +651,16 @@ def test_replace_fold(self): assert before.utcoffset() != after.utcoffset() def test_replace_fold_and_other(self): - arw = arrow.Arrow(2013, 5, 5, 12, 30, 45) assert arw.replace(fold=1, minute=50) == arrow.Arrow(2013, 5, 5, 12, 50, 45) assert arw.replace(minute=50, fold=1) == arrow.Arrow(2013, 5, 5, 12, 50, 45) def test_replace_week(self): - with pytest.raises(ValueError): arrow.Arrow.utcnow().replace(week=1) def test_replace_quarter(self): - with pytest.raises(ValueError): arrow.Arrow.utcnow().replace(quarter=1) @@ -748,14 +672,12 @@ def test_replace_quarter_and_fold(self): arrow.utcnow().replace(quarter=1, fold=1) def test_replace_other_kwargs(self): - with pytest.raises(AttributeError): arrow.utcnow().replace(abc="def") class TestArrowShift: def test_not_attr(self): - now = arrow.Arrow.utcnow() with pytest.raises(ValueError): @@ -765,7 +687,6 @@ def test_not_attr(self): now.shift(week=1) def test_shift(self): - arw = arrow.Arrow(2013, 5, 5, 12, 30, 45) assert arw.shift(years=1) == arrow.Arrow(2014, 5, 5, 12, 30, 45) @@ -822,7 +743,6 @@ def test_shift(self): assert arw.shift(weekday=SU(2)) == arrow.Arrow(2013, 5, 12, 12, 30, 45) def test_shift_negative(self): - arw = arrow.Arrow(2013, 5, 5, 12, 30, 45) assert arw.shift(years=-1) == arrow.Arrow(2012, 5, 5, 12, 30, 45) @@ -858,7 +778,6 @@ def test_shift_negative(self): assert arw.shift(weekday=SU(-2)) == arrow.Arrow(2013, 4, 28, 12, 30, 45) def test_shift_quarters_bug(self): - arw = arrow.Arrow(2013, 5, 5, 12, 30, 45) # The value of the last-read argument was used instead of the ``quarters`` argument. @@ -876,7 +795,6 @@ def test_shift_quarters_bug(self): ) def test_shift_positive_imaginary(self): - # Avoid shifting into imaginary datetimes, take into account DST and other timezone changes. new_york = arrow.Arrow(2017, 3, 12, 1, 30, tzinfo="America/New_York") @@ -907,7 +825,6 @@ def test_shift_positive_imaginary(self): ) def test_shift_negative_imaginary(self): - new_york = arrow.Arrow(2011, 3, 13, 3, 30, tzinfo="America/New_York") assert new_york.shift(hours=-1) == arrow.Arrow( 2011, 3, 13, 3, 30, tzinfo="America/New_York" @@ -951,7 +868,6 @@ def shift_imaginary_seconds(self): class TestArrowRange: def test_year(self): - result = list( arrow.Arrow.range( "year", datetime(2013, 1, 2, 3, 4, 5), datetime(2016, 4, 5, 6, 7, 8) @@ -966,7 +882,6 @@ def test_year(self): ] def test_quarter(self): - result = list( arrow.Arrow.range( "quarter", datetime(2013, 2, 3, 4, 5, 6), datetime(2013, 5, 6, 7, 8, 9) @@ -979,7 +894,6 @@ def test_quarter(self): ] def test_month(self): - result = list( arrow.Arrow.range( "month", datetime(2013, 2, 3, 4, 5, 6), datetime(2013, 5, 6, 7, 8, 9) @@ -994,7 +908,6 @@ def test_month(self): ] def test_week(self): - result = list( arrow.Arrow.range( "week", datetime(2013, 9, 1, 2, 3, 4), datetime(2013, 10, 1, 2, 3, 4) @@ -1010,7 +923,6 @@ def test_week(self): ] def test_day(self): - result = list( arrow.Arrow.range( "day", datetime(2013, 1, 2, 3, 4, 5), datetime(2013, 1, 5, 6, 7, 8) @@ -1025,7 +937,6 @@ def test_day(self): ] def test_hour(self): - result = list( arrow.Arrow.range( "hour", datetime(2013, 1, 2, 3, 4, 5), datetime(2013, 1, 2, 6, 7, 8) @@ -1048,7 +959,6 @@ def test_hour(self): assert result == [arrow.Arrow(2013, 1, 2, 3, 4, 5)] def test_minute(self): - result = list( arrow.Arrow.range( "minute", datetime(2013, 1, 2, 3, 4, 5), datetime(2013, 1, 2, 3, 7, 8) @@ -1063,7 +973,6 @@ def test_minute(self): ] def test_second(self): - result = list( arrow.Arrow.range( "second", datetime(2013, 1, 2, 3, 4, 5), datetime(2013, 1, 2, 3, 4, 8) @@ -1078,7 +987,6 @@ def test_second(self): ] def test_arrow(self): - result = list( arrow.Arrow.range( "day", @@ -1095,7 +1003,6 @@ def test_arrow(self): ] def test_naive_tz(self): - result = arrow.Arrow.range( "year", datetime(2013, 1, 2, 3), datetime(2016, 4, 5, 6), "US/Pacific" ) @@ -1104,7 +1011,6 @@ def test_naive_tz(self): assert r.tzinfo == tz.gettz("US/Pacific") def test_aware_same_tz(self): - result = arrow.Arrow.range( "day", arrow.Arrow(2013, 1, 1, tzinfo=tz.gettz("US/Pacific")), @@ -1115,7 +1021,6 @@ def test_aware_same_tz(self): assert r.tzinfo == tz.gettz("US/Pacific") def test_aware_different_tz(self): - result = arrow.Arrow.range( "day", datetime(2013, 1, 1, tzinfo=tz.gettz("US/Eastern")), @@ -1126,7 +1031,6 @@ def test_aware_different_tz(self): assert r.tzinfo == tz.gettz("US/Eastern") def test_aware_tz(self): - result = arrow.Arrow.range( "day", datetime(2013, 1, 1, tzinfo=tz.gettz("US/Eastern")), @@ -1150,7 +1054,6 @@ def test_imaginary(self): assert len(utc_range) == len(set(utc_range)) def test_unsupported(self): - with pytest.raises(ValueError): next(arrow.Arrow.range("abc", datetime.utcnow(), datetime.utcnow())) @@ -1206,7 +1109,6 @@ def test_range_over_year_maintains_end_date_across_leap_year(self): class TestArrowSpanRange: def test_year(self): - result = list( arrow.Arrow.span_range("year", datetime(2013, 2, 1), datetime(2016, 3, 31)) ) @@ -1231,7 +1133,6 @@ def test_year(self): ] def test_quarter(self): - result = list( arrow.Arrow.span_range( "quarter", datetime(2013, 2, 2), datetime(2013, 5, 15) @@ -1244,7 +1145,6 @@ def test_quarter(self): ] def test_month(self): - result = list( arrow.Arrow.span_range("month", datetime(2013, 1, 2), datetime(2013, 4, 15)) ) @@ -1257,7 +1157,6 @@ def test_month(self): ] def test_week(self): - result = list( arrow.Arrow.span_range("week", datetime(2013, 2, 2), datetime(2013, 2, 28)) ) @@ -1277,7 +1176,6 @@ def test_week(self): ] def test_day(self): - result = list( arrow.Arrow.span_range( "day", datetime(2013, 1, 1, 12), datetime(2013, 1, 4, 12) @@ -1304,7 +1202,6 @@ def test_day(self): ] def test_days(self): - result = list( arrow.Arrow.span_range( "days", datetime(2013, 1, 1, 12), datetime(2013, 1, 4, 12) @@ -1331,7 +1228,6 @@ def test_days(self): ] def test_hour(self): - result = list( arrow.Arrow.span_range( "hour", datetime(2013, 1, 1, 0, 30), datetime(2013, 1, 1, 3, 30) @@ -1368,7 +1264,6 @@ def test_hour(self): ] def test_minute(self): - result = list( arrow.Arrow.span_range( "minute", datetime(2013, 1, 1, 0, 0, 30), datetime(2013, 1, 1, 0, 3, 30) @@ -1395,7 +1290,6 @@ def test_minute(self): ] def test_second(self): - result = list( arrow.Arrow.span_range( "second", datetime(2013, 1, 1), datetime(2013, 1, 1, 0, 0, 3) @@ -1422,7 +1316,6 @@ def test_second(self): ] def test_naive_tz(self): - tzinfo = tz.gettz("US/Pacific") result = arrow.Arrow.span_range( @@ -1434,7 +1327,6 @@ def test_naive_tz(self): assert c.tzinfo == tzinfo def test_aware_same_tz(self): - tzinfo = tz.gettz("US/Pacific") result = arrow.Arrow.span_range( @@ -1448,7 +1340,6 @@ def test_aware_same_tz(self): assert c.tzinfo == tzinfo def test_aware_different_tz(self): - tzinfo1 = tz.gettz("US/Pacific") tzinfo2 = tz.gettz("US/Eastern") @@ -1463,7 +1354,6 @@ def test_aware_different_tz(self): assert c.tzinfo == tzinfo1 def test_aware_tz(self): - result = arrow.Arrow.span_range( "hour", datetime(2013, 1, 1, 0, tzinfo=tz.gettz("US/Eastern")), @@ -1476,7 +1366,6 @@ def test_aware_tz(self): assert c.tzinfo == tz.gettz("US/Central") def test_bounds_param_is_passed(self): - result = list( arrow.Arrow.span_range( "quarter", datetime(2013, 2, 2), datetime(2013, 5, 15), bounds="[]" @@ -1489,7 +1378,6 @@ def test_bounds_param_is_passed(self): ] def test_exact_bound_exclude(self): - result = list( arrow.Arrow.span_range( "hour", @@ -1709,40 +1597,34 @@ def test_exact(self): @pytest.mark.usefixtures("time_2013_02_15") class TestArrowSpan: def test_span_attribute(self): - with pytest.raises(ValueError): self.arrow.span("span") def test_span_year(self): - floor, ceil = self.arrow.span("year") assert floor == datetime(2013, 1, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 12, 31, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_quarter(self): - floor, ceil = self.arrow.span("quarter") assert floor == datetime(2013, 1, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 3, 31, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_quarter_count(self): - floor, ceil = self.arrow.span("quarter", 2) assert floor == datetime(2013, 1, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 6, 30, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_year_count(self): - floor, ceil = self.arrow.span("year", 2) assert floor == datetime(2013, 1, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2014, 12, 31, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_month(self): - floor, ceil = self.arrow.span("month") assert floor == datetime(2013, 2, 1, tzinfo=tz.tzutc()) @@ -1775,75 +1657,64 @@ def test_span_week(self): assert ceil == datetime(2013, 2, 16, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_day(self): - floor, ceil = self.arrow.span("day") assert floor == datetime(2013, 2, 15, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 23, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_hour(self): - floor, ceil = self.arrow.span("hour") assert floor == datetime(2013, 2, 15, 3, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 59, 59, 999999, tzinfo=tz.tzutc()) def test_span_minute(self): - floor, ceil = self.arrow.span("minute") assert floor == datetime(2013, 2, 15, 3, 41, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 41, 59, 999999, tzinfo=tz.tzutc()) def test_span_second(self): - floor, ceil = self.arrow.span("second") assert floor == datetime(2013, 2, 15, 3, 41, 22, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 41, 22, 999999, tzinfo=tz.tzutc()) def test_span_microsecond(self): - floor, ceil = self.arrow.span("microsecond") assert floor == datetime(2013, 2, 15, 3, 41, 22, 8923, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 41, 22, 8923, tzinfo=tz.tzutc()) def test_floor(self): - floor, ceil = self.arrow.span("month") assert floor == self.arrow.floor("month") assert ceil == self.arrow.ceil("month") def test_span_inclusive_inclusive(self): - floor, ceil = self.arrow.span("hour", bounds="[]") assert floor == datetime(2013, 2, 15, 3, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 4, tzinfo=tz.tzutc()) def test_span_exclusive_inclusive(self): - floor, ceil = self.arrow.span("hour", bounds="(]") assert floor == datetime(2013, 2, 15, 3, 0, 0, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 4, tzinfo=tz.tzutc()) def test_span_exclusive_exclusive(self): - floor, ceil = self.arrow.span("hour", bounds="()") assert floor == datetime(2013, 2, 15, 3, 0, 0, 1, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 59, 59, 999999, tzinfo=tz.tzutc()) def test_bounds_are_validated(self): - with pytest.raises(ValueError): floor, ceil = self.arrow.span("hour", bounds="][") def test_exact(self): - result_floor, result_ceil = self.arrow.span("hour", exact=True) expected_floor = datetime(2013, 2, 15, 3, 41, 22, 8923, tzinfo=tz.tzutc()) @@ -1853,28 +1724,24 @@ def test_exact(self): assert result_ceil == expected_ceil def test_exact_inclusive_inclusive(self): - floor, ceil = self.arrow.span("minute", bounds="[]", exact=True) assert floor == datetime(2013, 2, 15, 3, 41, 22, 8923, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 42, 22, 8923, tzinfo=tz.tzutc()) def test_exact_exclusive_inclusive(self): - floor, ceil = self.arrow.span("day", bounds="(]", exact=True) assert floor == datetime(2013, 2, 15, 3, 41, 22, 8924, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 16, 3, 41, 22, 8923, tzinfo=tz.tzutc()) def test_exact_exclusive_exclusive(self): - floor, ceil = self.arrow.span("second", bounds="()", exact=True) assert floor == datetime(2013, 2, 15, 3, 41, 22, 8924, tzinfo=tz.tzutc()) assert ceil == datetime(2013, 2, 15, 3, 41, 23, 8922, tzinfo=tz.tzutc()) def test_all_parameters_specified(self): - floor, ceil = self.arrow.span("week", bounds="()", exact=True, count=2) assert floor == datetime(2013, 2, 15, 3, 41, 22, 8924, tzinfo=tz.tzutc()) @@ -1884,7 +1751,6 @@ def test_all_parameters_specified(self): @pytest.mark.usefixtures("time_2013_01_01") class TestArrowHumanize: def test_granularity(self): - assert self.now.humanize(granularity="second") == "just now" later1 = self.now.shift(seconds=1) @@ -2054,7 +1920,6 @@ def test_multiple_granularity(self): ) def test_seconds(self): - later = self.now.shift(seconds=10) # regression test for issue #727 @@ -2065,7 +1930,6 @@ def test_seconds(self): assert later.humanize(self.now, only_distance=True) == "10 seconds" def test_minute(self): - later = self.now.shift(minutes=1) assert self.now.humanize(later) == "a minute ago" @@ -2075,7 +1939,6 @@ def test_minute(self): assert later.humanize(self.now, only_distance=True) == "a minute" def test_minutes(self): - later = self.now.shift(minutes=2) assert self.now.humanize(later) == "2 minutes ago" @@ -2085,7 +1948,6 @@ def test_minutes(self): assert later.humanize(self.now, only_distance=True) == "2 minutes" def test_hour(self): - later = self.now.shift(hours=1) assert self.now.humanize(later) == "an hour ago" @@ -2095,7 +1957,6 @@ def test_hour(self): assert later.humanize(self.now, only_distance=True) == "an hour" def test_hours(self): - later = self.now.shift(hours=2) assert self.now.humanize(later) == "2 hours ago" @@ -2105,7 +1966,6 @@ def test_hours(self): assert later.humanize(self.now, only_distance=True) == "2 hours" def test_day(self): - later = self.now.shift(days=1) assert self.now.humanize(later) == "a day ago" @@ -2127,7 +1987,6 @@ def test_day(self): assert later.humanize(self.now, only_distance=True) == "a day" def test_days(self): - later = self.now.shift(days=2) assert self.now.humanize(later) == "2 days ago" @@ -2147,7 +2006,6 @@ def test_days(self): assert later.humanize(self.now) == "in 4 days" def test_week(self): - later = self.now.shift(weeks=1) assert self.now.humanize(later) == "a week ago" @@ -2157,7 +2015,6 @@ def test_week(self): assert later.humanize(self.now, only_distance=True) == "a week" def test_weeks(self): - later = self.now.shift(weeks=2) assert self.now.humanize(later) == "2 weeks ago" @@ -2168,7 +2025,6 @@ def test_weeks(self): @pytest.mark.xfail(reason="known issue with humanize month limits") def test_month(self): - later = self.now.shift(months=1) # TODO this test now returns "4 weeks ago", we need to fix this to be correct on a per month basis @@ -2179,7 +2035,6 @@ def test_month(self): assert later.humanize(self.now, only_distance=True) == "a month" def test_month_plus_4_days(self): - # TODO needed for coverage, remove when month limits are fixed later = self.now.shift(months=1, days=4) @@ -2188,7 +2043,6 @@ def test_month_plus_4_days(self): @pytest.mark.xfail(reason="known issue with humanize month limits") def test_months(self): - later = self.now.shift(months=2) earlier = self.now.shift(months=-2) @@ -2199,7 +2053,6 @@ def test_months(self): assert later.humanize(self.now, only_distance=True) == "2 months" def test_year(self): - later = self.now.shift(years=1) assert self.now.humanize(later) == "a year ago" @@ -2209,7 +2062,6 @@ def test_year(self): assert later.humanize(self.now, only_distance=True) == "a year" def test_years(self): - later = self.now.shift(years=2) assert self.now.humanize(later) == "2 years ago" @@ -2225,7 +2077,6 @@ def test_years(self): assert result == "in a year" def test_arrow(self): - arw = arrow.Arrow.fromdatetime(self.datetime) result = arw.humanize(arrow.Arrow.fromdatetime(self.datetime)) @@ -2233,7 +2084,6 @@ def test_arrow(self): assert result == "just now" def test_datetime_tzinfo(self): - arw = arrow.Arrow.fromdatetime(self.datetime) result = arw.humanize(self.datetime.replace(tzinfo=tz.tzutc())) @@ -2241,21 +2091,18 @@ def test_datetime_tzinfo(self): assert result == "just now" def test_other(self): - arw = arrow.Arrow.fromdatetime(self.datetime) with pytest.raises(TypeError): arw.humanize(object()) def test_invalid_locale(self): - arw = arrow.Arrow.fromdatetime(self.datetime) with pytest.raises(ValueError): arw.humanize(locale="klingon") def test_none(self): - arw = arrow.Arrow.utcnow() result = arw.humanize() @@ -2277,7 +2124,6 @@ def test_week_limit(self): assert result == "a week ago" def test_untranslated_granularity(self, mocker): - arw = arrow.Arrow.utcnow() later = arw.shift(weeks=1) @@ -2317,7 +2163,6 @@ def test_no_floats_multi_gran(self): @pytest.mark.usefixtures("time_2013_01_01") class TestArrowHumanizeTestsWithLocale: def test_now(self): - arw = arrow.Arrow(2013, 1, 1, 0, 0, 0) result = arw.humanize(self.datetime, locale="ru") @@ -2331,7 +2176,6 @@ def test_seconds(self): assert result == "через 44 секунды" def test_years(self): - arw = arrow.Arrow(2011, 7, 2) result = arw.humanize(self.datetime, locale="ru") @@ -2582,9 +2426,7 @@ def slavic_locales() -> List[str]: class TestArrowDehumanize: def test_now(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-1) second_future = arw.shift(seconds=1) @@ -2600,9 +2442,7 @@ def test_now(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(second_future_string, locale=lang) == arw def test_seconds(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-5) second_future = arw.shift(seconds=5) @@ -2618,9 +2458,7 @@ def test_seconds(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(second_future_string, locale=lang) == second_future def test_minute(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2001, 6, 18, 5, 55, 0) minute_ago = arw.shift(minutes=-1) minute_future = arw.shift(minutes=1) @@ -2636,9 +2474,7 @@ def test_minute(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(minute_future_string, locale=lang) == minute_future def test_minutes(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2007, 1, 10, 5, 55, 0) minute_ago = arw.shift(minutes=-5) minute_future = arw.shift(minutes=5) @@ -2654,9 +2490,7 @@ def test_minutes(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(minute_future_string, locale=lang) == minute_future def test_hour(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2009, 4, 20, 5, 55, 0) hour_ago = arw.shift(hours=-1) hour_future = arw.shift(hours=1) @@ -2670,9 +2504,7 @@ def test_hour(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(hour_future_string, locale=lang) == hour_future def test_hours(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2010, 2, 16, 7, 55, 0) hour_ago = arw.shift(hours=-3) hour_future = arw.shift(hours=3) @@ -2686,9 +2518,7 @@ def test_hours(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(hour_future_string, locale=lang) == hour_future def test_week(self, locale_list_with_weeks: List[str]): - for lang in locale_list_with_weeks: - arw = arrow.Arrow(2012, 2, 18, 1, 52, 0) week_ago = arw.shift(weeks=-1) week_future = arw.shift(weeks=1) @@ -2702,9 +2532,7 @@ def test_week(self, locale_list_with_weeks: List[str]): assert arw.dehumanize(week_future_string, locale=lang) == week_future def test_weeks(self, locale_list_with_weeks: List[str]): - for lang in locale_list_with_weeks: - arw = arrow.Arrow(2020, 3, 18, 5, 3, 0) week_ago = arw.shift(weeks=-7) week_future = arw.shift(weeks=7) @@ -2718,9 +2546,7 @@ def test_weeks(self, locale_list_with_weeks: List[str]): assert arw.dehumanize(week_future_string, locale=lang) == week_future def test_year(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) year_ago = arw.shift(years=-1) year_future = arw.shift(years=1) @@ -2734,9 +2560,7 @@ def test_year(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(year_future_string, locale=lang) == year_future def test_years(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) year_ago = arw.shift(years=-10) year_future = arw.shift(years=10) @@ -2750,9 +2574,7 @@ def test_years(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(year_future_string, locale=lang) == year_future def test_gt_than_10_years(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) year_ago = arw.shift(years=-25) year_future = arw.shift(years=25) @@ -2766,9 +2588,7 @@ def test_gt_than_10_years(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(year_future_string, locale=lang) == year_future def test_mixed_granularity(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) past = arw.shift(hours=-1, minutes=-1, seconds=-1) future = arw.shift(hours=1, minutes=1, seconds=1) @@ -2784,9 +2604,7 @@ def test_mixed_granularity(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(future_string, locale=lang) == future def test_mixed_granularity_hours(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) past = arw.shift(hours=-3, minutes=-1, seconds=-15) future = arw.shift(hours=3, minutes=1, seconds=15) @@ -2802,9 +2620,7 @@ def test_mixed_granularity_hours(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(future_string, locale=lang) == future def test_mixed_granularity_day(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) past = arw.shift(days=-3, minutes=-1, seconds=-15) future = arw.shift(days=3, minutes=1, seconds=15) @@ -2820,9 +2636,7 @@ def test_mixed_granularity_day(self, locale_list_no_weeks: List[str]): assert arw.dehumanize(future_string, locale=lang) == future def test_mixed_granularity_day_hour(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 1, 10, 5, 55, 0) past = arw.shift(days=-3, hours=-23, seconds=-15) future = arw.shift(days=3, hours=23, seconds=15) @@ -2839,7 +2653,6 @@ def test_mixed_granularity_day_hour(self, locale_list_no_weeks: List[str]): # Test to make sure unsupported locales error out def test_unsupported_locale(self): - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-5) second_future = arw.shift(seconds=5) @@ -2860,7 +2673,6 @@ def test_unsupported_locale(self): # Test to ensure old style locale strings are supported def test_normalized_locale(self): - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-5) second_future = arw.shift(seconds=5) @@ -2877,9 +2689,7 @@ def test_normalized_locale(self): # Ensures relative units are required in string def test_require_relative_unit(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-5) second_future = arw.shift(seconds=5) @@ -2899,9 +2709,7 @@ def test_require_relative_unit(self, locale_list_no_weeks: List[str]): # Test for scrambled input def test_scrambled_input(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) second_ago = arw.shift(seconds=-5) second_future = arw.shift(seconds=5) @@ -2927,9 +2735,7 @@ def test_scrambled_input(self, locale_list_no_weeks: List[str]): arw.dehumanize(second_future_string, locale=lang) def test_no_units_modified(self, locale_list_no_weeks: List[str]): - for lang in locale_list_no_weeks: - arw = arrow.Arrow(2000, 6, 18, 5, 55, 0) # Ensures we pass the first stage of checking whether relative units exist @@ -2944,7 +2750,6 @@ def test_no_units_modified(self, locale_list_no_weeks: List[str]): arw.dehumanize(empty_future_string, locale=lang) def test_slavic_locales(self, slavic_locales: List[str]): - # Relevant units for Slavic locale plural logic units = [ 0, @@ -2975,7 +2780,6 @@ def test_slavic_locales(self, slavic_locales: List[str]): assert arw.dehumanize(future_string, locale=lang) == future def test_czech_slovak(self): - # Relevant units for Slavic locale plural logic units = [ 0, @@ -3082,7 +2886,6 @@ def test_value_error_exception(self): class TestArrowUtil: def test_get_datetime(self): - get_datetime = arrow.Arrow._get_datetime arw = arrow.Arrow.utcnow() @@ -3100,7 +2903,6 @@ def test_get_datetime(self): assert "not recognized as a datetime or timestamp" in str(raise_ctx.value) def test_get_tzinfo(self): - get_tzinfo = arrow.Arrow._get_tzinfo with pytest.raises(ValueError) as raise_ctx: @@ -3108,7 +2910,6 @@ def test_get_tzinfo(self): assert "not recognized as a timezone" in str(raise_ctx.value) def test_get_iteration_params(self): - assert arrow.Arrow._get_iteration_params("end", None) == ("end", sys.maxsize) assert arrow.Arrow._get_iteration_params(None, 100) == (arrow.Arrow.max, 100) assert arrow.Arrow._get_iteration_params(100, 120) == (100, 120) diff --git a/tests/test_factory.py b/tests/test_factory.py index f368126c6..4e328000e 100644 --- a/tests/test_factory.py +++ b/tests/test_factory.py @@ -14,13 +14,11 @@ @pytest.mark.usefixtures("arrow_factory") class TestGet: def test_no_args(self): - assert_datetime_equality( self.factory.get(), datetime.utcnow().replace(tzinfo=tz.tzutc()) ) def test_timestamp_one_arg_no_arg(self): - no_arg = self.factory.get(1406430900).timestamp() one_arg = self.factory.get("1406430900", "X").timestamp() @@ -31,14 +29,12 @@ def test_one_arg_none(self): self.factory.get(None) def test_struct_time(self): - assert_datetime_equality( self.factory.get(time.gmtime()), datetime.utcnow().replace(tzinfo=tz.tzutc()), ) def test_one_arg_timestamp(self): - int_timestamp = int(time.time()) timestamp_dt = datetime.utcfromtimestamp(int_timestamp).replace( tzinfo=tz.tzutc() @@ -66,7 +62,6 @@ def test_one_arg_timestamp(self): self.factory.get(timestamp) def test_one_arg_expanded_timestamp(self): - millisecond_timestamp = 1591328104308 microsecond_timestamp = 1591328104308505 @@ -79,7 +74,6 @@ def test_one_arg_expanded_timestamp(self): ).replace(tzinfo=tz.tzutc()) def test_one_arg_timestamp_with_tzinfo(self): - timestamp = time.time() timestamp_dt = datetime.fromtimestamp(timestamp, tz=tz.tzutc()).astimezone( tz.gettz("US/Pacific") @@ -91,27 +85,23 @@ def test_one_arg_timestamp_with_tzinfo(self): ) def test_one_arg_arrow(self): - arw = self.factory.utcnow() result = self.factory.get(arw) assert arw == result def test_one_arg_datetime(self): - dt = datetime.utcnow().replace(tzinfo=tz.tzutc()) assert self.factory.get(dt) == dt def test_one_arg_date(self): - d = date.today() dt = datetime(d.year, d.month, d.day, tzinfo=tz.tzutc()) assert self.factory.get(d) == dt def test_one_arg_tzinfo(self): - self.expected = ( datetime.utcnow() .replace(tzinfo=tz.tzutc()) @@ -132,7 +122,6 @@ def test_one_arg_dateparser_datetime(self): assert dt_output == expected def test_kwarg_tzinfo(self): - self.expected = ( datetime.utcnow() .replace(tzinfo=tz.tzutc()) @@ -144,7 +133,6 @@ def test_kwarg_tzinfo(self): ) def test_kwarg_tzinfo_string(self): - self.expected = ( datetime.utcnow() .replace(tzinfo=tz.tzutc()) @@ -176,7 +164,6 @@ def test_kwarg_normalize_whitespace(self): # regression test for #944 def test_one_arg_datetime_tzinfo_kwarg(self): - dt = datetime(2021, 4, 29, 6) result = self.factory.get(dt, tzinfo="America/Chicago") @@ -186,7 +173,6 @@ def test_one_arg_datetime_tzinfo_kwarg(self): assert_datetime_equality(result._datetime, expected) def test_one_arg_arrow_tzinfo_kwarg(self): - arw = Arrow(2021, 4, 29, 6) result = self.factory.get(arw, tzinfo="America/Chicago") @@ -196,7 +182,6 @@ def test_one_arg_arrow_tzinfo_kwarg(self): assert_datetime_equality(result._datetime, expected) def test_one_arg_date_tzinfo_kwarg(self): - da = date(2021, 4, 29) result = self.factory.get(da, tzinfo="America/Chicago") @@ -207,7 +192,6 @@ def test_one_arg_date_tzinfo_kwarg(self): assert result.tzinfo == expected.tzinfo def test_one_arg_iso_calendar_tzinfo_kwarg(self): - result = self.factory.get((2004, 1, 7), tzinfo="America/Chicago") expected = Arrow(2004, 1, 4, tzinfo="America/Chicago") @@ -215,7 +199,6 @@ def test_one_arg_iso_calendar_tzinfo_kwarg(self): assert_datetime_equality(result, expected) def test_one_arg_iso_str(self): - dt = datetime.utcnow() assert_datetime_equality( @@ -223,7 +206,6 @@ def test_one_arg_iso_str(self): ) def test_one_arg_iso_calendar(self): - pairs = [ (datetime(2004, 1, 4), (2004, 1, 7)), (datetime(2008, 12, 30), (2009, 1, 2)), @@ -252,12 +234,10 @@ def test_one_arg_iso_calendar(self): self.factory.get((2014, 7, 10)) def test_one_arg_other(self): - with pytest.raises(TypeError): self.factory.get(object()) def test_one_arg_bool(self): - with pytest.raises(TypeError): self.factory.get(False) @@ -272,47 +252,39 @@ def test_one_arg_decimal(self): ) def test_two_args_datetime_tzinfo(self): - result = self.factory.get(datetime(2013, 1, 1), tz.gettz("US/Pacific")) assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.gettz("US/Pacific")) def test_two_args_datetime_tz_str(self): - result = self.factory.get(datetime(2013, 1, 1), "US/Pacific") assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.gettz("US/Pacific")) def test_two_args_date_tzinfo(self): - result = self.factory.get(date(2013, 1, 1), tz.gettz("US/Pacific")) assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.gettz("US/Pacific")) def test_two_args_date_tz_str(self): - result = self.factory.get(date(2013, 1, 1), "US/Pacific") assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.gettz("US/Pacific")) def test_two_args_datetime_other(self): - with pytest.raises(TypeError): self.factory.get(datetime.utcnow(), object()) def test_two_args_date_other(self): - with pytest.raises(TypeError): self.factory.get(date.today(), object()) def test_two_args_str_str(self): - result = self.factory.get("2013-01-01", "YYYY-MM-DD") assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) def test_two_args_str_tzinfo(self): - result = self.factory.get("2013-01-01", tzinfo=tz.gettz("US/Pacific")) assert_datetime_equality( @@ -320,7 +292,6 @@ def test_two_args_str_tzinfo(self): ) def test_two_args_twitter_format(self): - # format returned by twitter API for created_at: twitter_date = "Fri Apr 08 21:08:54 +0000 2016" result = self.factory.get(twitter_date, "ddd MMM DD HH:mm:ss Z YYYY") @@ -328,24 +299,20 @@ def test_two_args_twitter_format(self): assert result._datetime == datetime(2016, 4, 8, 21, 8, 54, tzinfo=tz.tzutc()) def test_two_args_str_list(self): - result = self.factory.get("2013-01-01", ["MM/DD/YYYY", "YYYY-MM-DD"]) assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) def test_two_args_unicode_unicode(self): - result = self.factory.get("2013-01-01", "YYYY-MM-DD") assert result._datetime == datetime(2013, 1, 1, tzinfo=tz.tzutc()) def test_two_args_other(self): - with pytest.raises(TypeError): self.factory.get(object(), object()) def test_three_args_with_tzinfo(self): - timefmt = "YYYYMMDD" d = "20150514" @@ -354,11 +321,9 @@ def test_three_args_with_tzinfo(self): ) def test_three_args(self): - assert self.factory.get(2013, 1, 1) == datetime(2013, 1, 1, tzinfo=tz.tzutc()) def test_full_kwargs(self): - assert self.factory.get( year=2016, month=7, @@ -370,7 +335,6 @@ def test_full_kwargs(self): ) == datetime(2016, 7, 14, 7, 16, 45, 631092, tzinfo=tz.tzutc()) def test_three_kwargs(self): - assert self.factory.get(year=2016, month=7, day=14) == datetime( 2016, 7, 14, 0, 0, tzinfo=tz.tzutc() ) @@ -380,7 +344,6 @@ def test_tzinfo_string_kwargs(self): assert result._datetime == datetime(2019, 7, 28, 7, 0, 0, 0, tzinfo=tz.tzutc()) def test_insufficient_kwargs(self): - with pytest.raises(TypeError): self.factory.get(year=2016) @@ -409,7 +372,6 @@ def test_locale_with_tzinfo(self): @pytest.mark.usefixtures("arrow_factory") class TestUtcNow: def test_utcnow(self): - assert_datetime_equality( self.factory.utcnow()._datetime, datetime.utcnow().replace(tzinfo=tz.tzutc()), @@ -419,15 +381,12 @@ def test_utcnow(self): @pytest.mark.usefixtures("arrow_factory") class TestNow: def test_no_tz(self): - assert_datetime_equality(self.factory.now(), datetime.now(tz.tzlocal())) def test_tzinfo(self): - assert_datetime_equality( self.factory.now(tz.gettz("EST")), datetime.now(tz.gettz("EST")) ) def test_tz_str(self): - assert_datetime_equality(self.factory.now("EST"), datetime.now(tz.gettz("EST"))) diff --git a/tests/test_formatter.py b/tests/test_formatter.py index 06831f1e0..0b6c256cf 100644 --- a/tests/test_formatter.py +++ b/tests/test_formatter.py @@ -23,7 +23,6 @@ @pytest.mark.usefixtures("arrow_formatter") class TestFormatterFormatToken: def test_format(self): - dt = datetime(2013, 2, 5, 12, 32, 51) result = self.formatter.format(dt, "MM-DD-YYYY hh:mm:ss a") @@ -31,13 +30,11 @@ def test_format(self): assert result == "02-05-2013 12:32:51 pm" def test_year(self): - dt = datetime(2013, 1, 1) assert self.formatter._format_token(dt, "YYYY") == "2013" assert self.formatter._format_token(dt, "YY") == "13" def test_month(self): - dt = datetime(2013, 1, 1) assert self.formatter._format_token(dt, "MMMM") == "January" assert self.formatter._format_token(dt, "MMM") == "Jan" @@ -45,7 +42,6 @@ def test_month(self): assert self.formatter._format_token(dt, "M") == "1" def test_day(self): - dt = datetime(2013, 2, 1) assert self.formatter._format_token(dt, "DDDD") == "032" assert self.formatter._format_token(dt, "DDD") == "32" @@ -58,7 +54,6 @@ def test_day(self): assert self.formatter._format_token(dt, "d") == "5" def test_hour(self): - dt = datetime(2013, 1, 1, 2) assert self.formatter._format_token(dt, "HH") == "02" assert self.formatter._format_token(dt, "H") == "2" @@ -81,19 +76,16 @@ def test_hour(self): assert self.formatter._format_token(dt, "h") == "12" def test_minute(self): - dt = datetime(2013, 1, 1, 0, 1) assert self.formatter._format_token(dt, "mm") == "01" assert self.formatter._format_token(dt, "m") == "1" def test_second(self): - dt = datetime(2013, 1, 1, 0, 0, 1) assert self.formatter._format_token(dt, "ss") == "01" assert self.formatter._format_token(dt, "s") == "1" def test_sub_second(self): - dt = datetime(2013, 1, 1, 0, 0, 0, 123456) assert self.formatter._format_token(dt, "SSSSSS") == "123456" assert self.formatter._format_token(dt, "SSSSS") == "12345" @@ -111,7 +103,6 @@ def test_sub_second(self): assert self.formatter._format_token(dt, "S") == "0" def test_timestamp(self): - dt = datetime.now(tz=dateutil_tz.UTC) expected = str(dt.timestamp()) assert self.formatter._format_token(dt, "X") == expected @@ -122,7 +113,6 @@ def test_timestamp(self): assert self.formatter._format_token(dt, "x") == expected def test_timezone(self): - dt = datetime.utcnow().replace(tzinfo=dateutil_tz.gettz("US/Pacific")) result = self.formatter._format_token(dt, "ZZ") @@ -133,7 +123,6 @@ def test_timezone(self): @pytest.mark.parametrize("full_tz_name", make_full_tz_list()) def test_timezone_formatter(self, full_tz_name): - # This test will fail if we use "now" as date as soon as we change from/to DST dt = datetime(1986, 2, 14, tzinfo=pytz.timezone("UTC")).replace( tzinfo=dateutil_tz.gettz(full_tz_name) @@ -144,7 +133,6 @@ def test_timezone_formatter(self, full_tz_name): assert result == abbreviation def test_am_pm(self): - dt = datetime(2012, 1, 1, 11) assert self.formatter._format_token(dt, "a") == "am" assert self.formatter._format_token(dt, "A") == "AM" @@ -167,7 +155,6 @@ def test_nonsense(self): assert self.formatter._format_token(dt, "NONSENSE") is None def test_escape(self): - assert ( self.formatter.format( datetime(2015, 12, 10, 17, 9), "MMMM D, YYYY [at] h:mma" diff --git a/tests/test_locales.py b/tests/test_locales.py index 4bbbd3dc2..d6abb2a11 100644 --- a/tests/test_locales.py +++ b/tests/test_locales.py @@ -8,7 +8,6 @@ class TestLocaleValidation: """Validate locales to ensure that translations are valid and complete""" def test_locale_validation(self): - for locale_cls in self.locales.values(): # 7 days + 1 spacer to allow for 1-indexing of months assert len(locale_cls.day_names) == 8 @@ -34,7 +33,6 @@ def test_locale_validation(self): assert locale_cls.future is not None def test_locale_name_validation(self): - for locale_cls in self.locales.values(): for locale_name in locale_cls.names: assert len(locale_name) == 2 or len(locale_name) == 5 @@ -90,7 +88,6 @@ def test_get_locale_by_class_name(self, mocker): assert result == mock_locale_obj def test_locales(self): - assert len(locales._locale_map) > 0 @@ -116,24 +113,20 @@ def test_describe(self): assert self.locale.describe("now", only_distance=False) == "just now" def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 hours" assert self.locale._format_timeframe("hour", 0) == "an hour" def test_format_relative_now(self): - result = self.locale._format_relative("just now", "now", 0) assert result == "just now" def test_format_relative_past(self): - result = self.locale._format_relative("an hour", "hour", 1) assert result == "in an hour" def test_format_relative_future(self): - result = self.locale._format_relative("an hour", "hour", -1) assert result == "an hour ago" @@ -438,7 +431,6 @@ def test_plurals2(self): @pytest.mark.usefixtures("lang_locale") class TestPolishLocale: def test_plurals(self): - assert self.locale._format_timeframe("seconds", 0) == "0 sekund" assert self.locale._format_timeframe("second", 1) == "sekundę" assert self.locale._format_timeframe("seconds", 2) == "2 sekundy" @@ -491,7 +483,6 @@ def test_plurals(self): @pytest.mark.usefixtures("lang_locale") class TestIcelandicLocale: def test_format_timeframe(self): - assert self.locale._format_timeframe("now", 0) == "rétt í þessu" assert self.locale._format_timeframe("second", -1) == "sekúndu" @@ -534,23 +525,19 @@ def test_format_timeframe(self): @pytest.mark.usefixtures("lang_locale") class TestMalayalamLocale: def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 മണിക്കൂർ" assert self.locale._format_timeframe("hour", 0) == "ഒരു മണിക്കൂർ" def test_format_relative_now(self): - result = self.locale._format_relative("ഇപ്പോൾ", "now", 0) assert result == "ഇപ്പോൾ" def test_format_relative_past(self): - result = self.locale._format_relative("ഒരു മണിക്കൂർ", "hour", 1) assert result == "ഒരു മണിക്കൂർ ശേഷം" def test_format_relative_future(self): - result = self.locale._format_relative("ഒരു മണിക്കൂർ", "hour", -1) assert result == "ഒരു മണിക്കൂർ മുമ്പ്" @@ -585,22 +572,18 @@ def test_weekday(self): @pytest.mark.usefixtures("lang_locale") class TestHindiLocale: def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 घंटे" assert self.locale._format_timeframe("hour", 0) == "एक घंटा" def test_format_relative_now(self): - result = self.locale._format_relative("अभी", "now", 0) assert result == "अभी" def test_format_relative_past(self): - result = self.locale._format_relative("एक घंटा", "hour", 1) assert result == "एक घंटा बाद" def test_format_relative_future(self): - result = self.locale._format_relative("एक घंटा", "hour", -1) assert result == "एक घंटा पहले" @@ -675,17 +658,14 @@ def test_format_timeframe(self): assert self.locale._format_timeframe("years", 5) == "5 let" def test_format_relative_now(self): - result = self.locale._format_relative("Teď", "now", 0) assert result == "Teď" def test_format_relative_future(self): - result = self.locale._format_relative("hodinu", "hour", 1) assert result == "Za hodinu" def test_format_relative_past(self): - result = self.locale._format_relative("hodinou", "hour", -1) assert result == "Před hodinou" @@ -693,7 +673,6 @@ def test_format_relative_past(self): @pytest.mark.usefixtures("lang_locale") class TestSlovakLocale: def test_format_timeframe(self): - assert self.locale._format_timeframe("seconds", -5) == "5 sekundami" assert self.locale._format_timeframe("seconds", -2) == "2 sekundami" assert self.locale._format_timeframe("second", -1) == "sekundou" @@ -753,17 +732,14 @@ def test_format_timeframe(self): assert self.locale._format_timeframe("now", 0) == "Teraz" def test_format_relative_now(self): - result = self.locale._format_relative("Teraz", "now", 0) assert result == "Teraz" def test_format_relative_future(self): - result = self.locale._format_relative("hodinu", "hour", 1) assert result == "O hodinu" def test_format_relative_past(self): - result = self.locale._format_relative("hodinou", "hour", -1) assert result == "Pred hodinou" @@ -1400,7 +1376,6 @@ def test_ordinal_number(self): @pytest.mark.usefixtures("lang_locale") class TestRomanianLocale: def test_timeframes(self): - assert self.locale._format_timeframe("hours", 2) == "2 ore" assert self.locale._format_timeframe("months", 2) == "2 luni" @@ -1435,7 +1410,6 @@ def test_relative_timeframes(self): @pytest.mark.usefixtures("lang_locale") class TestArabicLocale: def test_timeframes(self): - # single assert self.locale._format_timeframe("minute", 1) == "دقيقة" assert self.locale._format_timeframe("hour", 1) == "ساعة" @@ -2514,22 +2488,18 @@ def test_ordinal_number(self): assert self.locale._ordinal_number(-1) == "" def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 ଘଣ୍ଟା" assert self.locale._format_timeframe("hour", 0) == "ଏକ ଘଣ୍ଟା" def test_format_relative_now(self): - result = self.locale._format_relative("ବର୍ତ୍ତମାନ", "now", 0) assert result == "ବର୍ତ୍ତମାନ" def test_format_relative_past(self): - result = self.locale._format_relative("ଏକ ଘଣ୍ଟା", "hour", 1) assert result == "ଏକ ଘଣ୍ଟା ପରେ" def test_format_relative_future(self): - result = self.locale._format_relative("ଏକ ଘଣ୍ଟା", "hour", -1) assert result == "ଏକ ଘଣ୍ଟା ପୂର୍ବେ" @@ -2758,13 +2728,11 @@ def test_format_relative_now(self): assert result == "දැන්" def test_format_relative_future(self): - result = self.locale._format_relative("පැයකින්", "පැය", 1) assert result == "පැයකින්" # (in) one hour def test_format_relative_past(self): - result = self.locale._format_relative("පැයක", "පැය", -1) assert result == "පැයකට පෙර" # an hour ago @@ -2868,24 +2836,20 @@ def test_ordinal_number(self): assert self.locale.ordinal_number(1) == "1." def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 timer" assert self.locale._format_timeframe("hour", 0) == "en time" def test_format_relative_now(self): - result = self.locale._format_relative("nå nettopp", "now", 0) assert result == "nå nettopp" def test_format_relative_past(self): - result = self.locale._format_relative("en time", "hour", 1) assert result == "om en time" def test_format_relative_future(self): - result = self.locale._format_relative("en time", "hour", -1) assert result == "for en time siden" @@ -2924,24 +2888,20 @@ def test_ordinal_number(self): assert self.locale.ordinal_number(1) == "1." def test_format_timeframe(self): - assert self.locale._format_timeframe("hours", 2) == "2 timar" assert self.locale._format_timeframe("hour", 0) == "ein time" def test_format_relative_now(self): - result = self.locale._format_relative("no nettopp", "now", 0) assert result == "no nettopp" def test_format_relative_past(self): - result = self.locale._format_relative("ein time", "hour", 1) assert result == "om ein time" def test_format_relative_future(self): - result = self.locale._format_relative("ein time", "hour", -1) assert result == "for ein time sidan" @@ -3063,13 +3023,11 @@ def test_ordinal_number(self): assert self.locale.ordinal_number(1) == "1ኛ" def test_format_relative_future(self): - result = self.locale._format_relative("በአንድ ሰዓት", "hour", 1) assert result == "በአንድ ሰዓት ውስጥ" # (in) one hour def test_format_relative_past(self): - result = self.locale._format_relative("ከአንድ ሰዓት", "hour", -1) assert result == "ከአንድ ሰዓት በፊት" # an hour ago diff --git a/tests/test_parser.py b/tests/test_parser.py index bdcc10264..1932b450d 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -83,7 +83,6 @@ def test_parse_token_invalid_meridians(self): assert parts == {} def test_parser_no_caching(self, mocker): - mocked_parser = mocker.patch( "arrow.parser.DateTimeParser._generate_pattern_re", fmt="fmt_a" ) @@ -135,7 +134,6 @@ def test_parser_multiple_line_caching(self, mocker): assert mocked_parser.call_args_list[1] == mocker.call(fmt="fmt_b") def test_YY_and_YYYY_format_list(self): - assert self.parser.parse("15/01/19", ["DD/MM/YY", "DD/MM/YYYY"]) == datetime( 2019, 1, 15 ) @@ -165,7 +163,6 @@ def test_timestamp_format_list(self): @pytest.mark.usefixtures("dt_parser") class TestDateTimeParserParse: def test_parse_list(self, mocker): - mocker.patch( "arrow.parser.DateTimeParser._parse_multiformat", string="str", @@ -177,7 +174,6 @@ def test_parse_list(self, mocker): assert result == "result" def test_parse_unrecognized_token(self, mocker): - mocker.patch.dict("arrow.parser.DateTimeParser._BASE_INPUT_RE_MAP") del arrow.parser.DateTimeParser._BASE_INPUT_RE_MAP["YYYY"] @@ -187,17 +183,14 @@ def test_parse_unrecognized_token(self, mocker): _parser.parse("2013-01-01", "YYYY-MM-DD") def test_parse_parse_no_match(self): - with pytest.raises(ParserError): self.parser.parse("01-01", "YYYY-MM-DD") def test_parse_separators(self): - with pytest.raises(ParserError): self.parser.parse("1403549231", "YYYY-MM-DD") def test_parse_numbers(self): - self.expected = datetime(2012, 1, 1, 12, 5, 10) assert ( self.parser.parse("2012-01-01 12:05:10", "YYYY-MM-DD HH:mm:ss") @@ -205,19 +198,16 @@ def test_parse_numbers(self): ) def test_parse_am(self): - with pytest.raises(ParserMatchError): self.parser.parse("2021-01-30 14:00:00 AM", "YYYY-MM-DD HH:mm:ss A") def test_parse_year_two_digit(self): - self.expected = datetime(1979, 1, 1, 12, 5, 10) assert ( self.parser.parse("79-01-01 12:05:10", "YY-MM-DD HH:mm:ss") == self.expected ) def test_parse_timestamp(self): - tz_utc = tz.tzutc() float_timestamp = time.time() int_timestamp = int(float_timestamp) @@ -296,14 +286,12 @@ def test_parse_expanded_timestamp(self): self.parser.parse(f"{timestamp:f}", "x") def test_parse_names(self): - self.expected = datetime(2012, 1, 1) assert self.parser.parse("January 1, 2012", "MMMM D, YYYY") == self.expected assert self.parser.parse("Jan 1, 2012", "MMM D, YYYY") == self.expected def test_parse_pm(self): - self.expected = datetime(1, 1, 1, 13, 0, 0) assert self.parser.parse("1 pm", "H a") == self.expected assert self.parser.parse("1 pm", "h a") == self.expected @@ -321,19 +309,16 @@ def test_parse_pm(self): assert self.parser.parse("12 pm", "h A") == self.expected def test_parse_tz_hours_only(self): - self.expected = datetime(2025, 10, 17, 5, 30, 10, tzinfo=tz.tzoffset(None, 0)) parsed = self.parser.parse("2025-10-17 05:30:10+00", "YYYY-MM-DD HH:mm:ssZ") assert parsed == self.expected def test_parse_tz_zz(self): - self.expected = datetime(2013, 1, 1, tzinfo=tz.tzoffset(None, -7 * 3600)) assert self.parser.parse("2013-01-01 -07:00", "YYYY-MM-DD ZZ") == self.expected @pytest.mark.parametrize("full_tz_name", make_full_tz_list()) def test_parse_tz_name_zzz(self, full_tz_name): - self.expected = datetime(2013, 1, 1, tzinfo=tz.gettz(full_tz_name)) assert ( self.parser.parse(f"2013-01-01 {full_tz_name}", "YYYY-MM-DD ZZZ") @@ -727,7 +712,6 @@ def test_parse_HH_24(self): self.parser.parse("2019-12-31T24:00:00.999999", "YYYY-MM-DDTHH:mm:ss.S") def test_parse_W(self): - assert self.parser.parse("2011-W05-4", "W") == datetime(2011, 2, 3) assert self.parser.parse("2011W054", "W") == datetime(2011, 2, 3) assert self.parser.parse("2011-W05", "W") == datetime(2011, 1, 31) @@ -794,31 +778,24 @@ def test_parse_normalize_whitespace(self): @pytest.mark.usefixtures("dt_parser_regex") class TestDateTimeParserRegex: def test_format_year(self): - assert self.format_regex.findall("YYYY-YY") == ["YYYY", "YY"] def test_format_month(self): - assert self.format_regex.findall("MMMM-MMM-MM-M") == ["MMMM", "MMM", "MM", "M"] def test_format_day(self): - assert self.format_regex.findall("DDDD-DDD-DD-D") == ["DDDD", "DDD", "DD", "D"] def test_format_hour(self): - assert self.format_regex.findall("HH-H-hh-h") == ["HH", "H", "hh", "h"] def test_format_minute(self): - assert self.format_regex.findall("mm-m") == ["mm", "m"] def test_format_second(self): - assert self.format_regex.findall("ss-s") == ["ss", "s"] def test_format_subsecond(self): - assert self.format_regex.findall("SSSSSS-SSSSS-SSSS-SSS-SS-S") == [ "SSSSSS", "SSSSS", @@ -829,23 +806,18 @@ def test_format_subsecond(self): ] def test_format_tz(self): - assert self.format_regex.findall("ZZZ-ZZ-Z") == ["ZZZ", "ZZ", "Z"] def test_format_am_pm(self): - assert self.format_regex.findall("A-a") == ["A", "a"] def test_format_timestamp(self): - assert self.format_regex.findall("X") == ["X"] def test_format_timestamp_milli(self): - assert self.format_regex.findall("x") == ["x"] def test_escape(self): - escape_regex = parser.DateTimeParser._ESCAPE_RE assert escape_regex.findall("2018-03-09 8 [h] 40 [hello]") == ["[h]", "[hello]"] @@ -869,7 +841,6 @@ def test_month_abbreviations(self): assert result == calendar.month_abbr[1:] def test_digits(self): - assert parser.DateTimeParser._ONE_OR_TWO_DIGIT_RE.findall("4-56") == ["4", "56"] assert parser.DateTimeParser._ONE_OR_TWO_OR_THREE_DIGIT_RE.findall( "4-56-789" @@ -940,7 +911,6 @@ def test_time(self): @pytest.mark.usefixtures("dt_parser") class TestDateTimeParserISO: def test_YYYY(self): - assert self.parser.parse_iso("2013") == datetime(2013, 1, 1) def test_YYYY_DDDD(self): @@ -968,7 +938,6 @@ def test_YYYY_DDDD(self): assert self.parser.parse_iso("2017-366") == datetime(2018, 1, 1) def test_YYYY_DDDD_HH_mm_ssZ(self): - assert self.parser.parse_iso("2013-036 04:05:06+01:00") == datetime( 2013, 2, 5, 4, 5, 6, tzinfo=tz.tzoffset(None, 3600) ) @@ -982,67 +951,55 @@ def test_YYYY_MM_DDDD(self): self.parser.parse_iso("2014-05-125") def test_YYYY_MM(self): - for separator in DateTimeParser.SEPARATORS: assert self.parser.parse_iso(separator.join(("2013", "02"))) == datetime( 2013, 2, 1 ) def test_YYYY_MM_DD(self): - for separator in DateTimeParser.SEPARATORS: assert self.parser.parse_iso( separator.join(("2013", "02", "03")) ) == datetime(2013, 2, 3) def test_YYYY_MM_DDTHH_mmZ(self): - assert self.parser.parse_iso("2013-02-03T04:05+01:00") == datetime( 2013, 2, 3, 4, 5, tzinfo=tz.tzoffset(None, 3600) ) def test_YYYY_MM_DDTHH_mm(self): - assert self.parser.parse_iso("2013-02-03T04:05") == datetime(2013, 2, 3, 4, 5) def test_YYYY_MM_DDTHH(self): - assert self.parser.parse_iso("2013-02-03T04") == datetime(2013, 2, 3, 4) def test_YYYY_MM_DDTHHZ(self): - assert self.parser.parse_iso("2013-02-03T04+01:00") == datetime( 2013, 2, 3, 4, tzinfo=tz.tzoffset(None, 3600) ) def test_YYYY_MM_DDTHH_mm_ssZ(self): - assert self.parser.parse_iso("2013-02-03T04:05:06+01:00") == datetime( 2013, 2, 3, 4, 5, 6, tzinfo=tz.tzoffset(None, 3600) ) def test_YYYY_MM_DDTHH_mm_ss(self): - assert self.parser.parse_iso("2013-02-03T04:05:06") == datetime( 2013, 2, 3, 4, 5, 6 ) def test_YYYY_MM_DD_HH_mmZ(self): - assert self.parser.parse_iso("2013-02-03 04:05+01:00") == datetime( 2013, 2, 3, 4, 5, tzinfo=tz.tzoffset(None, 3600) ) def test_YYYY_MM_DD_HH_mm(self): - assert self.parser.parse_iso("2013-02-03 04:05") == datetime(2013, 2, 3, 4, 5) def test_YYYY_MM_DD_HH(self): - assert self.parser.parse_iso("2013-02-03 04") == datetime(2013, 2, 3, 4) def test_invalid_time(self): - with pytest.raises(ParserError): self.parser.parse_iso("2013-02-03T") @@ -1053,19 +1010,16 @@ def test_invalid_time(self): self.parser.parse_iso("2013-02-03 04:05:06.") def test_YYYY_MM_DD_HH_mm_ssZ(self): - assert self.parser.parse_iso("2013-02-03 04:05:06+01:00") == datetime( 2013, 2, 3, 4, 5, 6, tzinfo=tz.tzoffset(None, 3600) ) def test_YYYY_MM_DD_HH_mm_ss(self): - assert self.parser.parse_iso("2013-02-03 04:05:06") == datetime( 2013, 2, 3, 4, 5, 6 ) def test_YYYY_MM_DDTHH_mm_ss_S(self): - assert self.parser.parse_iso("2013-02-03T04:05:06.7") == datetime( 2013, 2, 3, 4, 5, 6, 700000 ) @@ -1100,7 +1054,6 @@ def test_YYYY_MM_DDTHH_mm_ss_S(self): ) def test_YYYY_MM_DDTHH_mm_ss_SZ(self): - assert self.parser.parse_iso("2013-02-03T04:05:06.7+01:00") == datetime( 2013, 2, 3, 4, 5, 6, 700000, tzinfo=tz.tzoffset(None, 3600) ) @@ -1126,7 +1079,6 @@ def test_YYYY_MM_DDTHH_mm_ss_SZ(self): ) def test_W(self): - assert self.parser.parse_iso("2011-W05-4") == datetime(2011, 2, 3) assert self.parser.parse_iso("2011-W05-4T14:17:01") == datetime( @@ -1140,7 +1092,6 @@ def test_W(self): ) def test_invalid_Z(self): - with pytest.raises(ParserError): self.parser.parse_iso("2013-02-03T04:05:06.78912z") @@ -1198,7 +1149,6 @@ def test_gnu_date(self): ) def test_isoformat(self): - dt = datetime.utcnow() assert self.parser.parse_iso(dt.isoformat()) == dt @@ -1359,11 +1309,9 @@ def test_midnight_end_day(self): @pytest.mark.usefixtures("tzinfo_parser") class TestTzinfoParser: def test_parse_local(self): - assert self.parser.parse("local") == tz.tzlocal() def test_parse_utc(self): - assert self.parser.parse("utc") == tz.tzutc() assert self.parser.parse("UTC") == tz.tzutc() @@ -1376,7 +1324,6 @@ def test_parse_utc_withoffset(self): ) == tz.tzoffset(None, 3600) def test_parse_iso(self): - assert self.parser.parse("01:00") == tz.tzoffset(None, 3600) assert self.parser.parse("11:35") == tz.tzoffset(None, 11 * 3600 + 2100) assert self.parser.parse("+01:00") == tz.tzoffset(None, 3600) @@ -1391,11 +1338,9 @@ def test_parse_iso(self): assert self.parser.parse("-01") == tz.tzoffset(None, -3600) def test_parse_str(self): - assert self.parser.parse("US/Pacific") == tz.gettz("US/Pacific") def test_parse_fails(self): - with pytest.raises(parser.ParserError): self.parser.parse("fail") @@ -1403,31 +1348,25 @@ def test_parse_fails(self): @pytest.mark.usefixtures("dt_parser") class TestDateTimeParserMonthName: def test_shortmonth_capitalized(self): - assert self.parser.parse("2013-Jan-01", "YYYY-MMM-DD") == datetime(2013, 1, 1) def test_shortmonth_allupper(self): - assert self.parser.parse("2013-JAN-01", "YYYY-MMM-DD") == datetime(2013, 1, 1) def test_shortmonth_alllower(self): - assert self.parser.parse("2013-jan-01", "YYYY-MMM-DD") == datetime(2013, 1, 1) def test_month_capitalized(self): - assert self.parser.parse("2013-January-01", "YYYY-MMMM-DD") == datetime( 2013, 1, 1 ) def test_month_allupper(self): - assert self.parser.parse("2013-JANUARY-01", "YYYY-MMMM-DD") == datetime( 2013, 1, 1 ) def test_month_alllower(self): - assert self.parser.parse("2013-january-01", "YYYY-MMMM-DD") == datetime( 2013, 1, 1 ) @@ -1574,13 +1513,11 @@ def test_french(self): @pytest.mark.usefixtures("dt_parser") class TestDateTimeParserSearchDate: def test_parse_search(self): - assert self.parser.parse( "Today is 25 of September of 2003", "DD of MMMM of YYYY" ) == datetime(2003, 9, 25) def test_parse_search_with_numbers(self): - assert self.parser.parse( "2000 people met the 2012-01-01 12:05:10", "YYYY-MM-DD HH:mm:ss" ) == datetime(2012, 1, 1, 12, 5, 10) @@ -1590,7 +1527,6 @@ def test_parse_search_with_numbers(self): ) == datetime(1979, 1, 1, 12, 5, 10) def test_parse_search_with_names(self): - assert self.parser.parse("June was born in May 1980", "MMMM YYYY") == datetime( 1980, 5, 1 ) @@ -1607,12 +1543,10 @@ def test_parse_search_locale_with_names(self): ) def test_parse_search_fails(self): - with pytest.raises(parser.ParserError): self.parser.parse("Jag föddes den 25 Augusti 1975", "DD MMMM YYYY") def test_escape(self): - format = "MMMM D, YYYY [at] h:mma" assert self.parser.parse( "Thursday, December 10, 2015 at 5:09pm", format diff --git a/tox.ini b/tox.ini index 11d70cb26..03c4d2af3 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion = 3.18.0 -envlist = py{py3,36,37,38,39,310,311} +envlist = py{py3,38,39,310,311,312} skip_missing_interpreters = true [gh-actions] @@ -12,6 +12,7 @@ python = 3.9: py39 3.10: py310 3.11: py311 + 3.12: py312 [testenv] deps = -r requirements/requirements-tests.txt