Skip to content

Commit 119b900

Browse files
committed
Fix tests
1 parent 47acb88 commit 119b900

File tree

8 files changed

+56
-29
lines changed

8 files changed

+56
-29
lines changed

.github/workflows/cifuzz.yml

+1-1
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

dateparser/custom_language_detection/fasttext.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22

3-
import fasttext
4-
3+
from dateparser.custom_language_detection.fasttext_wrapper import load_model
54
from dateparser_cli.exceptions import FastTextModelNotFoundException
65
from dateparser_cli.fasttext_manager import fasttext_downloader
76
from dateparser_cli.utils import create_data_model_home, dateparser_model_home
@@ -27,7 +26,7 @@ def _load_fasttext_model():
2726
model_path = os.path.join(dateparser_model_home, downloaded_models[0])
2827
if not os.path.isfile(model_path):
2928
raise FastTextModelNotFoundException("Fasttext model file not found")
30-
_FastTextCache.model = fasttext.load_model(model_path)
29+
_FastTextCache.model = load_model(model_path)
3130
return _FastTextCache.model
3231

3332

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fasttext
2+
import numpy as np
3+
4+
5+
class FastTextWrapper:
6+
def __init__(self, model_path):
7+
self.model = fasttext.load_model(model_path)
8+
9+
def predict(self, text, k=1, threshold=0.0, on_unicode_error="strict"):
10+
def check(entry):
11+
if entry.find("\n") != -1:
12+
raise ValueError("predict processes one line at a time (remove '\\n')")
13+
entry += "\n"
14+
return entry
15+
16+
if isinstance(text, list):
17+
text = [check(entry) for entry in text]
18+
all_labels, all_probs = self.model.f.multilinePredict(
19+
text, k, threshold, on_unicode_error
20+
)
21+
return all_labels, all_probs
22+
else:
23+
text = check(text)
24+
predictions = self.model.f.predict(text, k, threshold, on_unicode_error)
25+
if predictions:
26+
probs, labels = zip(*predictions)
27+
else:
28+
probs, labels = ([], ())
29+
30+
return labels, np.asarray(probs)
31+
32+
33+
def load_model(model_path):
34+
return FastTextWrapper(model_path)

fuzzing/requirements.txt

-1
This file was deleted.

setup.cfg

+6-17
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,17 @@ universal = 1
44
[flake8]
55
max-line-length = 119
66
ignore =
7-
# This rule goes against the PEP 8 recommended style and it's incompatible
8-
# with W504
97
W503
108

11-
# Exclude automatically generated files
12-
# E501: Line too long
13-
dateparser/data/date_translation_data/* E501
14-
15-
# Exclude files that are meant to provide top-level imports
16-
# F401: Module imported but unused
17-
dateparser/data/__init__.py F401
18-
dateparser/languages/__init__.py F401
19-
20-
# Issues pending a review:
21-
dateparser/freshness_date_parser.py E722
22-
dateparser/parser.py E722
23-
dateparser/docs/conf.py E402
24-
25-
# Additional ignored codes
269
E203
2710
E501
2811
E722
2912
F401
3013
E701
3114
E704
15+
16+
exclude =
17+
dateparser/data/date_translation_data/*
18+
dateparser/data/__init__.py
19+
dateparser/languages/__init__.py
20+
docs/conf.py

tests/test_clean_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_dates_which_match_locales_are_parsed(
119119
languages=["en"],
120120
region="",
121121
date_formats=["%a", "%a", "%a", "%a"],
122-
expected_date=datetime(1969, 1, 31, 14, 4),
122+
expected_date=datetime(1969, 1, 31, 13, 4),
123123
)
124124
]
125125
)

tests/test_search.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,14 @@ def test_search_and_parse(self, shortname, string, expected, settings=None):
642642
(
643643
"June 23th 5 pm EST",
644644
datetime.datetime(
645-
2023, 6, 23, 17, 0, tzinfo=pytz.timezone("EST")
645+
2023,
646+
6,
647+
23,
648+
17,
649+
0,
650+
tzinfo=datetime.timezone(
651+
datetime.timedelta(hours=-5), name="EST"
652+
),
646653
),
647654
),
648655
("May 31", datetime.datetime(2023, 5, 31, 0, 0)),

tox.ini

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ envlist = flake8, py3
55
deps =
66
-rdateparser_scripts/requirements.txt
77
-rtests/requirements.txt
8-
-rfuzzing/requirements.txt
8+
atheris; python_version < '3.12'
99

1010
[testenv]
1111
deps =
@@ -40,10 +40,9 @@ commands =
4040

4141
[testenv:twinecheck]
4242
basepython = python3
43-
extras = []
4443
deps =
45-
twine==4.0.2
46-
build==1.0.3
44+
build
45+
twine
4746
commands =
48-
python -m build --sdist
47+
python -m build --sdist --wheel
4948
twine check dist/*

0 commit comments

Comments
 (0)