forked from sepehrkrz/nwmurl
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move test to test folder and add pytest.ini pytest.ini is required in order to run the test with `pytest` instead of just `python -m pytest`. * Unit test cases developed for individual folders * rename with `test_` for pytest convention * Drop the extraneous files and synchronize removed filenamelist.txt in test folder removed urlgennwm.py in test folder added `write_to_file` var changed function call from `generate_urls` to `generate_urls_operational` * black test files --------- Co-authored-by: James S. Halgren <jshalgren@ua.edu>
- Loading branch information
1 parent
9458b8c
commit e297dca
Showing
33 changed files
with
1,898 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim(self): | ||
# Define test input values | ||
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 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the analysis_assim folder | ||
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", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim/nwm.t08z.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.t08z.analysis_assim.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/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.20220113/analysis_assim/nwm.t00z.analysis_assim.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm018.conus.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim_extend(self): | ||
# Define test input values | ||
start_date = "202201120000" | ||
end_date = "202201130000" | ||
fcst_cycle = [0, 8] | ||
lead_time = [1, 18] | ||
varinput = 1 | ||
geoinput = 1 | ||
runinput = 6 # Set to 6 for the analysis_assim_extend folder | ||
urlbaseinput = 2 | ||
meminput = 1 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the analysis_assim_extend folder | ||
expected_urls = [ | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend/nwm.t00z.analysis_assim_extend.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend/nwm.t00z.analysis_assim_extend.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend/nwm.t08z.analysis_assim_extend.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend/nwm.t08z.analysis_assim_extend.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend/nwm.t00z.analysis_assim_extend.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend/nwm.t00z.analysis_assim_extend.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend/nwm.t08z.analysis_assim_extend.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend/nwm.t08z.analysis_assim_extend.channel_rt.tm018.conus.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim_extend_no_da(self): | ||
# Define test input values | ||
start_date = "202201120000" | ||
end_date = "202201130000" | ||
fcst_cycle = [0, 8] | ||
lead_time = [1, 18] | ||
varinput = 1 | ||
geoinput = 1 | ||
runinput = 7 # Set to 7 for the assim_extend_no_da folder | ||
urlbaseinput = 2 | ||
meminput = 1 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the assim_extend_no_da folder | ||
expected_urls = [ | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend_no_da/nwm.t00z.analysis_assim_extend_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend_no_da/nwm.t00z.analysis_assim_extend_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend_no_da/nwm.t08z.analysis_assim_extend_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_extend_no_da/nwm.t08z.analysis_assim_extend_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend_no_da/nwm.t00z.analysis_assim_extend_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend_no_da/nwm.t00z.analysis_assim_extend_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend_no_da/nwm.t08z.analysis_assim_extend_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_extend_no_da/nwm.t08z.analysis_assim_extend_no_da.channel_rt.tm018.conus.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim_hawaii(self): | ||
# Define test input values | ||
start_date = "202201120000" | ||
end_date = "202201130000" | ||
fcst_cycle = [0, 8] | ||
lead_time = [1, 18] | ||
varinput = 1 | ||
geoinput = 2 | ||
runinput = 5 # Set to 5 for the analysis_assim_hawaii folder | ||
urlbaseinput = 2 | ||
meminput = 1 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the analysis_assim_hawaii folder | ||
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.hawaii.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.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm018.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t00z.analysis_assim.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t00z.analysis_assim.channel_rt.tm018.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim/nwm.t08z.analysis_assim.channel_rt.tm018.hawaii.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim_hawaii_no_da(self): | ||
# Define test input values | ||
start_date = "202201120000" | ||
end_date = "202201130000" | ||
fcst_cycle = [0, 8] | ||
lead_time = [1, 18] | ||
varinput = 1 | ||
geoinput = 2 | ||
runinput = 10 # Set to 10 for the analysis_assim_hawaii_no_da folder | ||
urlbaseinput = 2 | ||
meminput = 1 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the analysis_assim_hawaii_no_da folder | ||
expected_urls = [ | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm018.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm018.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm018.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm001.hawaii.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm018.hawaii.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
import unittest | ||
from urlgennwm import ( | ||
generate_urls_operational, | ||
) # Import the generate_urls_operational function from your script | ||
|
||
|
||
class TestGenerateURLs(unittest.TestCase): | ||
def test_generate_urls_operational_for_analysis_assim_no_da(self): | ||
# Define test input values | ||
start_date = "202201120000" | ||
end_date = "202201130000" | ||
fcst_cycle = [0, 8] | ||
lead_time = [1, 18] | ||
varinput = 1 | ||
geoinput = 1 | ||
runinput = 10 # Set to 5 for the analysis_assim_no_da folder | ||
urlbaseinput = 2 | ||
meminput = 1 | ||
write_to_file = True | ||
|
||
# Call the function to generate URLs | ||
generate_urls_operational( | ||
start_date, | ||
end_date, | ||
fcst_cycle, | ||
lead_time, | ||
varinput, | ||
geoinput, | ||
runinput, | ||
urlbaseinput, | ||
meminput, | ||
write_to_file, | ||
) | ||
|
||
# Check if the generated 'filenamelist.txt' file exists | ||
self.assertTrue(os.path.exists("filenamelist.txt")) | ||
|
||
# Define the expected URLs or patterns for the analysis_assim_no_da folder | ||
expected_urls = [ | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220112/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t00z.analysis_assim_no_da.channel_rt.tm018.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm001.conus.nc", | ||
"https://nomads.ncep.noaa.gov/pub/data/nccf/com/nwm/post-processed/WMS/nwm.20220113/analysis_assim_no_da/nwm.t08z.analysis_assim_no_da.channel_rt.tm018.conus.nc", | ||
] | ||
|
||
# Read the content of the file and check for the expected content | ||
with open("filenamelist.txt", "r") as file: | ||
content = file.read() | ||
for url in expected_urls: | ||
self.assertIn(url, content) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.