diff --git a/tests/integration/.coveragerc b/tests/integration/.coveragerc index cb89d0a396759867d7068ece466e87f38c533d67..33547c0d9870880802d0f2af4ecde7efd71d26d9 100644 --- a/tests/integration/.coveragerc +++ b/tests/integration/.coveragerc @@ -2,5 +2,4 @@ exclude_lines = if __name__ == .__main__.: omit = - */Processor.py */__init__.py \ No newline at end of file diff --git a/tests/integration/test_deposition.py b/tests/integration/test_deposition.py index 36a2ef190bb87ee9c19f7fad7a67f6835f8c699e..6316839a9dc291ac9077287676e642c79f86719c 100644 --- a/tests/integration/test_deposition.py +++ b/tests/integration/test_deposition.py @@ -14,7 +14,7 @@ class TestDeposition(unittest.TestCase): @classmethod def setUpClass(cls) -> None: TestDeposition.write_temp_run_config_file() - TestDeposition.run_depo_pipelines() + TestDeposition.run_depo_pipeline() @staticmethod @@ -37,11 +37,11 @@ class TestDeposition(unittest.TestCase): @staticmethod - def run_depo_pipelines(): + def run_depo_pipeline(): + os.environ["EMAIL_CRED"] = "../test_data/test_deployment/envs/Cred_gmail.json" from Processor import run_Process, set_log_level - args_dict: dict = {} args_dict['component'] = 'Deposition' args_dict['config_paths'] = [IntegrationTestUtils.TEMP_CONFIG_FILE_PATH] diff --git a/tests/integration/test_env_suit.py b/tests/integration/test_env_suit.py index 0596d6e5dd628c5b5ca8ecaf7d237aef7b8cc909..d2dbd553d2a4e7ade8892f3c0dd5ba7c8fae6543 100644 --- a/tests/integration/test_env_suit.py +++ b/tests/integration/test_env_suit.py @@ -6,18 +6,45 @@ from integration.integration_test_utils import IntegrationTestUtils class TestEnvSuit(unittest.TestCase): + TEST_OUT_PATH: str = "not_set" + TEST_RUN_DATE: str = '20221001' + TEST_JOB_DIR: str = "ENVIRONMENT_2.0_" + TEST_RUN_DATE - def setUp(self) -> None: - super().setUp() - default_config = '../test_data/test_deployment/regions/EastAfrica/resources/coordinator/configs/config_EastAfrica_fc_live.json' - self.default_config_dict: dict = IntegrationTestUtils.load_json_file(default_config) - def test_env_suit_standard_inputs_expected_results1(self): + @classmethod + def setUpClass(cls) -> None: + TestEnvSuit.write_temp_run_config_file() + # TestEnvSuit.run_env_pipeline() + + @staticmethod + def write_temp_run_config_file(): nowstring: str = IntegrationTestUtils.get_now_string() + prefix: str = "temp_depo_" + nowstring + # prefix: str = "" + + 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) + TestEnvSuit.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep + run_dict['WorkspacePathout'] = TestEnvSuit.TEST_OUT_PATH + run_dict['WorkspacePath'] = TestEnvSuit.TEST_OUT_PATH + run_dict['Environment']['WORK_PATH'] = TestEnvSuit.TEST_OUT_PATH + run_dict['Environment']['INPUT_PATH'] = TestEnvSuit.TEST_OUT_PATH + run_dict['Environment']['OUTPUT_PATH'] = TestEnvSuit.TEST_OUT_PATH + run_dict['ServerName'] = '' # nothing, as local machine + full_server_path = os.path.abspath("../test_data/met_office/env_suit/") + run_dict['Environment']['ServerPathTemplate'] = full_server_path + + IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH) + + @staticmethod + def run_env_pipeline(): os.environ["EMAIL_CRED"] = "../test_data/test_deployment/envs/Cred_gmail.json" from Processor import run_Process, set_log_level + + args_dict: dict = {} args_dict['component'] = 'Environment' args_dict['config_paths'] = [IntegrationTestUtils.TEMP_CONFIG_FILE_PATH] @@ -27,23 +54,56 @@ class TestEnvSuit(unittest.TestCase): args_dict['noupload'] = True set_log_level(args_dict['log_level']) - run_dict: dict = copy.deepcopy(self.default_config_dict) - test_out_path = run_dict['WorkspacePathout'] + "temp_env_" + nowstring + os.sep - run_dict['WorkspacePathout'] = test_out_path - run_dict['WorkspacePath'] = test_out_path - run_dict['Environment']['WORK_PATH'] = test_out_path - run_dict['Environment']['INPUT_PATH'] = test_out_path - run_dict['Environment']['OUTPUT_PATH'] = test_out_path - run_dict['ServerName'] = '' # nothing, as local machine - full_server_path = os.path.abspath("../test_data/met_office/env_suit/") - run_dict['Environment']['ServerPathTemplate'] = full_server_path + run_Process(args_dict) - # run_dict['SubRegionNames'].remove('Kenya') - IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH) + def test_standard_run_input_status_success(self): + status_file_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, "STATUS_SUCCESS") + success_file_exists: bool = os.path.isfile(status_file_path) + self.assertTrue(success_file_exists) - run_Process(args_dict) - self.assertTrue(True) + + def test_standard_run_input_all_regions_ran(self): + """ + working on the assumption that if there are images for each region, it must have run through + (at least past the region iteration) + """ + + east_africa_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "eastafrica", "images", "Weekly", + "suitability_eastafrica_leaf_rust_total_202210010000_202210070000_map.png") + ethiopia_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "ethiopia", "images", "Weekly", + "suitability_ethiopia_leaf_rust_total_202210010000_202210070000_map.png") + + 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_all_input_csvs_produced(self): + east_africa_csv_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "eastafrica", "input_csvs", "*.csv") + ethiopia_csv_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "ethiopia", "input_csvs", "*.csv") + + ea_csv_count: int = IntegrationTestUtils.count_files_in_wildcard(east_africa_csv_path) + eth_csv_count: int = IntegrationTestUtils.count_files_in_wildcard(ethiopia_csv_path) + self.assertEqual(18, ea_csv_count) + self.assertEqual(18, eth_csv_count) + + + def test_standard_run_all_images_produced(self): + east_africa_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "eastafrica", "images", "Weekly", "*.png") + ethiopia_image_path = os.path.join(TestEnvSuit.TEST_OUT_PATH, TestEnvSuit.TEST_JOB_DIR, + "plotting", "ethiopia", "images", "Weekly", "*.png") + + ea_csv_count: int = IntegrationTestUtils.count_files_in_wildcard(east_africa_image_path) + eth_csv_count: int = IntegrationTestUtils.count_files_in_wildcard(ethiopia_image_path) + self.assertEqual(6, ea_csv_count) + self.assertEqual(6, eth_csv_count) if __name__ == '__main__':