Skip to content

Commit

Permalink
Sorting future FV (#188)
Browse files Browse the repository at this point in the history
* updated statement to sort documents for future FV

* Added tests
  • Loading branch information
DeltaDaniel authored Jun 25, 2024
1 parent 5057298 commit aacf11c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions dev_requirements/requirements-tests.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pytest-datafiles
pytest-mock
pytest-asyncio==0.22.0 #pinned for bugs/breaking changes in 0.23.x
aioresponses
freezegun
8 changes: 8 additions & 0 deletions dev_requirements/requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ aiosignal==1.3.1
# via aiohttp
attrs==23.2.0
# via aiohttp
colorama==0.4.6
# via pytest
freezegun==1.5.1
# via -r dev_requirements/requirements-tests.in
frozenlist==1.4.1
# via
# aiohttp
Expand Down Expand Up @@ -40,5 +44,9 @@ pytest-datafiles==3.0.0
# via -r dev_requirements/requirements-tests.in
pytest-mock==3.14.0
# via -r dev_requirements/requirements-tests.in
python-dateutil==2.9.0.post0
# via freezegun
six==1.16.0
# via python-dateutil
yarl==1.9.4
# via aiohttp
8 changes: 0 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#
# pip-compile pyproject.toml
#
aiodns==3.2.0
# via aiohttp
aiohttp[speedups]==3.9.5
# via
# aiohttp-requests
Expand All @@ -22,8 +20,6 @@ beautifulsoup4==4.12.3
# via edi_energy_scraper (pyproject.toml)
brotli==1.1.0
# via aiohttp
cffi==1.16.0
# via pycares
coworker==2.0.1
# via aiohttp-requests
frozenlist==1.4.1
Expand All @@ -44,10 +40,6 @@ multidict==6.0.5
# yarl
packaging==24.0
# via marshmallow
pycares==4.4.0
# via aiodns
pycparser==2.22
# via cffi
pypdf==4.2.0
# via edi_energy_scraper (pyproject.toml)
pytz==2024.1
Expand Down
7 changes: 6 additions & 1 deletion src/edi_energy_scraper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,12 @@ def get_edifact_format_version_range_from_filename(path: Path) -> List[EdifactFo

is_format_version_end_greater_than_next_format_version = format_version_end > next_format_version
if is_format_version_end_greater_than_next_format_version:
format_version_end = next_format_version
# files which have been published earlier and not been replaced yet are used until the next format version
if format_version_start < next_format_version:
format_version_end = next_format_version
# new documents which are not valdi yet are used for the future format version
else:
format_version_end = format_version_start

format_versions = [efv.value for efv in EdifactFormatVersion]

Expand Down
12 changes: 12 additions & 0 deletions unittests/test_edienergyscraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from aioresponses import aioresponses
from bs4 import BeautifulSoup
from freezegun import freeze_time
from maus.edifact import EdifactFormatVersion

from edi_energy_scraper import (
Expand Down Expand Up @@ -505,6 +506,7 @@ def test_get_edifact_version_and_formats(self, input_filename: str, expected_res

assert actual == expected_result

@freeze_time("2024-06-25")
@pytest.mark.parametrize(
"input_filename, expected_result",
[
Expand All @@ -527,6 +529,16 @@ def test_get_edifact_version_and_formats(self, input_filename: str, expected_res
[EdifactFormatVersion.FV2310, EdifactFormatVersion.FV2404],
id="valid for two format versions",
),
pytest.param(
"IFTSTAMIG2.0e_20280930_20231001.pdf",
[EdifactFormatVersion.FV2310, EdifactFormatVersion.FV2404, EdifactFormatVersion.FV2410],
id="valid in future, starting in past",
),
pytest.param(
"IFTSTAMIG2.0e_20280930_20250404.pdf",
[EdifactFormatVersion.FV2504],
id="starting in future",
),
],
)
def test_get_edifact_format_version_range(self, input_filename: str, expected_result: List[EdifactFormatVersion]):
Expand Down

0 comments on commit aacf11c

Please sign in to comment.