From 0419e50cc1c921b4427499b400f4c60ed0fa5b15 Mon Sep 17 00:00:00 2001 From: lb584 <lb584@cam.ac.uk> Date: Mon, 20 Mar 2023 15:21:27 +0000 Subject: [PATCH] restructuring the advisory test to get ready for a full-fat implementation --- tests/integration/partial/test_advisory.py | 80 +++++-------------- .../test_suites/advisory_test_suite.py | 67 ++++++++++++++++ 2 files changed, 89 insertions(+), 58 deletions(-) create mode 100644 tests/integration/test_suites/advisory_test_suite.py diff --git a/tests/integration/partial/test_advisory.py b/tests/integration/partial/test_advisory.py index 807d6c1..417ff2d 100644 --- a/tests/integration/partial/test_advisory.py +++ b/tests/integration/partial/test_advisory.py @@ -1,36 +1,43 @@ import copy -import glob import os import unittest from integration.partial.integration_test_utils import IntegrationTestUtils +from integration.test_suites.advisory_test_suite import BaseAdvisoryTestSuite -class TestAdvisory(unittest.TestCase): +class TestAdvisory(BaseAdvisoryTestSuite.AdvisoryTestSuite): - TEST_OUT_PATH: str = "not_set" - TEST_START_DATE: str = '20221001' - TEST_JOB_DIR: str = "ADVISORY_" + TEST_START_DATE + def set_expected_values(self): + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_START_DATE = '20221001' + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR = "ADVISORY_" + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_START_DATE - @classmethod - def setUpClass(cls) -> None: - TestAdvisory.write_temp_run_config_files() - TestAdvisory.unpack_dependencies() - TestAdvisory.run_advisory_pipeline() + + def setUp(self) -> None: + + self.set_expected_values() + + if BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH is None or not os.path.isdir(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH): + TestAdvisory.write_temp_run_config_files() + TestAdvisory.unpack_dependencies() + TestAdvisory.run_advisory_pipeline() + else: + print(f"output in {BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH} already written, skipping rerun") @staticmethod def write_temp_run_config_files(): nowstring: str = IntegrationTestUtils.get_now_string() - prefix: str = "temp_advisory_" + nowstring - # prefix: str = "" + # prefix: str = "temp_advisory_" + nowstring + prefix: str = "temp_advisory" default_config = IntegrationTestUtils.DEFAULT_CONFIG_FILE_PATH default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config) run_dict: dict = copy.deepcopy(default_config_dict) - TestAdvisory.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep - run_dict['WorkspacePathout'] = TestAdvisory.TEST_OUT_PATH - run_dict['WorkspacePath'] = TestAdvisory.TEST_OUT_PATH + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH = IntegrationTestUtils.TEST_WORKSPACE_PATH + prefix + os.sep + # TestAdvisory.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep + run_dict['WorkspacePathout'] = BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH + run_dict['WorkspacePath'] = BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH run_dict['ServerName'] = '' # nothing, as local machine IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_NAME) @@ -49,48 +56,5 @@ class TestAdvisory(unittest.TestCase): IntegrationTestUtils.run_unittest_pipeline(component, TestAdvisory.TEST_START_DATE) - def test_standard_run_input_status_success(self): - status_file_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, "STATUS_SUCCESS") - success_file_exists: bool = os.path.isfile(status_file_path) - self.assertTrue(success_file_exists) - - def test_standard_run_input_all_docs_produced(self): - - east_africa_image_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, - "tight-layout", - "wheat_rust_advisory_template_EastAfrica_20221001.docx") - ethiopia_image_path = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, - "tight-layout", - "wheat_rust_advisory_template_Ethiopia_20221001.docx") - - ea_file_exists: bool = os.path.isfile(east_africa_image_path) - eth_file_exists: bool = os.path.isfile(ethiopia_image_path) - self.assertTrue(ea_file_exists) - self.assertTrue(eth_file_exists) - - def test_standard_run_input_images_produced(self): - - east_africa_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, - "images", - "*eastafrica*.png") - ethiopia_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, - "images", - "*ethiopia*.png") - - africa_image_count: int = len(glob.glob(east_africa_image_wildcard)) - ethiopia_image_count: int = len(glob.glob(ethiopia_image_wildcard)) - self.assertEqual(3, africa_image_count) - self.assertEqual(3, ethiopia_image_count) - - def test_standard_run_input_shapefiles_produced(self): - - east_africa_image_wildcard = os.path.join(TestAdvisory.TEST_OUT_PATH, TestAdvisory.TEST_JOB_DIR, - "images", - "*eastafrica*.shp") - - africa_image_count: int = len(glob.glob(east_africa_image_wildcard)) - self.assertEqual(3, africa_image_count) - - if __name__ == '__main__': unittest.main() diff --git a/tests/integration/test_suites/advisory_test_suite.py b/tests/integration/test_suites/advisory_test_suite.py new file mode 100644 index 0000000..6a9f4dd --- /dev/null +++ b/tests/integration/test_suites/advisory_test_suite.py @@ -0,0 +1,67 @@ +import abc +import glob +import os +import unittest + +from integration.partial.integration_test_utils import IntegrationTestUtils + + +class BaseAdvisoryTestSuite: + + class AdvisoryTestSuite(unittest.TestCase): + + TEST_OUT_PATH: str = None + TEST_START_DATE: str = None + TEST_JOB_DIR: str = None + + @abc.abstractmethod + def set_expected_values(self): + pass + + + def test_standard_run_input_status_success(self): + status_file_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, "STATUS_SUCCESS") + success_file_exists: bool = os.path.isfile(status_file_path) + self.assertTrue(success_file_exists) + + + def test_standard_run_input_all_docs_produced(self): + east_africa_image_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, + "tight-layout", + "wheat_rust_advisory_template_EastAfrica_20221001.docx") + ethiopia_image_path = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, + "tight-layout", + "wheat_rust_advisory_template_Ethiopia_20221001.docx") + + ea_file_exists: bool = os.path.isfile(east_africa_image_path) + eth_file_exists: bool = os.path.isfile(ethiopia_image_path) + self.assertTrue(ea_file_exists) + self.assertTrue(eth_file_exists) + + + def test_standard_run_input_images_produced(self): + east_africa_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, + "images", + "*eastafrica*.png") + ethiopia_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, + "images", + "*ethiopia*.png") + + africa_image_count: int = len(glob.glob(east_africa_image_wildcard)) + ethiopia_image_count: int = len(glob.glob(ethiopia_image_wildcard)) + self.assertEqual(3, africa_image_count) + self.assertEqual(3, ethiopia_image_count) + + + def test_standard_run_input_shapefiles_produced(self): + east_africa_image_wildcard = os.path.join(BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_OUT_PATH, + BaseAdvisoryTestSuite.AdvisoryTestSuite.TEST_JOB_DIR, + "images", + "*eastafrica*.shp") + + africa_image_count: int = len(glob.glob(east_africa_image_wildcard)) + self.assertEqual(3, africa_image_count) \ No newline at end of file -- GitLab