Skip to content

Commit

Permalink
Merge pull request #517 from flairNLP/remove-previous-files-in-test-c…
Browse files Browse the repository at this point in the history
…ase-script

Remove previous file when using `-o` option in test case script
  • Loading branch information
MaxDall authored May 16, 2024
2 parents e79e728 + 4dda3fb commit cd75d00
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion scripts/generate_parser_test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main() -> None:
test_data = content if not arguments.overwrite_json and (content := test_data_file.load()) else {}

# load html
html_mapping = load_html_test_file_mapping(publisher) if not arguments.overwrite else {}
html_mapping = load_html_test_file_mapping(publisher)

if arguments.overwrite or not html_mapping.get(publisher.parser.latest_version):
if not (article := get_test_article(publisher, url)):
Expand All @@ -120,6 +120,10 @@ def main() -> None:
html.write()
subprocess.call(["git", "add", html.path], stdout=subprocess.PIPE)

# remove previous file
if previous_file := html_mapping.get(publisher.parser.latest_version):
previous_file.remove()

html_mapping[publisher.parser.latest_version] = html
test_data[publisher.parser.latest_version.__name__] = {}

Expand Down
10 changes: 10 additions & 0 deletions tests/utility.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import gzip
import json
import os
import subprocess
from dataclasses import dataclass
from pathlib import Path
Expand Down Expand Up @@ -202,6 +203,15 @@ def load(cls, path: Path, encoding: str = "utf-8") -> Self:
raise ValueError(f"Missing meta info for file {path.name!r}")
return cls(content=content, publisher=publisher, encoding=encoding, **meta_info[path.name])

def remove(self) -> None:
if meta_info_file := get_meta_info_file(self.publisher):
meta_info = meta_info_file.load() or {}
meta_info.pop(self.path.name)
meta_info_file.write(meta_info)

if self.path.exists():
os.remove(self.path)

def _register_at_meta_info(self) -> None:
"""Writes meta information about the file to the corresponding meta.info file.
Expand Down

0 comments on commit cd75d00

Please sign in to comment.