Skip to content

Commit 36a5634

Browse files
serhii73Gallaecio
andauthored
Fix tests (#1248)
* Fix tests * Fix the TestLocalTZOffset test * Setup tests for minimum deps * Run pre-commit --------- Co-authored-by: Adrián Chaves <adrian@chaves.io>
1 parent 47acb88 commit 36a5634

26 files changed

+125
-166
lines changed

.flake8

Lines changed: 0 additions & 7 deletions
This file was deleted.

.github/workflows/cifuzz.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fuzz-seconds: 600
2222
output-sarif: true
2323
- name: Upload Crash
24-
uses: actions/upload-artifact@v3
24+
uses: actions/upload-artifact@v4
2525
if: failure() && steps.build.outcome == 'success'
2626
with:
2727
name: artifacts

.github/workflows/main.yml

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,24 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
include:
17-
- python-version: 3.9
18-
env:
19-
TOXENV: flake8
20-
- python-version: 3.9
21-
env:
22-
TOXENV: py
23-
- python-version: "3.10"
24-
env:
25-
TOXENV: py
17+
- python-version: "3.13"
18+
toxenv: pre-commit
19+
- python-version: "3.9"
20+
toxenv: min
21+
- python-version: "3.9"
22+
toxenv: min-all
23+
- python-version: "3.9"
2624
- python-version: "3.10"
27-
env:
28-
TOXENV: latest
29-
- python-version: "3.11"
30-
env:
31-
TOXENV: py
3225
- python-version: "3.11"
33-
env:
34-
TOXENV: latest
3526
- python-version: "3.12"
36-
env:
37-
TOXENV: py
38-
- python-version: "3.12"
39-
env:
40-
TOXENV: latest
41-
- python-version: "3.13"
42-
env:
43-
TOXENV: py
4427
- python-version: "3.13"
45-
env:
46-
TOXENV: latest
28+
toxenv: all
4729
- python-version: "3.13"
48-
env:
49-
TOXENV: twinecheck
30+
toxenv: scripts
5031
- python-version: "3.12" # Keep in sync with tox.ini
51-
env:
52-
TOXENV: docs
32+
toxenv: docs
33+
- python-version: "3.13"
34+
toxenv: twinecheck
5335
steps:
5436
- uses: actions/checkout@v3
5537
- name: 'Set up Python ${{ matrix.python-version }}'
@@ -63,13 +45,6 @@ jobs:
6345
python -m pip install --upgrade pip
6446
pip install tox
6547
- name: Run tests
66-
run: tox -e ${{ matrix.env.TOXENV }}
48+
run: tox -e ${{ matrix.toxenv || 'py' }}
6749
- name: Upload coverage.xml to codecov
68-
if: ${{ matrix.env.python-version == '3.9' && matrix.env.TOXENV == 'latest' }}
69-
uses: codecov/codecov-action@v3
70-
71-
pre-commit:
72-
runs-on: ubuntu-latest
73-
steps:
74-
- uses: actions/checkout@v3
75-
- uses: pre-commit/action@v3.0.0
50+
uses: codecov/codecov-action@v4.0.1

.pre-commit-config.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
repos:
2-
- repo: https://github.com/PyCQA/flake8
3-
rev: 6.0.0 # 6.0.0 drops Python 3.7 support
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.3
44
hooks:
5-
- id: flake8
6-
args: ['--config=.flake8']
7-
- repo: https://github.com/psf/black.git
8-
rev: 23.3.0
9-
hooks:
10-
- id: black
11-
exclude: ^dateparser/data/date_translation_data/
12-
- repo: https://github.com/pycqa/isort
13-
rev: 5.12.0 # 5.12 drops Python 3.7 support
14-
hooks:
15-
- id: isort
5+
- id: ruff
6+
args: [ --fix ]
7+
- id: ruff-format

dateparser/calendars/jalali_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
from collections import OrderedDict
3-
from datetime import datetime
43
from functools import reduce
54

65
from convertdate import persian

dateparser/data/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
from dateparser.data import date_translation_data
2-
3-
from .languages_info import language_locale_dict, language_order
2+
from .languages_info import language_order, language_locale_dict

dateparser/date.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import collections
2-
import sys
32
from collections.abc import Set
43
from datetime import datetime, timedelta
54

dateparser/freshness_date_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def _parse_time(self, date_string, settings):
3131
date_string = re.sub(r"\b(?:ago|in)\b", "", date_string)
3232
try:
3333
return time_parser(date_string)
34-
except:
34+
except Exception:
3535
pass
3636

3737
def get_local_tz(self):

dateparser/parser.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def _find_best_matching_date(cls, datestring):
182182
dt = strptime(datestring, fmt), cls._get_period(fmt)
183183
if len(str(dt[0].year)) == 4:
184184
return dt
185-
except:
185+
except Exception:
186186
pass
187187
return None
188188

@@ -216,7 +216,7 @@ def parse(cls, datestring, settings):
216216
missing = _get_missing_parts(fmt)
217217
_check_strict_parsing(missing, settings)
218218
return dt
219-
except:
219+
except Exception:
220220
pass
221221
else:
222222
if ambiguous_date:
@@ -332,7 +332,7 @@ def __init__(self, tokens, settings):
332332
token.index(":")
333333
# Is after period? raise ValueError if '.' can't be found:
334334
self.tokens[self.tokens.index((token, 0)) + 1][0].index(".")
335-
except:
335+
except Exception:
336336
microsecond = None
337337

338338
if microsecond:
@@ -342,7 +342,7 @@ def __init__(self, tokens, settings):
342342
meridian = MERIDIAN.search(
343343
self.filtered_tokens[meridian_index][0]
344344
).group()
345-
except:
345+
except Exception:
346346
meridian = None
347347

348348
if any([":" in token, meridian, microsecond]):
@@ -514,9 +514,9 @@ def _correct_for_time_frame(self, dateobj, tz):
514514

515515
# NOTE: If this assert fires, self.now needs to be made offset-aware in a similar
516516
# way that dateobj is temporarily made offset-aware.
517-
assert not (
518-
self.now.tzinfo is None and dateobj.tzinfo is not None
519-
), "`self.now` doesn't have `tzinfo`. Review comment in code for details."
517+
assert not (self.now.tzinfo is None and dateobj.tzinfo is not None), (
518+
"`self.now` doesn't have `tzinfo`. Review comment in code for details."
519+
)
520520

521521
# Store the original dateobj values so that upon subsequent parsing everything is not
522522
# treated as offset-aware if offset awareness is changed.
@@ -686,7 +686,7 @@ def parse_alpha(token, skip_component=None):
686686
(component, getattr(do, component)),
687687
("day", prev_value),
688688
]
689-
except:
689+
except Exception:
690690
pass
691691
else:
692692
raise ValueError("Unable to parse: %s" % token)

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import os
1414
import sys
1515

16+
import dateparser
17+
1618
# Get the project root dir, which is the parent dir of this
1719
cwd = os.getcwd()
1820
project_root = os.path.dirname(cwd)
@@ -22,8 +24,6 @@
2224
# version is used.
2325
sys.path.insert(0, project_root)
2426

25-
import dateparser
26-
2727
# -- General configuration ---------------------------------------------
2828

2929
# Add any Sphinx extension module names here, as strings. They can be

0 commit comments

Comments
 (0)