Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
added analysis_assim, extend, conus, forcing
  • Loading branch information
James S. Halgren committed Oct 31, 2023
1 parent ee4da98 commit cd6fd25
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/test_analysis_assim.py
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions test/test_analysis_extend.py
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions test/test_conus.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions test/test_forcing.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit cd6fd25

Please sign in to comment.