Skip to content

Commit

Permalink
Unit test-cases (#32)
Browse files Browse the repository at this point in the history
* 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
RohanSunkarapalli and James S. Halgren authored Nov 13, 2023
1 parent 9458b8c commit e297dca
Show file tree
Hide file tree
Showing 33 changed files with 1,898 additions and 6 deletions.
59 changes: 59 additions & 0 deletions test/test_analysisAssim.py
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()
59 changes: 59 additions & 0 deletions test/test_analysisAssimExtend.py
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()
59 changes: 59 additions & 0 deletions test/test_analysisAssimExtendNoDa.py
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()
59 changes: 59 additions & 0 deletions test/test_analysisAssimHawaii.py
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()
59 changes: 59 additions & 0 deletions test/test_analysisAssimHawaiiNoDa.py
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()
59 changes: 59 additions & 0 deletions test/test_analysisAssimNoDa.py
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()
Loading

0 comments on commit e297dca

Please sign in to comment.