Skip to content

Commit

Permalink
feat(test): add test_config param to a2t2f-news run
Browse files Browse the repository at this point in the history
  • Loading branch information
spool committed Jul 31, 2023
1 parent 7640333 commit 00fe523
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
49 changes: 28 additions & 21 deletions alto2txt2fixture/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
__main__), the ``run`` function is executed.
"""

from argparse import ArgumentParser
from argparse import ArgumentParser, BooleanOptionalAction

from alto2txt2fixture.parser import parse
from alto2txt2fixture.router import route
Expand Down Expand Up @@ -54,10 +54,17 @@ def parse_args(argv=None):
help="<Optional> Set an output directory",
required=False,
)
parser.add_argument(
"-t",
"--test-config",
default=False,
help="Only print the configuration",
action=BooleanOptionalAction,
)
return parser.parse_args(argv)


def run() -> None:
def run(test_config: bool = False) -> None:
"""
The run function is the main function that starts the alto2txt2fixture
process.
Expand Down Expand Up @@ -105,25 +112,25 @@ def run() -> None:
REPORT_DIR=settings.REPORT_DIR,
MAX_ELEMENTS_PER_FILE=settings.MAX_ELEMENTS_PER_FILE,
)

# Routing alto2txt into subdirectories with structured files
route(
COLLECTIONS,
settings.CACHE_HOME,
MOUNTPOINT,
settings.JISC_PAPERS_CSV,
settings.REPORT_DIR,
)

# Parsing the resulting JSON files
parse(
COLLECTIONS,
settings.CACHE_HOME,
OUTPUT,
settings.MAX_ELEMENTS_PER_FILE,
)

clear_cache(settings.CACHE_HOME)
if not args.test_config and not test_config:
# Routing alto2txt into subdirectories with structured files
route(
COLLECTIONS,
settings.CACHE_HOME,
MOUNTPOINT,
settings.JISC_PAPERS_CSV,
settings.REPORT_DIR,
)

# Parsing the resulting JSON files
parse(
COLLECTIONS,
settings.CACHE_HOME,
OUTPUT,
settings.MAX_ELEMENTS_PER_FILE,
)

clear_cache(settings.CACHE_HOME)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions alto2txt2fixture/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ class DataProvider(Cache):
Examples:
```pycon
>>> from pprint import pprint
>>> hmd = DataProvider("hmd")
>>> hmd.pk
2
Expand Down
7 changes: 7 additions & 0 deletions tests/test_newspaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
from alto2txt2fixture.__main__ import run


def test_newspaper_test_config(capsys) -> None:
"""Test using `test_config` to only print out run config."""
collections_config = "│ COLLECTIONS │ ['hmd', 'lwm', 'jisc', 'bna'] │"
run(test_config=True)
assert collections_config in capsys.readouterr().out


def test_run_without_local_or_blobfuse(capsys, uncached_folder) -> None:
"""Test error mesages from `alto2txt2fixture.run` cli.
Expand Down

0 comments on commit 00fe523

Please sign in to comment.