Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #1248

Merged
merged 6 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fuzz-seconds: 600
output-sarif: true
- name: Upload Crash
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
Gallaecio marked this conversation as resolved.
Show resolved Hide resolved
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
53 changes: 14 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,24 @@ jobs:
fail-fast: false
matrix:
include:
- python-version: 3.9
env:
TOXENV: flake8
- python-version: 3.9
env:
TOXENV: py
- python-version: "3.10"
env:
TOXENV: py
- python-version: "3.13"
toxenv: pre-commit
- python-version: "3.9"
toxenv: min
- python-version: "3.9"
toxenv: min-all
- python-version: "3.9"
- python-version: "3.10"
env:
TOXENV: latest
- python-version: "3.11"
env:
TOXENV: py
- python-version: "3.11"
env:
TOXENV: latest
- python-version: "3.12"
env:
TOXENV: py
- python-version: "3.12"
env:
TOXENV: latest
- python-version: "3.13"
env:
TOXENV: py
- python-version: "3.13"
env:
TOXENV: latest
toxenv: all
- python-version: "3.13"
env:
TOXENV: twinecheck
toxenv: scripts
- python-version: "3.12" # Keep in sync with tox.ini
env:
TOXENV: docs
toxenv: docs
- python-version: "3.13"
toxenv: twinecheck
steps:
- uses: actions/checkout@v3
- name: 'Set up Python ${{ matrix.python-version }}'
Expand All @@ -63,13 +45,6 @@ jobs:
python -m pip install --upgrade pip
pip install tox
- name: Run tests
run: tox -e ${{ matrix.env.TOXENV }}
run: tox -e ${{ matrix.toxenv || 'py' }}
- name: Upload coverage.xml to codecov
if: ${{ matrix.env.python-version == '3.9' && matrix.env.TOXENV == 'latest' }}
uses: codecov/codecov-action@v3

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pre-commit/[email protected]
uses: codecov/[email protected]
18 changes: 5 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0 # 6.0.0 drops Python 3.7 support
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.3
hooks:
- id: flake8
args: ['--config=.flake8']
- repo: https://github.com/psf/black.git
rev: 23.3.0
hooks:
- id: black
exclude: ^dateparser/data/date_translation_data/
- repo: https://github.com/pycqa/isort
rev: 5.12.0 # 5.12 drops Python 3.7 support
hooks:
- id: isort
- id: ruff
args: [ --fix ]
- id: ruff-format
1 change: 0 additions & 1 deletion dateparser/calendars/jalali_parser.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import re
from collections import OrderedDict
from datetime import datetime
from functools import reduce

from convertdate import persian
Expand Down
3 changes: 1 addition & 2 deletions dateparser/data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
from dateparser.data import date_translation_data

from .languages_info import language_locale_dict, language_order
from .languages_info import language_order, language_locale_dict
1 change: 0 additions & 1 deletion dateparser/date.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import collections
import sys
from collections.abc import Set
from datetime import datetime, timedelta

Expand Down
2 changes: 1 addition & 1 deletion dateparser/freshness_date_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _parse_time(self, date_string, settings):
date_string = re.sub(r"\b(?:ago|in)\b", "", date_string)
try:
return time_parser(date_string)
except:
except Exception:
pass

def get_local_tz(self):
Expand Down
16 changes: 8 additions & 8 deletions dateparser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _find_best_matching_date(cls, datestring):
dt = strptime(datestring, fmt), cls._get_period(fmt)
if len(str(dt[0].year)) == 4:
return dt
except:
except Exception:
pass
return None

Expand Down Expand Up @@ -216,7 +216,7 @@ def parse(cls, datestring, settings):
missing = _get_missing_parts(fmt)
_check_strict_parsing(missing, settings)
return dt
except:
except Exception:
pass
else:
if ambiguous_date:
Expand Down Expand Up @@ -332,7 +332,7 @@ def __init__(self, tokens, settings):
token.index(":")
# Is after period? raise ValueError if '.' can't be found:
self.tokens[self.tokens.index((token, 0)) + 1][0].index(".")
except:
except Exception:
microsecond = None

if microsecond:
Expand All @@ -342,7 +342,7 @@ def __init__(self, tokens, settings):
meridian = MERIDIAN.search(
self.filtered_tokens[meridian_index][0]
).group()
except:
except Exception:
meridian = None

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

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

# Store the original dateobj values so that upon subsequent parsing everything is not
# treated as offset-aware if offset awareness is changed.
Expand Down Expand Up @@ -686,7 +686,7 @@ def parse_alpha(token, skip_component=None):
(component, getattr(do, component)),
("day", prev_value),
]
except:
except Exception:
pass
else:
raise ValueError("Unable to parse: %s" % token)
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import os
import sys

import dateparser

# Get the project root dir, which is the parent dir of this
cwd = os.getcwd()
project_root = os.path.dirname(cwd)
Expand All @@ -22,8 +24,6 @@
# version is used.
sys.path.insert(0, project_root)

import dateparser

# -- General configuration ---------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
Expand Down
1 change: 0 additions & 1 deletion fuzzing/requirements.txt

This file was deleted.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[tool.ruff]
exclude = ["date_translation_data"]

[tool.ruff.lint.per-file-ignores]
"dateparser/data/__init__.py" = ["F401"]
"dateparser/languages/__init__.py" = ["F401"]
31 changes: 0 additions & 31 deletions setup.cfg

This file was deleted.

17 changes: 7 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
r":mod:|:class:|:func:", "", open("HISTORY.rst", encoding="utf-8").read()
)

test_requirements = open("tests/requirements.txt").read().splitlines()

setup(
name="dateparser",
version=__version__,
Expand All @@ -31,19 +29,18 @@
packages=find_packages(exclude=("tests", "tests.*")),
include_package_data=True,
install_requires=[
"python-dateutil",
"pytz",
# https://bitbucket.org/mrabarnett/mrab-regex/issues/314/import-error-no-module-named
"regex !=2019.02.19,!=2021.8.27",
"tzlocal",
"python-dateutil>=2.7.0",
"pytz>=2024.2",
"regex>=2015.06.24,!=2019.02.19,!=2021.8.27",
"tzlocal>=0.2",
],
entry_points={
"console_scripts": ["dateparser-download = dateparser_cli.cli:entrance"],
},
extras_require={
"calendars": ["hijridate", "convertdate"],
"fasttext": ["fasttext"],
"langdetect": ["langdetect"],
"calendars": ["convertdate>=2.2.1", "hijridate"],
"fasttext": ["fasttext>=0.9.1", "numpy>=1.19.3,<2"],
"langdetect": ["langdetect>=1.0.0"],
},
license="BSD",
zip_safe=False,
Expand Down
4 changes: 0 additions & 4 deletions tests/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_clean_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_dates_which_match_locales_are_parsed(
languages=["en"],
region="",
date_formats=["%a", "%a", "%a", "%a"],
expected_date=datetime(1969, 1, 31, 14, 4),
expected_date=datetime(1969, 1, 31, 13, 4),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just changed the digit to resolve the error in this test

)
]
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_should_reject_easily_mistaken_dateutil_arguments(self, invalid_period):
self.when_date_range_generated(
begin=datetime(2014, 6, 15),
end=datetime(2014, 6, 25),
**{invalid_period: 1}
**{invalid_period: 1},
)
self.then_period_was_rejected(invalid_period)

Expand Down
8 changes: 2 additions & 6 deletions tests/test_date_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ def setUp(self):
param("[সেপ্টেম্বর] 04, 2014.", datetime(2014, 9, 4)),
param("মঙ্গলবার জুলাই 22, 2014", datetime(2014, 7, 22)),
param("শুক্রবার", datetime(2012, 11, 9)),
param(
"শুক্র, 12 ডিসেম্বর 2014 10:55:50", datetime(2014, 12, 12, 10, 55, 50)
),
param("শুক্র, 12 ডিসেম্বর 2014 10:55:50", datetime(2014, 12, 12, 10, 55, 50)),
param("1লা জানুয়ারী 2015", datetime(2015, 1, 1)),
param("25শে মার্চ 1971", datetime(1971, 3, 25)),
param("8ই মে 2002", datetime(2002, 5, 8)),
Expand Down Expand Up @@ -418,9 +416,7 @@ def test_stringified_datetime_should_parse_fine(self):
param("[সেপ্টেম্বর] 04, 2014.", datetime(2014, 9, 4)),
param("মঙ্গলবার জুলাই 22, 2014", datetime(2014, 7, 22)),
param("শুক্রবার", datetime(2012, 11, 9)),
param(
"শুক্র, 12 ডিসেম্বর 2014 10:55:50", datetime(2014, 12, 12, 10, 55, 50)
),
param("শুক্র, 12 ডিসেম্বর 2014 10:55:50", datetime(2014, 12, 12, 10, 55, 50)),
param("1লা জানুয়ারী 2015", datetime(2015, 1, 1)),
param("25শে মার্চ 1971", datetime(1971, 3, 25)),
param("8ই মে 2002", datetime(2002, 5, 8)),
Expand Down
4 changes: 4 additions & 0 deletions tests/test_dateparser_data_integrity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import pytest

pytest.importorskip("ruamel")

from dateparser_scripts.write_complete_data import write_complete_data


Expand Down
6 changes: 4 additions & 2 deletions tests/test_hijri.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import sys
import unittest
import pytest

pytest.importorskip("hijridate")

from datetime import datetime

from parameterized import param, parameterized
Expand Down
4 changes: 4 additions & 0 deletions tests/test_jalali.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import pytest

pytest.importorskip("convertdate")

from datetime import datetime

from parameterized import param, parameterized
Expand Down
4 changes: 4 additions & 0 deletions tests/test_language_detect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import pytest

pytest.importorskip("fasttext")

import unittest
from datetime import datetime
from unittest.mock import Mock
Expand Down
Loading
Loading