FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 5eb92fe3 authored by L. Bower's avatar L. Bower
Browse files

adding first proper asserts to depo test

parent 6e99174f
No related branches found
No related tags found
No related merge requests found
import glob
import json
from datetime import datetime
from zipfile import ZipFile
......@@ -5,6 +6,7 @@ from zipfile import ZipFile
class IntegrationTestUtils:
DEFAULT_CONFIG_FILE_PATH: str = "../test_data/test_deployment/regions/EastAfrica/resources/coordinator/configs/config_EastAfrica_fc_live.json"
TEMP_CONFIG_FILE_PATH: str = "../test_data/test_deployment/regions/EastAfrica/workspace/temp_config.json"
EXAMPLE_SURVEY_FILE_PATH: str = "../test_data/test_deployment/regions/EastAfrica/resources/coordinator/assets/example_survey_run.zip"
EXAMPLE_DEPO_FILE_PATH: str = "../test_data/test_deployment/regions/EastAfrica/resources/coordinator/assets/example_depo_run.zip"
......@@ -34,3 +36,8 @@ class IntegrationTestUtils:
with ZipFile(zip_to_unpack) as zf: # open the zip file
for target_file in zf.namelist(): # check if the file exists in the archive
zf.extract(target_file, out_file)
@staticmethod
def count_files_in_wildcard(wildcard: str) -> int:
results = glob.glob(wildcard)
return len(results)
......@@ -6,42 +6,101 @@ from integration.integration_test_utils import IntegrationTestUtils
class TestDeposition(unittest.TestCase):
TEST_OUT_PATH: str = "not_set"
TEST_RUN_DATE: str = '20221001'
TEST_JOB_DIR: str = "DEPOSITION_" + 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)
i = 0
def test_depo_standard_inputs_expected_results1(self):
@classmethod
def setUpClass(cls) -> None:
TestDeposition.write_temp_run_config_file()
TestDeposition.run_depo_pipelines()
@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)
TestDeposition.TEST_OUT_PATH = run_dict['WorkspacePathout'] + prefix + os.sep
run_dict['WorkspacePathout'] = TestDeposition.TEST_OUT_PATH
run_dict['WorkspacePath'] = TestDeposition.TEST_OUT_PATH
run_dict['ServerName'] = '' # nothing, as local machine
full_server_path = os.path.abspath("../test_data/met_office/depo/")
run_dict['Deposition']['ServerPathTemplate'] = full_server_path
IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH)
@staticmethod
def run_depo_pipelines():
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]
args_dict['log_level'] = 'error'
args_dict['live'] = False
args_dict['start_date'] = '20221001'
args_dict['start_date'] = TestDeposition.TEST_RUN_DATE
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_depo_" + nowstring + os.sep
run_dict['WorkspacePathout'] = test_out_path
run_dict['WorkspacePath'] = test_out_path
run_dict['ServerName'] = '' # nothing, as local machine
full_server_path = os.path.abspath("../test_data/met_office/depo/")
run_dict['Deposition']['ServerPathTemplate'] = full_server_path
run_Process(args_dict)
# run_dict['SubRegionNames'].remove('Kenya')
# run_dict['Deposition']['EWS-Plotting'].pop('Kenya', None)
IntegrationTestUtils.write_json_file(run_dict, IntegrationTestUtils.TEMP_CONFIG_FILE_PATH)
run_Process(args_dict)
self.assertTrue(True)
def test_standard_run_input_status_success(self):
status_file_path = os.path.join(TestDeposition.TEST_OUT_PATH, TestDeposition.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_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(TestDeposition.TEST_OUT_PATH, TestDeposition.TEST_JOB_DIR,
"plotting", "eastafrica", "images", "Weekly",
"deposition_eastafrica_leaf_rust_total_202210010000_202210080000_map.png")
ethiopia_image_path = os.path.join(TestDeposition.TEST_OUT_PATH, TestDeposition.TEST_JOB_DIR,
"plotting", "ethiopia", "images", "Weekly",
"deposition_ethiopia_leaf_rust_total_202210010000_202210080000_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(TestDeposition.TEST_OUT_PATH, TestDeposition.TEST_JOB_DIR,
"plotting", "eastafrica", "input_csvs", "*.csv")
ethiopia_csv_path = os.path.join(TestDeposition.TEST_OUT_PATH, TestDeposition.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(9, ea_csv_count)
self.assertEqual(27, eth_csv_count)
def test_standard_run_all_images_produced(self):
east_africa_image_path = os.path.join(TestDeposition.TEST_OUT_PATH, TestDeposition.TEST_JOB_DIR,
"plotting", "eastafrica", "images", "Weekly", "*.png")
ethiopia_image_path = os.path.join(TestDeposition.TEST_OUT_PATH, TestDeposition.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(3, ea_csv_count)
self.assertEqual(6, eth_csv_count)
if __name__ == '__main__':
......
......@@ -4,7 +4,7 @@
"StartTime" : "?",
"StartString" : "?",
"WorkspacePathout" : "../test_data/test_deployment/regions/EastAfrica/workspace/",
"WorkspacePath" : "../test_data/test_deployment/regions/EastAfrica/workspace/",
"WorkspacePath" : "set_in_the_code",
"ResourcesPath" : "../test_data/test_deployment/regions/EastAfrica/resources/",
"ServerPath" : "/storage/moved/Ethiopia/",
"ServerName" : "ewsmanager@willow.csx.cam.ac.uk",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment