Skip to content

Commit

Permalink
Merge branch 'master' into Armenian
Browse files Browse the repository at this point in the history
  • Loading branch information
jadchaar committed May 1, 2022
2 parents 0543c48 + 1904804 commit 18d9afb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 69 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.2.0
hooks:
- id: check-ast
- id: check-yaml
Expand All @@ -22,7 +22,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/asottile/pyupgrade
rev: v2.30.1
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py36-plus]
Expand All @@ -38,7 +38,7 @@ repos:
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
args: [--safe, --quiet, --target-version=py36]
Expand All @@ -48,7 +48,7 @@ repos:
- id: flake8
additional_dependencies: [flake8-bugbear,flake8-annotations]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v0.930'
rev: 'v0.950'
hooks:
- id: mypy
additional_dependencies: [types-python-dateutil]
6 changes: 3 additions & 3 deletions arrow/arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow":
search_string = search_string.format(r"\d+")

# Create search pattern and find within string
pattern = re.compile(fr"(^|\b|\d){search_string}")
pattern = re.compile(rf"(^|\b|\d){search_string}")
match = pattern.search(input_string)

# If there is no match continue to next iteration
Expand Down Expand Up @@ -1426,12 +1426,12 @@ def dehumanize(self, input_string: str, locale: str = "en_us") -> "Arrow":
# Sign logic
future_string = locale_obj.future
future_string = future_string.format(".*")
future_pattern = re.compile(fr"^{future_string}$")
future_pattern = re.compile(rf"^{future_string}$")
future_pattern_match = future_pattern.findall(input_string)

past_string = locale_obj.past
past_string = past_string.format(".*")
past_pattern = re.compile(fr"^{past_string}$")
past_pattern = re.compile(rf"^{past_string}$")
past_pattern_match = past_pattern.findall(input_string)

# If a string contains the now unit, there will be no relative units, hence the need to check if the now unit
Expand Down
2 changes: 1 addition & 1 deletion arrow/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Must get max value of ctime on Windows based on architecture (x32 vs x64)
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/ctime-ctime32-ctime64-wctime-wctime32-wctime64
# Note: this may occur on both 32-bit Linux systems (issue #930) along with Windows systems
is_64bits = sys.maxsize > 2 ** 32
is_64bits = sys.maxsize > 2**32
_MAX_TIMESTAMP = (
datetime(3000, 1, 1, 23, 59, 59, 999999).timestamp()
if is_64bits
Expand Down
24 changes: 12 additions & 12 deletions tests/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ def test_granularity(self):
assert self.now.humanize(later4000, granularity="day") == "0 days ago"
assert later4000.humanize(self.now, granularity="day") == "in 0 days"

later105 = self.now.shift(seconds=10 ** 5)
later105 = self.now.shift(seconds=10**5)
assert self.now.humanize(later105, granularity="hour") == "27 hours ago"
assert later105.humanize(self.now, granularity="hour") == "in 27 hours"
assert self.now.humanize(later105, granularity="day") == "a day ago"
Expand All @@ -1921,7 +1921,7 @@ def test_granularity(self):
assert self.now.humanize(later105, granularity=["month"]) == "0 months ago"
assert later105.humanize(self.now, granularity=["month"]) == "in 0 months"

later106 = self.now.shift(seconds=3 * 10 ** 6)
later106 = self.now.shift(seconds=3 * 10**6)
assert self.now.humanize(later106, granularity="day") == "34 days ago"
assert later106.humanize(self.now, granularity="day") == "in 34 days"
assert self.now.humanize(later106, granularity="week") == "4 weeks ago"
Expand All @@ -1931,7 +1931,7 @@ def test_granularity(self):
assert self.now.humanize(later106, granularity="year") == "0 years ago"
assert later106.humanize(self.now, granularity="year") == "in 0 years"

later506 = self.now.shift(seconds=50 * 10 ** 6)
later506 = self.now.shift(seconds=50 * 10**6)
assert self.now.humanize(later506, granularity="week") == "82 weeks ago"
assert later506.humanize(self.now, granularity="week") == "in 82 weeks"
assert self.now.humanize(later506, granularity="month") == "18 months ago"
Expand All @@ -1943,27 +1943,27 @@ def test_granularity(self):

assert self.now.humanize(later1, granularity="quarter") == "0 quarters ago"
assert later1.humanize(self.now, granularity="quarter") == "in 0 quarters"
later107 = self.now.shift(seconds=10 ** 7)
later107 = self.now.shift(seconds=10**7)
assert self.now.humanize(later107, granularity="quarter") == "a quarter ago"
assert later107.humanize(self.now, granularity="quarter") == "in a quarter"
later207 = self.now.shift(seconds=2 * 10 ** 7)
later207 = self.now.shift(seconds=2 * 10**7)
assert self.now.humanize(later207, granularity="quarter") == "2 quarters ago"
assert later207.humanize(self.now, granularity="quarter") == "in 2 quarters"
later307 = self.now.shift(seconds=3 * 10 ** 7)
later307 = self.now.shift(seconds=3 * 10**7)
assert self.now.humanize(later307, granularity="quarter") == "3 quarters ago"
assert later307.humanize(self.now, granularity="quarter") == "in 3 quarters"
later377 = self.now.shift(seconds=3.7 * 10 ** 7)
later377 = self.now.shift(seconds=3.7 * 10**7)
assert self.now.humanize(later377, granularity="quarter") == "4 quarters ago"
assert later377.humanize(self.now, granularity="quarter") == "in 4 quarters"
later407 = self.now.shift(seconds=4 * 10 ** 7)
later407 = self.now.shift(seconds=4 * 10**7)
assert self.now.humanize(later407, granularity="quarter") == "5 quarters ago"
assert later407.humanize(self.now, granularity="quarter") == "in 5 quarters"

later108 = self.now.shift(seconds=10 ** 8)
later108 = self.now.shift(seconds=10**8)
assert self.now.humanize(later108, granularity="year") == "3 years ago"
assert later108.humanize(self.now, granularity="year") == "in 3 years"

later108onlydistance = self.now.shift(seconds=10 ** 8)
later108onlydistance = self.now.shift(seconds=10**8)
assert (
self.now.humanize(
later108onlydistance, only_distance=True, granularity="year"
Expand Down Expand Up @@ -2012,15 +2012,15 @@ def test_multiple_granularity(self):
== "0 days an hour and 6 minutes ago"
)

later105 = self.now.shift(seconds=10 ** 5)
later105 = self.now.shift(seconds=10**5)
assert (
self.now.humanize(later105, granularity=["hour", "day", "minute"])
== "a day 3 hours and 46 minutes ago"
)
with pytest.raises(ValueError):
self.now.humanize(later105, granularity=["error", "second"])

later108onlydistance = self.now.shift(seconds=10 ** 8)
later108onlydistance = self.now.shift(seconds=10**8)
assert (
self.now.humanize(
later108onlydistance, only_distance=True, granularity=["year"]
Expand Down
21 changes: 9 additions & 12 deletions tests/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,18 +359,15 @@ def test_three_args(self):

def test_full_kwargs(self):

assert (
self.factory.get(
year=2016,
month=7,
day=14,
hour=7,
minute=16,
second=45,
microsecond=631092,
)
== datetime(2016, 7, 14, 7, 16, 45, 631092, tzinfo=tz.tzutc())
)
assert self.factory.get(
year=2016,
month=7,
day=14,
hour=7,
minute=16,
second=45,
microsecond=631092,
) == datetime(2016, 7, 14, 7, 16, 45, 631092, tzinfo=tz.tzutc())

def test_three_kwargs(self):

Expand Down
57 changes: 21 additions & 36 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,18 @@ def test_YY_and_YYYY_format_list(self):
2019, 1, 15
)

assert (
self.parser.parse(
"15/01/2019T04:05:06.789120Z",
["D/M/YYThh:mm:ss.SZ", "D/M/YYYYThh:mm:ss.SZ"],
)
== datetime(2019, 1, 15, 4, 5, 6, 789120, tzinfo=tz.tzutc())
)
assert self.parser.parse(
"15/01/2019T04:05:06.789120Z",
["D/M/YYThh:mm:ss.SZ", "D/M/YYYYThh:mm:ss.SZ"],
) == datetime(2019, 1, 15, 4, 5, 6, 789120, tzinfo=tz.tzutc())

# regression test for issue #447
def test_timestamp_format_list(self):
# should not match on the "X" token
assert (
self.parser.parse(
"15 Jul 2000",
["MM/DD/YYYY", "YYYY-MM-DD", "X", "DD-MMMM-YYYY", "D MMM YYYY"],
)
== datetime(2000, 7, 15)
)
assert self.parser.parse(
"15 Jul 2000",
["MM/DD/YYYY", "YYYY-MM-DD", "X", "DD-MMMM-YYYY", "D MMM YYYY"],
) == datetime(2000, 7, 15)

with pytest.raises(ParserError):
self.parser.parse("15 Jul", "X")
Expand Down Expand Up @@ -503,21 +497,15 @@ def test_parse_with_extra_words_at_start_and_end_valid(self):
"2016-05-16T04:05:06.789120 blah", "YYYY-MM-DDThh:mm:ss.S"
) == datetime(2016, 5, 16, 4, 5, 6, 789120)

assert (
self.parser.parse(
"Meet me at 2016-05-16T04:05:06.789120 at the restaurant.",
"YYYY-MM-DDThh:mm:ss.S",
)
== datetime(2016, 5, 16, 4, 5, 6, 789120)
)
assert self.parser.parse(
"Meet me at 2016-05-16T04:05:06.789120 at the restaurant.",
"YYYY-MM-DDThh:mm:ss.S",
) == datetime(2016, 5, 16, 4, 5, 6, 789120)

assert (
self.parser.parse(
"Meet me at 2016-05-16 04:05:06.789120 at the restaurant.",
"YYYY-MM-DD hh:mm:ss.S",
)
== datetime(2016, 5, 16, 4, 5, 6, 789120)
)
assert self.parser.parse(
"Meet me at 2016-05-16 04:05:06.789120 at the restaurant.",
"YYYY-MM-DD hh:mm:ss.S",
) == datetime(2016, 5, 16, 4, 5, 6, 789120)

# regression test for issue #701
# tests cases of a partial match surrounded by punctuation
Expand Down Expand Up @@ -783,14 +771,11 @@ def test_parse_normalize_whitespace(self):
with pytest.raises(ParserError):
self.parser.parse("Jun 1 2005 1:33PM", "MMM D YYYY H:mmA")

assert (
self.parser.parse(
"\t 2013-05-05 T \n 12:30:45\t123456 \t \n",
"YYYY-MM-DD T HH:mm:ss S",
normalize_whitespace=True,
)
== datetime(2013, 5, 5, 12, 30, 45, 123456)
)
assert self.parser.parse(
"\t 2013-05-05 T \n 12:30:45\t123456 \t \n",
"YYYY-MM-DD T HH:mm:ss S",
normalize_whitespace=True,
) == datetime(2013, 5, 5, 12, 30, 45, 123456)

with pytest.raises(ParserError):
self.parser.parse(
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ include_trailing_comma = true

[flake8]
per-file-ignores = arrow/__init__.py:F401,tests/*:ANN001,ANN201
ignore = E203,E501,W503,ANN101,ANN102
ignore = E203,E501,W503,ANN101,ANN102,ANN401

0 comments on commit 18d9afb

Please sign in to comment.