Skip to content

Commit baf52cd

Browse files
committed
add tests for validate_year updates in aop_download.py
1 parent 70ba62a commit baf52cd

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

tests/test_aop_download.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"""
2626

2727
# import required packages
28+
from datetime import datetime
2829
import os
2930
import pytest
3031
import unittest
@@ -120,6 +121,33 @@ def test_invalid_neon_site(self):
120121
):
121122
by_file_aop(dpid=self.dpid, site=invalid_site, year=self.year)
122123

124+
def test_valid_year(self):
125+
# Should not raise for a valid year
126+
current_year = datetime.now().year
127+
try:
128+
by_file_aop(dpid=self.dpid, site=self.site, year=current_year)
129+
130+
except ValueError:
131+
self.fail(
132+
"validate_year() raised ValueError unexpectedly for a valid year."
133+
)
134+
135+
def test_invalid_year_out_of_range(self):
136+
current_year = datetime.now().year
137+
# Should raise for a year before 2012
138+
with pytest.raises(
139+
ValueError,
140+
match=f"2011 is an invalid year. Year must be between 2012 and {current_year}.",
141+
):
142+
by_file_aop(dpid=self.dpid, site=self.site, year=2011)
143+
# Should raise for a year after the current yearAdd commentMore actions
144+
future_year = datetime.now().year + 1
145+
with pytest.raises(
146+
ValueError,
147+
match=f"{future_year} is an invalid year. Year must be between 2012 and {current_year}.",
148+
):
149+
by_file_aop(dpid=self.dpid, site=self.site, year=future_year)
150+
123151
@parameterized.expand(
124152
[
125153
("21",),
@@ -132,7 +160,7 @@ def test_invalid_year_format(self, year):
132160
"""
133161
with pytest.raises(
134162
ValueError,
135-
match=f'{year} is an invalid year. Year is required in the format "2017" or 2017, eg. NEON AOP data are available from 2013 to present.',
163+
match=f"{year} is an invalid year. Year is required in the format '2017' or 2017, e.g. NEON AOP data are available from 2012 to present.",
136164
):
137165
by_file_aop(dpid=self.dpid, site=self.site, year=year)
138166

@@ -336,7 +364,7 @@ def test_invalid_year_format(self, year):
336364
"""
337365
with pytest.raises(
338366
ValueError,
339-
match=f'{year} is an invalid year. Year is required in the format "2017" or 2017, eg. NEON AOP data are available from 2013 to present.',
367+
match=f"{year} is an invalid year. Year is required in the format '2017' or 2017, e.g. NEON AOP data are available from 2012 to present.",
340368
):
341369
by_tile_aop(
342370
dpid=self.dpid,

0 commit comments

Comments
 (0)