fre.pp.tests.test_rename_split_to_pp module

fre pp rename-split tests

Functionality tested: - daily frequency, 6 months duration - monthly frequency, 1 year duration - static frequency - annual frequency, one year duration, with time bounds - annual frequency, one year duration, without time bounds and with diag manifest

Failure cases: - no files in your input directory/subdirs - input files are not named according to our very specific naming conventions

fre.pp.tests.test_rename_split_to_pp.test_get_duration_from_two_dates(start_date, end_date, expected_duration)

Lookup some durations between two dates

fre.pp.tests.test_rename_split_to_pp.test_get_duration_from_two_dates_raises_valueerror(start_date, end_date)

Test that ValueError is raised when duration cannot be determined

fre.pp.tests.test_rename_split_to_pp.test_get_freq_and_format_from_two_dates(start_date, end_date, expected_freq, expected_format)

Lookup some frequencies and formats between 2 dates

fre.pp.tests.test_rename_split_to_pp.test_get_freq_and_format_from_two_dates_raises_valueerror(start_date, end_date)

Test that ValueError is raised when frequency cannot be determined

fre.pp.tests.test_rename_split_to_pp.test_rename_file_raises_exception_missing_in_manifests()

Test that missing label in all manifests raises an exception.

fre.pp.tests.test_rename_split_to_pp.test_rename_file_raises_filenotfounderror_missing_diag_manifest()

Test that FileNotFoundError is raised when diag manifest doesn’t exist

fre.pp.tests.test_rename_split_to_pp.test_rename_file_raises_valueerror_bad_filename()

Test that ValueError is raised when filename cannot be parsed

fre.pp.tests.test_rename_split_to_pp.test_rename_file_uses_diag_manifest_tuple()

Test that diag_manifest tuple is supported and picks the matching manifest entry.

fre.pp.tests.test_rename_split_to_pp.test_rename_split_raises_filenotfounderror_no_files()

Test that FileNotFoundError is raised when no files matching the component are found

fre.pp.tests.test_rename_split_to_pp.test_rename_split_to_pp_cleanup()

deletes the test files (any file ending with .nc) and output directories (any directory under output/)

fre.pp.tests.test_rename_split_to_pp.test_rename_split_to_pp_multiply_setup()

Takes every file with ‘tile1’ in the name and make 5 new copies. rename-split-to-pp needs 6 tile files - it throws an error if there are fewer - but it’s not checking on whether the tiles match up with each other, so we can take one and copy it 5 times.

fre.pp.tests.test_rename_split_to_pp.test_rename_split_to_pp_run(hist_source, do_regrid, og_suffix)

Tests the running of rename-split-to-pp, which takes 3 input args:

Parameters:
  • hist_source – source of the history data, used to build input and output paths

  • do_regrid – whether to do regridding, boolean, changes dir structure

  • og_suffix – the frequency suffix that rename-split-to-pp should be adding to the output data dir structure

rename-split-to-pp takes 4 arguments, which are set as env variables:

InputDir:

(inputDir) location of your input files, output from split-netcdf

OutputDir:

(outputDir) location to which to write your output files

Component:

(history_source) VERY BADLY NAMED. What split-netcdf is calling the hist_source after the rewrite.

Use_subdirs:

(do_regrid) either set to 1 or unset. 1 is used for the regridding case.

  • no longer set to 1 or unset, set to “True” or “False”. Makes the if checks more sensitive, but makes the setup/teardown of unsetting env variables easier.

These tests operate under 4 frequencies with regridding/no regridding cases:

  • success:

    • daily regrid/native, multiple tiles

    • monthly regrid/native, multiple tiles (currently failing because of metadata)

    • annual regrid/native

    • static regrid/no regrid

  • failure:

    • files in input don’t match naming convention, raises error TBD

    • no files in input dir, raises error TBD

For the moment, rename-split-to-pp isn’t doing any rewriting of files - it’s copying files to new locations and verifying that they have the right number of timesteps. I’ve included hooks for functions that check on data + metadata, but we really don’t need them yet.

TODO:

  • When this is ported to python, the xfail tests should check for the python error that gets raised, but until that point, not a whole lot of point in checking on a raised exception here

fre.pp.tests.test_rename_split_to_pp.test_rename_split_to_pp_setup()

sets up the test files for the test cases