diff --git a/tests/integration/integration_test_utils.py b/tests/integration/integration_test_utils.py index 03a616b393bf770b168230ce14a0f3aaff197741..bf5e5e86f16eb4b0321968f3a4d0036fb9214f2d 100644 --- a/tests/integration/integration_test_utils.py +++ b/tests/integration/integration_test_utils.py @@ -2,6 +2,7 @@ import glob import json import os from datetime import datetime +from typing import List from zipfile import ZipFile @@ -46,9 +47,32 @@ class IntegrationTestUtils: @staticmethod - def check_file_not_empty(file_path: str): + def check_file_not_empty(file_path: str) -> bool: return os.stat(file_path).st_size != 0 + @staticmethod + def check_file_exists(file_path: str) -> bool: + return os.path.isfile(file_path) + + @staticmethod + def check_wildcard_exists_and_not_empty(wildcard: str) -> bool: + + """ + requires at least one file matching the wildcard to exist and not be empty + """ + result = False + files: List[str] = glob.glob(wildcard) + for file in files: + result = IntegrationTestUtils.check_file_not_empty(file) + if result is False: + break + return result + + @staticmethod + def check_file_exists_and_not_empty(file_path: str) -> bool: + file_exists = IntegrationTestUtils.check_file_exists(file_path) + file_not_empty = IntegrationTestUtils.check_file_not_empty(file_path) + return file_exists and file_not_empty @staticmethod def run_pipeline(component: str, diff --git a/tests/integration/test_epi.py b/tests/integration/test_epi.py index 18d406d9c5879288bd4f2cc864b5a10743efac48..58686e90e24418f1a5d9de9c4548b1b35196c450 100644 --- a/tests/integration/test_epi.py +++ b/tests/integration/test_epi.py @@ -9,19 +9,20 @@ class TestEpi(unittest.TestCase): TEST_OUT_PATH: str = "not_set" TEST_START_DATE: str = '20221001' - TEST_JOB_DIR: str = "SUMMARY_" + TEST_START_DATE + TEST_JOB_DIR: str = "EPI_" + TEST_START_DATE @classmethod def setUpClass(cls) -> None: TestEpi.write_temp_run_config_files() - TestEpi.unpack_dependencies() - TestEpi.run_advisory_pipeline() + # TestEpi.unpack_dependencies() + # TestEpi.run_epi_pipeline() @staticmethod def write_temp_run_config_files(): nowstring: str = IntegrationTestUtils.get_now_string() - prefix: str = "temp_epi_" + nowstring + # prefix: str = "temp_epi_" + nowstring + prefix: str = "temp_epi_2022-11-23_164339" # prefix: str = "" default_config = IntegrationTestUtils.DEFAULT_CONFIG_FILE_PATH @@ -43,7 +44,7 @@ class TestEpi(unittest.TestCase): @staticmethod - def run_advisory_pipeline(): + def run_epi_pipeline(): component = 'Epidemiology' IntegrationTestUtils.run_pipeline(component, TestEpi.TEST_START_DATE) @@ -53,19 +54,65 @@ class TestEpi(unittest.TestCase): success_file_exists: bool = os.path.isfile(status_file_path) self.assertTrue(success_file_exists) - def test_standard_run_input_all_docs_produced(self): + def test_standard_run_input_all_stem_rust_files_produced(self): - east_africa_image_path = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, - "tight-layout", - "wheat_rust_advisory_template_EastAfrica_20221001.docx") - ethiopia_image_path = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, - "tight-layout", - "wheat_rust_advisory_template_Ethiopia_20221001.docx") + alpha_beta_gamma_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "EastAfrica", + "StemRust", + "*psbeta0.004gamma0.00025alpha1.0") - 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) + self.check_wildcard_exists_and_not_empty(alpha_beta_gamma_root, ".csv") + self.check_wildcard_exists_and_not_empty(alpha_beta_gamma_root, "*comparison.png") + self.check_wildcard_exists_and_not_empty(alpha_beta_gamma_root, "*progression.csv") + self.check_wildcard_exists_and_not_empty(alpha_beta_gamma_root, ".png") + self.check_wildcard_exists_and_not_empty(alpha_beta_gamma_root, ".tif") + + env_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "EastAfrica", + "StemRust", + "infections_temp_config_Epidemiology") + + self.check_wildcard_exists_and_not_empty(env_root, "*env.csv") + self.check_wildcard_exists_and_not_empty(env_root, "*env.png") + self.check_wildcard_exists_and_not_empty(env_root, "*env.tif") + + data_input_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "EastAfrica", + "StemRust", + "input_data", + "data_input*") + + self.check_wildcard_exists_and_not_empty(data_input_root, "*deposition.csv") + self.check_wildcard_exists_and_not_empty(data_input_root, "*environment.csv") + + map_spam_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "EastAfrica", + "StemRust", + "input_data", + "wheat_area_frac_MapSPAM2010_EastAfrica*") + + self.check_wildcard_exists_and_not_empty(map_spam_root, ".csv") + self.check_wildcard_exists_and_not_empty(map_spam_root, ".csv") + + def test_standard_run_input_all_plotting_files_produced(self): + + input_csvs_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "plotting", + "input_csvs", + "*stem*") + + self.check_wildcard_exists_and_not_empty(input_csvs_root, ".csv") + + images_root = os.path.join(TestEpi.TEST_OUT_PATH, TestEpi.TEST_JOB_DIR, + "plotting", + "images", + "*stem*") + + self.check_wildcard_exists_and_not_empty(images_root, "png") + + def check_wildcard_exists_and_not_empty(self, root: str, extension: str): + file_exists: bool = IntegrationTestUtils.check_wildcard_exists_and_not_empty(root + extension) + self.assertTrue(file_exists) if __name__ == '__main__':