From cd6fd2527f1ca1ddaaf6ff4511c7ee0ddbab5748 Mon Sep 17 00:00:00 2001 From: "James S. Halgren" Date: Tue, 31 Oct 2023 15:22:34 -0500 Subject: [PATCH] add tests added analysis_assim, extend, conus, forcing --- test/test_analysis_assim.py | 33 +++++++++++++++++++++++++++++++++ test/test_analysis_extend.py | 32 ++++++++++++++++++++++++++++++++ test/test_conus.py | 35 +++++++++++++++++++++++++++++++++++ test/test_forcing.py | 22 ++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 test/test_analysis_assim.py create mode 100644 test/test_analysis_extend.py create mode 100644 test/test_conus.py create mode 100644 test/test_forcing.py diff --git a/test/test_analysis_assim.py b/test/test_analysis_assim.py new file mode 100644 index 0000000..75d9e99 --- /dev/null +++ b/test/test_analysis_assim.py @@ -0,0 +1,33 @@ +import os +import pytest +from urlgennwm import generate_urls + +@pytest.fixture +def generated_urls(): + start_date = "202201120000" + end_date = "202201130000" + fcst_cycle = [0, 8] + lead_time = [1, 18] + varinput = 1 + geoinput = 1 + runinput = 5 # Set to 5 for the analysis_assim folder + urlbaseinput = 2 + meminput = 1 + + generate_urls(start_date, end_date, fcst_cycle, lead_time, varinput, geoinput, runinput, urlbaseinput, meminput) + + yield + +def test_generate_urls_for_analysis_assim(generated_urls): + assert os.path.exists("filenamelist.txt") + + expected_urls = [ + "https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim/nwm.t00z.analysis_assim.channel_rt.tm001.conus.nc", + "https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim/nwm.t00z.analysis_assim.channel_rt.tm018.conus.nc", + # Add more expected URLs here for the analysis_assim folder + ] + + with open("filenamelist.txt", "r") as file: + content = file.read() + for url in expected_urls: + assert url in content diff --git a/test/test_analysis_extend.py b/test/test_analysis_extend.py new file mode 100644 index 0000000..a34eeee --- /dev/null +++ b/test/test_analysis_extend.py @@ -0,0 +1,32 @@ +import os +import pytest +from urlgennwm import generate_urls + +@pytest.fixture +def generated_urls_for_analysis_assim_extend(): + start_date = "202201120000" + end_date = "202201130000" + fcst_cycle = [16] + lead_time = [28] + varinput = 1 + geoinput = 1 + runinput = 6 + urlbaseinput = 2 + meminput = 1 + + generate_urls(start_date, end_date, fcst_cycle, lead_time, varinput, geoinput, runinput, urlbaseinput, meminput) + + yield + +def test_generate_urls_for_analysis_assim_extend(generated_urls_for_analysis_assim_extend): + assert os.path.exists("filenamelist.txt") + + expected_urls = [ + "https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend/nwm.t16z.analysis_assim_extend.channel_rt.tm028.conus.nc", + # Add more expected URLs here for the analysis_assim_extend folder + ] + + with open("filenamelist.txt", "r") as file: + content = file.read() + for url in expected_urls: + assert url in content diff --git a/test/test_conus.py b/test/test_conus.py new file mode 100644 index 0000000..88a39b0 --- /dev/null +++ b/test/test_conus.py @@ -0,0 +1,35 @@ +import os +import pytest +from urlgennwm import generate_urls + +@pytest.fixture +def generated_urls(): + start_date = "202310150000" + end_date = "202310150000" + fcst_cycle = [0, 8] + lead_time = [1, 18] + varinput = 1 + geoinput = 1 # Assuming this is for "conus" + runinput = 1 + urlbaseinput = 2 + meminput = 1 + + generate_urls(start_date, end_date, fcst_cycle, lead_time, varinput, geoinput, runinput, urlbaseinput, meminput) + + yield + +def test_generate_urls_for_conus(generated_urls): + assert os.path.exists("filenamelist.txt") + + # Modify the expected URL to match the "conus" geography + expected_urls = [ + 'https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20231015/short_range/nwm.t00z.short_range.channel_rt.f001.conus.nc', + 'https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20231015/short_range/nwm.t00z.short_range.channel_rt.f018.conus.nc', + 'https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20231015/short_range/nwm.t08z.short_range.channel_rt.f001.conus.nc', + 'https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20231015/short_range/nwm.t08z.short_range.channel_rt.f018.conus.nc' + ] + + with open("filenamelist.txt", "r") as file: + content = file.read() + for url in expected_urls: + assert url in content diff --git a/test/test_forcing.py b/test/test_forcing.py new file mode 100644 index 0000000..11fa11d --- /dev/null +++ b/test/test_forcing.py @@ -0,0 +1,22 @@ +import os +import pytest +from urlgennwm import generate_urls + +@pytest.fixture +def generated_urls_for_forcing_medium_range(): + start_date = "202201120000" + end_date = "202201130000" + fcst_cycle = [0, 12] + lead_time = [6, 120] + varinput = 5 + geoinput = 1 + runinput = 2 + urlbaseinput = 1 + meminput = 1 + + generate_urls(start_date, end_date, fcst_cycle, lead_time, varinput, geoinput, runinput, urlbaseinput, meminput) + + yield + +def test_generate_urls_for_forcing_medium_range(generated_urls_for_forcing_medium_range): + assert os.path.exists("filenamelist.txt")