Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii73 committed Jan 24, 2025
1 parent 47acb88 commit 119b900
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 29 deletions.
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
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
Expand Down
5 changes: 2 additions & 3 deletions dateparser/custom_language_detection/fasttext.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import fasttext

from dateparser.custom_language_detection.fasttext_wrapper import load_model
from dateparser_cli.exceptions import FastTextModelNotFoundException
from dateparser_cli.fasttext_manager import fasttext_downloader
from dateparser_cli.utils import create_data_model_home, dateparser_model_home
Expand All @@ -27,7 +26,7 @@ def _load_fasttext_model():
model_path = os.path.join(dateparser_model_home, downloaded_models[0])
if not os.path.isfile(model_path):
raise FastTextModelNotFoundException("Fasttext model file not found")
_FastTextCache.model = fasttext.load_model(model_path)
_FastTextCache.model = load_model(model_path)
return _FastTextCache.model


Expand Down
34 changes: 34 additions & 0 deletions dateparser/custom_language_detection/fasttext_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import fasttext
import numpy as np


class FastTextWrapper:
def __init__(self, model_path):
self.model = fasttext.load_model(model_path)

def predict(self, text, k=1, threshold=0.0, on_unicode_error="strict"):
def check(entry):
if entry.find("\n") != -1:
raise ValueError("predict processes one line at a time (remove '\\n')")
entry += "\n"
return entry

if isinstance(text, list):
text = [check(entry) for entry in text]
all_labels, all_probs = self.model.f.multilinePredict(
text, k, threshold, on_unicode_error
)
return all_labels, all_probs
else:
text = check(text)
predictions = self.model.f.predict(text, k, threshold, on_unicode_error)
if predictions:
probs, labels = zip(*predictions)
else:
probs, labels = ([], ())

return labels, np.asarray(probs)


def load_model(model_path):
return FastTextWrapper(model_path)
1 change: 0 additions & 1 deletion fuzzing/requirements.txt

This file was deleted.

23 changes: 6 additions & 17 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,17 @@ universal = 1
[flake8]
max-line-length = 119
ignore =
# This rule goes against the PEP 8 recommended style and it's incompatible
# with W504
W503

# Exclude automatically generated files
# E501: Line too long
dateparser/data/date_translation_data/* E501

# Exclude files that are meant to provide top-level imports
# F401: Module imported but unused
dateparser/data/__init__.py F401
dateparser/languages/__init__.py F401

# Issues pending a review:
dateparser/freshness_date_parser.py E722
dateparser/parser.py E722
dateparser/docs/conf.py E402

# Additional ignored codes
E203
E501
E722
F401
E701
E704

exclude =
dateparser/data/date_translation_data/*
dateparser/data/__init__.py
dateparser/languages/__init__.py
docs/conf.py
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),
)
]
)
Expand Down
9 changes: 8 additions & 1 deletion tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,14 @@ def test_search_and_parse(self, shortname, string, expected, settings=None):
(
"June 23th 5 pm EST",
datetime.datetime(
2023, 6, 23, 17, 0, tzinfo=pytz.timezone("EST")
2023,
6,
23,
17,
0,
tzinfo=datetime.timezone(
datetime.timedelta(hours=-5), name="EST"
),
),
),
("May 31", datetime.datetime(2023, 5, 31, 0, 0)),
Expand Down
9 changes: 4 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist = flake8, py3
deps =
-rdateparser_scripts/requirements.txt
-rtests/requirements.txt
-rfuzzing/requirements.txt
atheris; python_version < '3.12'

[testenv]
deps =
Expand Down Expand Up @@ -40,10 +40,9 @@ commands =

[testenv:twinecheck]
basepython = python3
extras = []
deps =
twine==4.0.2
build==1.0.3
build
twine
commands =
python -m build --sdist
python -m build --sdist --wheel
twine check dist/*

0 comments on commit 119b900

Please sign in to comment.