diff --git a/test/bar/test_bar.py b/test/bar/test_bar.py index 0cacf667..eb0c5fee 100644 --- a/test/bar/test_bar.py +++ b/test/bar/test_bar.py @@ -33,16 +33,15 @@ def setup_nones(remove_files, setup_env): bar.main(custom_config_filename) -@pytest.mark.parametrize("test_input, expected", - (["bar_expected.png", True], - ["bar.png", True], - ["bar.points1", True])) -def test_files_exist(setup, test_input, expected, remove_files): +def test_files_exist(setup, remove_files): """ Checking that the plot and data files are getting created """ - assert os.path.isfile(f"{cwd}/{test_input}") == expected - remove_files(cwd, CLEANUP_FILES) + check_files = ('bar.png', 'bar.points1') + for test_input in check_files: + print(f'Checking if {cwd}/{test_input} is found') + assert os.path.isfile(f"{cwd}/{test_input}") + remove_files(cwd, check_files) def test_no_nans_in_points_file(setup, remove_files): @@ -101,13 +100,11 @@ def test_none_data_images_match(setup_nones): pass -@pytest.mark.parametrize("test_input, expected", - (["bar_points1.png", True], - ["intermed_files/bar.points1", True])) -def test_point_and_plot_files_exist(setup_env, test_input, expected, remove_files): +def test_point_and_plot_files_exist(setup_env, remove_files): """ Checking that the plot and (specified location) intermediate file are getting created """ + check_files = ("bar_points1.png", "intermed_files/bar.points1") setup_env(cwd) custom_config_filename = f"{cwd}/custom_points1_bar.yaml" intermed_dir = os.path.join(cwd, 'intermed_files') @@ -120,16 +117,16 @@ def test_point_and_plot_files_exist(setup_env, test_input, expected, remove_file # the custom_bar.yaml custom config file. bar.main(custom_config_filename) - assert os.path.isfile(f"{cwd}/{test_input}") == expected - remove_files(cwd, ['bar_points1.png']) + for test_input in check_files: + assert os.path.isfile(f"{cwd}/{test_input}") + remove_files(cwd, check_files) -@pytest.mark.parametrize("test_input, expected", - (["bar_defaultpoints1.png", True], ["bar.points1", True])) -def test_point_and_plot_files_exist(setup_env, test_input, expected, remove_files): +def test_point_and_plot_files_exist_default(setup_env, remove_files): """ Checking that the plot and (specified location) intermediate file are getting created """ + check_files = ("bar_defaultpoints1.png", "bar.points1") setup_env(cwd) custom_config_filename = f"{cwd}/custom_defaultpoints1_bar.yaml" @@ -137,10 +134,11 @@ def test_point_and_plot_files_exist(setup_env, test_input, expected, remove_file # the custom_bar.yaml custom config file. bar.main(custom_config_filename) - assert os.path.isfile(f"{cwd}/{test_input}") == expected + for test_input in check_files: + assert os.path.isfile(f"{cwd}/{test_input}") # remove the .png and .points files - remove_files(cwd, ['bar_defaultpoints1.png', 'bar.points1']) + remove_files(cwd, check_files) @pytest.mark.skip("fails on linux host machines") diff --git a/test/skew_t/test_skew_t.py b/test/skew_t/test_skew_t.py index b87255bc..42e003ec 100644 --- a/test/skew_t/test_skew_t.py +++ b/test/skew_t/test_skew_t.py @@ -9,11 +9,7 @@ cwd = os.path.dirname(__file__) -def test_files_exist(setup_env, remove_files): - ''' - Checking that only the expected plot files are getting created and - input files with only fill/missing data are not created. - ''' +def test_skew_t(setup_env): setup_env(cwd) custom_config_filename = os.path.join(cwd, "test_skew_t.yaml") @@ -39,30 +35,37 @@ def test_files_exist(setup_env, remove_files): base_file = os.path.basename(full_file) files_of_interest.append(base_file) - # List of files for the sh052023 data (which is missing data for hours 66-240). - data_some_missing_data = ['ssh052023_avno_doper_2023010100_diag', - 'ssh052023_avno_doper_2023010106_diag'] + _check_files_exist(files_of_interest) + _check_files_not_created(files_of_interest) + _check_empty_input(files_of_interest) + + # Clean up all png files + shutil.rmtree(output_dir) + # If running without the ' -p no:logging' option, then uncomment to ensure that log + # files are removed. + # shutil.rmtree('./logs') + +def _check_files_exist(files_of_interest): + ''' + Checking that only the expected plot files are getting created and + input files with only fill/missing data are not created. + ''' + # List of files for the sh052023 data (which is missing data for hours 66-240). # Config file is requesting all the available sounding hours - expected_hours_for_2023_010100 = range(0,61,6) - expected_hours_for_2023_010106 = range(0,49,6) + data_some_missing_data = { + '2023010100': range(0, 61, 6), + '2023010106': range(0, 49, 6), + } # Create a list of expected base file names with their expected hours. expected_base_filenames = [] - for base in data_some_missing_data: - # Expected base for expected plot output name of format: - # ssh_052023_avno_doper_202301010[0|6]_diag_[0-9]{1,2}_hr - if base == 'ssh052023_avno_doper_2023010100_diag': - # Working with the 2023010100 date file - for cur_hr in expected_hours_for_2023_010100: - base_hr = base + '_' + str(cur_hr) + '_hr' - expected_base_filenames.append(base_hr) - - elif base == 'ssh052023_avno_doper_2023010106_diag': - # Working with the 2023010106 date - for cur_hr in expected_hours_for_2023_010106: - base_hr = base + '_' + str(cur_hr) + '_hr' - expected_base_filenames.append(base_hr) + # Expected base for expected plot output name of format: + # ssh_052023_avno_doper_202301010[0|6]_diag_[0-9]{1,2}_hr + for filetime, expected_hours in data_some_missing_data.items(): + for cur_hr in expected_hours: + base_hr = f'ssh052023_avno_doper_{filetime}_diag_{cur_hr}_hr' + expected_base_filenames.append(base_hr) # Subset only the files that correspond to the sh052023 data subset_files_of_interest = [] @@ -77,45 +80,13 @@ def test_files_exist(setup_env, remove_files): if expected in subset_files_of_interest: num_found += 1 - if len(subset_files_of_interest) != num_found: - assert False - - # Clean up all png files - shutil.rmtree(output_dir) - # If running without the ' -p no:logging' option, then uncomment to ensure that log - # files are removed. - # shutil.rmtree('./logs') + assert len(subset_files_of_interest) == num_found -def test_files_not_created(setup_env, remove_files): +def _check_files_not_created(files_of_interest): ''' Checking that input files with only fill/missing data are not created. ''' - setup_env(cwd) - custom_config_filename = os.path.join(cwd, "test_skew_t.yaml") - - # Invoke the command to generate a skew-T Diagram based on - # the test_skew_tm.yaml custom config file. - skew_t.main(custom_config_filename) - - # Verify that files for the ssh052023 data exists for the 0,6, 12,18,24, 30, 42, - # 48, 54, and 60 hour data. - output_dir = os.path.join(cwd, 'output') - - # Some of these data files have incomplete data so check for the expected hour - # plots. - - print(f"Output dir: {output_dir}") - file_ext = '.png' - files_of_interest = [] - for root, dir, files in os.walk(output_dir): - for item in files: - if item.endswith(file_ext): - # print(f"Item of interest: {item}") - full_file = os.path.join(root, item) - base_file = os.path.basename(full_file) - files_of_interest.append(base_file) - # List of files with no sounding data (9999 for all fields and times) no_sounding_data = ['ssh162023_avno_doper_2023022712_diag', 'ssh162023_avno_doper_2023022800_diag', @@ -146,45 +117,13 @@ def test_files_not_created(setup_env, remove_files): if cur in subsetted_basenames: fail_counter += 1 - if fail_counter != 0: - assert False - - # Clean up all png files - shutil.rmtree(output_dir) - # If running with the ' -p no:logging' option, then uncomment to ensure that log - # files are removed. - # shutil.rmtree('./logs') + assert fail_counter == 0 -def test_empty_input(setup_env, remove_files): +def _check_empty_input(files_of_interest): ''' Checking that empty input file is not creating any plots. ''' - setup_env(cwd) - custom_config_filename = os.path.join(cwd, "test_skew_t.yaml") - - # Invoke the command to generate a skew-T Diagram based on - # the test_skew_tm.yaml custom config file. - skew_t.main(custom_config_filename) - - # Verify that files for the ssh052023 data exists for the 0,6, 12,18,24, 30, 42, - # 48, 54, and 60 hour data. - output_dir = os.path.join(cwd, 'output') - - # Some of these data files have incomplete data so check for the expected hour - # plots. - - print(f"Output dir: {output_dir}") - file_ext = '.png' - files_of_interest = [] - for root, dir, files in os.walk(output_dir): - for item in files: - if item.endswith(file_ext): - # print(f"Item of interest: {item}") - full_file = os.path.join(root, item) - base_file = os.path.basename(full_file) - files_of_interest.append(base_file) - # List of empty files no_data_empty_file = ['sal092022_avno_doper_2022092800_diag'] @@ -200,12 +139,5 @@ def test_empty_input(setup_env, remove_files): match_found = re.match(r'^sal092022_avno_doper_2022092800_diag', no_data_empty_file[0]) - if match_found in subsetted_files_of_interest: - # The output file was created when it shouldn't have been, fail. - assert False - - # Clean up all png files - shutil.rmtree(output_dir) - # If running without the ' -p no:logging' option, then uncomment to ensure that log - # files are removed. - # shutil.rmtree('./logs') + # The output file was created when it shouldn't have been, fail. + assert match_found not in subsetted_files_of_interest