From 72d84c7d033d71bd36885eb474f7c17b484eab42 Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 14:37:07 +0100 Subject: [PATCH 1/7] add functional tests for factgenie list command Testing listing of dataset (inputs) campaigns and skipping testing for outputs On fresh factgenie copy it tests just there the commands produce empty list --- tests/test_cli_commands.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/test_cli_commands.py diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py new file mode 100644 index 00000000..df4a3b77 --- /dev/null +++ b/tests/test_cli_commands.py @@ -0,0 +1,68 @@ +""" +Run cli commands which wrap high level functionalites as a kind of functional tests. +""" + +from pathlib import Path +import subprocess +import logging + +from factgenie import INPUT_DIR, OUTPUT_DIR, CAMPAIGN_DIR + + +def test_factgenie_help(): + cmd = "factgenie --help" + result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + logging.debug(f"RUNNING ${cmd}\n{result.stdout.decode()}") + assert result.returncode == 0 + assert b"Usage: factgenie [OPTIONS] COMMAND [ARGS]..." in result.stdout + + +def test_factgenie_routes(): + """Routes list endpoints to be called with GET, POST, PUT, DELETE methods""" + cmd = "factgenie routes" + result = subprocess.run(cmd, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + assert result.returncode == 0 + + +# TODO by default there are no datasets in empty fatgenie data/input directory +# download some and create and test download command by that +def test_factgenie_list_datasets(): + """List datasets defined as inputs in factgenie.INPUT_DIR + factgenie.INPUTDIR is factgenie/data/input""" + assert Path(INPUT_DIR).exists() + assert "factgenie/data/input" in str(INPUT_DIR), f"INPUT_DIR: {INPUT_DIR}" + cmd = "factgenie list datasets" + result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + logging.debug(f"RUNNING ${cmd}\n{result.stdout.decode()}") + assert result.returncode == 0 + cli_datasets = sorted([d.strip() for d in result.stdout.decode().split("\n") if len(d.strip()) > 0]) + dir_datasets = sorted([d.name for d in Path(INPUT_DIR).iterdir() if d.is_dir()]) + logging.debug(f"CLI: {cli_datasets}") + logging.debug(f"DIR: {dir_datasets}") + assert cli_datasets == dir_datasets + + +def test_factgenie_list_outputs(): + assert Path(OUTPUT_DIR).exists() + # Skipping the rest of the logic for now. Parsing factgenie list outputs is fragile. + + +def test_factgenie_list_campaigns(): + """List campaigns defined as inputs in factgenie.CAMPAIGN_DIR + factgenie.CAMPAIGN_DIR is factgenie/data/campaigns""" + assert Path(CAMPAIGN_DIR).exists() + assert "factgenie/campaigns" in str(CAMPAIGN_DIR), f"CAMPAIGN_DIR: {CAMPAIGN_DIR}" + cmd = "factgenie list campaigns" + result = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + logging.debug(f"RUNNING ${cmd}\n{result.stdout.decode()}") + assert result.returncode == 0 + cli_campaigns = sorted([d.strip() for d in result.stdout.decode().split("\n") if len(d.strip()) > 0]) + dir_campaigns = sorted([d.name for d in Path(CAMPAIGN_DIR).iterdir() if d.is_dir()]) + logging.debug(f"CLI: {cli_campaigns}") + logging.debug(f"DIR: {dir_campaigns}") + assert cli_campaigns == dir_campaigns + + +if __name__ == "__main__": + # test_factgenie_list_datasets() + pass From 11cce6184a8a228e59d698125072bdcb148faecc Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 14:57:09 +0100 Subject: [PATCH 2/7] add expected structure to the repo using gitignore files for cacmpaigns and data/{inputs,outputs} --- factgenie/campaigns/.gitignore | 1 + factgenie/data/inputs/.gitignore | 1 + factgenie/data/outputs/.gitignore | 1 + 3 files changed, 3 insertions(+) create mode 100644 factgenie/campaigns/.gitignore create mode 100644 factgenie/data/inputs/.gitignore create mode 100644 factgenie/data/outputs/.gitignore diff --git a/factgenie/campaigns/.gitignore b/factgenie/campaigns/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/factgenie/campaigns/.gitignore @@ -0,0 +1 @@ +* diff --git a/factgenie/data/inputs/.gitignore b/factgenie/data/inputs/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/factgenie/data/inputs/.gitignore @@ -0,0 +1 @@ +* diff --git a/factgenie/data/outputs/.gitignore b/factgenie/data/outputs/.gitignore new file mode 100644 index 00000000..72e8ffc0 --- /dev/null +++ b/factgenie/data/outputs/.gitignore @@ -0,0 +1 @@ +* From f42431a8ec240cc95ba458f8abde67f2d680e4a7 Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 14:58:17 +0100 Subject: [PATCH 3/7] Shorten the name of black CI --- .github/workflows/black_check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/black_check.yml b/.github/workflows/black_check.yml index d7ba4f7b..b08e4625 100644 --- a/.github/workflows/black_check.yml +++ b/.github/workflows/black_check.yml @@ -1,4 +1,4 @@ -name: Black Check +name: Black on: push: @@ -23,4 +23,4 @@ jobs: pip install black==24.10.0 - name: Run Black run: | - black --check . --line-length 120 \ No newline at end of file + black --check . --line-length 120 From d00e151a9be1dbea48261b1f49e4327b23e7f7b2 Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 15:00:33 +0100 Subject: [PATCH 4/7] use pip install -e .[tests] in CI the same as recommended in README --- .github/workflows/py311_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/py311_tests.yml b/.github/workflows/py311_tests.yml index 35871146..7e186b22 100644 --- a/.github/workflows/py311_tests.yml +++ b/.github/workflows/py311_tests.yml @@ -20,7 +20,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install .[test] + pip install -e .[test] - name: Run tests run: | pytest From 78e11157b34d5488e3a5b249068ba4af32c271e3 Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 15:09:23 +0100 Subject: [PATCH 5/7] setup config before tests --- tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..7c402e10 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,10 @@ +# conftest.py +import pytest +import shutil +from factgenie import MAIN_CONFIG_PATH + +@pytest.fixture(scope="module", autouse=True) +def prepare_testing_config(): + # copy config_TEMPLATE.yml to config.yml + shutil.copy(MAIN_CONFIG_PATH.with_name("config_TEMPLATE.yml"), MAIN_CONFIG_PATH) + assert MAIN_CONFIG_PATH.exists() \ No newline at end of file From c181638e12d896e5771a3ba46545693f06ebbbdb Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 15:13:10 +0100 Subject: [PATCH 6/7] fix permission and black --- factgenie/datasets/basic.py | 0 factgenie/datasets/dataset.py | 0 factgenie/datasets/rotowire_shared_task.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 factgenie/datasets/basic.py mode change 100755 => 100644 factgenie/datasets/dataset.py mode change 100755 => 100644 factgenie/datasets/rotowire_shared_task.py diff --git a/factgenie/datasets/basic.py b/factgenie/datasets/basic.py old mode 100755 new mode 100644 diff --git a/factgenie/datasets/dataset.py b/factgenie/datasets/dataset.py old mode 100755 new mode 100644 diff --git a/factgenie/datasets/rotowire_shared_task.py b/factgenie/datasets/rotowire_shared_task.py old mode 100755 new mode 100644 From bb3e4936c5063c68e8e4ab40b5bbba0b2fb36726 Mon Sep 17 00:00:00 2001 From: Ondrej Platek Date: Wed, 6 Nov 2024 15:16:48 +0100 Subject: [PATCH 7/7] fix black for conftest.py --- tests/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 7c402e10..1bfd81f3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,8 +3,9 @@ import shutil from factgenie import MAIN_CONFIG_PATH + @pytest.fixture(scope="module", autouse=True) def prepare_testing_config(): # copy config_TEMPLATE.yml to config.yml shutil.copy(MAIN_CONFIG_PATH.with_name("config_TEMPLATE.yml"), MAIN_CONFIG_PATH) - assert MAIN_CONFIG_PATH.exists() \ No newline at end of file + assert MAIN_CONFIG_PATH.exists()