-
Notifications
You must be signed in to change notification settings - Fork 0
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
move parsing functions #13
Conversation
due to issues with tox
Co-authored-by: kevin <68426071+hf-krechan@users.noreply.github.com>
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ich vermute dass wir noch die mypy settings anpassen müssen.
Da sind verdächtig viele variablen nicht mit einem type hint verstehen.
Können das aber auch in einem extra PR machen.
Sonst passt es soweit. Habe nur viele Kleinigkeiten.
@@ -1,2 +1,3 @@ | |||
# specific requirements for the tox coverage env | |||
coverage | |||
pytest_loguru |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh nice, was ist es, was tut es?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/migmose/parsing.py
Outdated
from maus.edifact import EdifactFormat | ||
|
||
|
||
def find_file_to_type(message_types: list[EdifactFormat], input_dir: Path) -> dict[EdifactFormat, Path]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
statt type
würde ich lieber bei dem fachlichen wording bleiben. Also eher format
oder EdifactFormat
Das dann in dem Funktionsnamen und dem parameter message_type
anpassen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | ||
finds the file with the message type in the input directory | ||
""" | ||
file_dict = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beschwert sich mypy hier nicht über den fehlenden typehint ^^?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finde ich gerade selber komisch, aber nein 🤔
src/migmose/parsing.py
Outdated
logger.warning(f"⚠️ No file found for {message_type}.", fg="red") | ||
if file_dict: | ||
return file_dict | ||
logger.error("⚠️ No files found in the input directory.", fg="red") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finde die emoticons mega gut. Würde nur für errors ein anders emoticon nehmen, bspw. ❌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/migmose/parsing.py
Outdated
raise click.Abort() | ||
|
||
|
||
def preliminary_output_as_json(table: list[str], message_type: EdifactFormat, output_dir: Path) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def preliminary_output_as_json(table: list[str], message_type: EdifactFormat, output_dir: Path) -> None: | |
def preliminary_output_as_json(table: list[str], message_format: EdifactFormat, output_dir: Path) -> None: |
oder
def preliminary_output_as_json(table: list[str], message_type: EdifactFormat, output_dir: Path) -> None: | |
def preliminary_output_as_json(table: list[str], edifact_format: EdifactFormat, output_dir: Path) -> None: |
im Deutschen heißt es Nachrichtenformat oder EDIFACT-Format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/migmose/parsing.py
Outdated
if not output_dir.exists(): | ||
output_dir.mkdir(parents=True, exist_ok=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
das kannst du vereinfachen
if not output_dir.exists(): | |
output_dir.mkdir(parents=True, exist_ok=True) | |
output_dir.mkdir(parents=True, exist_ok=True) |
das exist_ok
hilft dir genau dabei.
will not raise an exception if the directory already exists (exist_ok=True)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/migmose/parsing.py
Outdated
raise click.Abort() | ||
|
||
|
||
def preliminary_output_as_json(table: list[str], message_type: EdifactFormat, output_dir: Path) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wieso ist die table
nur vom typ list[str]
?
Hätte gedacht dass es eins von unseren Klassen ist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hier ist das wirklich nur ein einfaches Outputframework. Die klassenspezifischen Methoden kommen später. :-)
|
||
def parse_raw_nachrichtenstrukturzeile(input_path: Path) -> list[str]: | ||
""" | ||
parses raw nachrichtenstrukturzeile from a table. returns list of raw lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parses raw nachrichtenstrukturzeile from a table. returns list of raw lines | |
Parses raw nachrichtenstrukturzeile from a table. Returns list of raw lines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unittests/test_parsing.py
Outdated
def test_find_file_to_type(self): | ||
message_type = [EdifactFormat.ORDCHG] | ||
input_dir = Path("unittests/test_data/") | ||
file_dict = find_file_to_type(message_type, input_dir) | ||
assert file_dict[EdifactFormat.ORDCHG] == input_dir / Path("ORDCHG_MIG_1_1_info_20230331_v2.docx") | ||
|
||
def test_find_only_one_file(self, caplog): | ||
message_type = [EdifactFormat.ORDCHG, EdifactFormat.ORDRSP] | ||
input_dir = Path("unittests/test_data/") | ||
with caplog.at_level(logging.WARNING): | ||
file_dict = find_file_to_type(message_type, input_dir) | ||
assert f"No file found for {EdifactFormat.ORDRSP}." in caplog.text | ||
assert file_dict[EdifactFormat.ORDCHG] == input_dir / Path("ORDCHG_MIG_1_1_info_20230331_v2.docx") | ||
|
||
def test_parse_raw_nachrichtenstrukturzeile(self): | ||
|
||
input_file = Path("unittests/test_data/ORDCHG_MIG_1_1_info_20230331_v2.docx") | ||
mig_table = parse_raw_nachrichtenstrukturzeile(input_file) | ||
assert len(mig_table) == 18 | ||
assert "Nachrichten-Kopfsegment" in mig_table[0] | ||
assert "Nachrichten-Endesegment" in mig_table[-1] | ||
|
||
def test_preliminary_output_as_json(self, tmp_path): | ||
table = ["line1", "line2", "line3"] | ||
message_type = EdifactFormat.ORDCHG | ||
output_dir = tmp_path / Path("output") | ||
|
||
preliminary_output_as_json(table, message_type, output_dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kannst du den tests noch einen docstring verpassen damit man grob weiß was getestet wird?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.