diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2021-01-17 16:37:27 +0000 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2021-01-17 16:37:27 +0000 |
commit | 1c366183fc1dd880363956cc17a6d6159cecbd05 (patch) | |
tree | d2b945df2516d0ea9d6840102d53ef6110c47508 /datamaps | |
parent | 82c8be2d89a1359c271bccc889986272fcb40d02 (diff) |
added flag to change input directory for import templates command
Diffstat (limited to 'datamaps')
-rw-r--r-- | datamaps/main.py | 5 | ||||
-rw-r--r-- | datamaps/tests/conftest.py | 8 | ||||
-rw-r--r-- | datamaps/tests/test_cli.py | 24 |
3 files changed, 35 insertions, 2 deletions
diff --git a/datamaps/main.py b/datamaps/main.py index 7b7c670..1bde2a6 100644 --- a/datamaps/main.py +++ b/datamaps/main.py @@ -143,7 +143,8 @@ def show_file(): help="Set row limit to prevent spurious Excel files with hidden rows being processed." "Default is 500.", ) -def templates(to_master, datamap, rowlimit): +@click.option("--inputdir", help="Path to input directory", metavar="INPUT_DIRECTORY_PATH") +def templates(to_master, datamap, rowlimit, inputdir): """Import data to a master file from a collection of populated templates. BASICS @@ -171,7 +172,7 @@ def templates(to_master, datamap, rowlimit): if to_master: try: engine_cli.import_and_create_master( - echo_funcs=output_funcs, datamap=datamap, rowlimit=rowlimit + echo_funcs=output_funcs, datamap=datamap, rowlimit=rowlimit, inputdir=inputdir ) except MalFormedCSVHeaderException as e: click.echo( diff --git a/datamaps/tests/conftest.py b/datamaps/tests/conftest.py index aa59301..4faed8c 100644 --- a/datamaps/tests/conftest.py +++ b/datamaps/tests/conftest.py @@ -1,5 +1,7 @@ import os import shutil +import tempfile + from pathlib import Path import pytest @@ -13,6 +15,12 @@ def master() -> Path: @pytest.fixture +def temp_input_dir() -> Path: + pth = tempfile.mkdtemp() + yield pth + + +@pytest.fixture def mock_config(monkeypatch): monkeypatch.setattr(Config, "PLATFORM_DOCS_DIR", Path("/tmp/Documents/datamaps")) monkeypatch.setattr( diff --git a/datamaps/tests/test_cli.py b/datamaps/tests/test_cli.py index aef977c..a3a832f 100644 --- a/datamaps/tests/test_cli.py +++ b/datamaps/tests/test_cli.py @@ -20,6 +20,30 @@ def _copy_resources_to_input(config, directory): ) +def test_import_from_user_defined_source_dir( + mock_config, resource_dir, caplog, temp_input_dir +): + runner = CliRunner() + mock_config.initialise() + caplog.set_level(logging.INFO) + for fl in os.listdir(resource_dir): + shutil.copy( + Path.cwd() / "datamaps" / "tests" / "resources" / fl, temp_input_dir + ) + result = runner.invoke(_import, ["templates", "-m", "--inputdir", temp_input_dir]) + assert result.exit_code == 0 + output = [x[2] for x in caplog.record_tuples] + found = False + for o in output: + if f"Reading datamap {temp_input_dir}/" in o: + found = True + break + if found: + assert True + else: + assert False, "Cannot find correct string" + + @pytest.mark.parametrize( "rowlimit,expected,exit_code", [ |