-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add a few tests for Variables class #431
base: development
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @rwegener2! First off, thanks for all your great work on icepyx recently! Really nice to see more unit tests added to icepyx because it really improves the long term sustainability and quality of the software 😄
Taking a look at your code, the implementation of the tests are pretty good, and it looks like you've covered most of the public methods (those not starting with an underscore (e.g. _check_valid_lists
). Ideally though, we'll need to figure a way to avoid storing the 8MB HDF5 file in git, hopefully via a dynamic download step, or some alternative way. See specific comments below.
def variables_obj_atl06(): | ||
return Variables( | ||
"file", | ||
path='./test_data/processed_ATL06_20191130112041_09860505_006_01.h5', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we'll need to see if it's possible to avoid storing this 8MB HDF5 file in git, because it will slow down git clone
for future developers. There's actually some work to prevent big files from being uploaded at #143, and we had some nasty work a few years ago to remove HDF5 files at #114.
There are some tests in the test_behind_NSIDC_API_login.py
file which actually downloads data from NSIDC. Maybe it is possible to reuse some functionality from there?
@pytest.fixture() | ||
def variables_obj_atl06(): | ||
return Variables( | ||
"file", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use vartype="order"
instead of vartype="file"
to dynamically download the file?
region = Query('ATL06',[-45, 74, -44,75],['2019-11-30','2019-11-30'], \ | ||
start_time='00:00:00', end_time='23:59:59') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommend to set the version
here, because the returned schema can change from version to version.
region = Query('ATL06',[-45, 74, -44,75],['2019-11-30','2019-11-30'], \ | |
start_time='00:00:00', end_time='23:59:59') | |
region = Query( | |
product="ATL06", | |
spatial_extent=[-45, 74, -44, 75], | |
date_range=["2019-11-30", "2019-11-30"], | |
start_time="00:00:00", | |
end_time="23:59:59", | |
version="006", | |
) |
What was Changed
This PR adds a few tests for the Variables class. It doesn't cover all the available arguments, but it adds the following tests:
.avail()
function, reading from a local file.avail()
function, using an order result.append()
function with thedefaults
flag set to True.remove()
function for all.append()
function when given avars_list
argumentHow it was Changed
A
test_variables.py
file already existed, so I added additional tests there. For expected outputs longer than a few lines the output is saved in atxt
orjson
file within theexpected_outputs
folder. These are read into a Python object during the test and compared to theicepyx
produced result.For the test using a local file I saved the local file in a
test_data
folder. I used an ATL06 product because it was small (less than 8MB). TheVariables
object that was created using this dataset was created as apytest.fixture
, to avoid repeating the class initiation code multiple times.How to test it
I actually couldn't get all the tests to run, so I was only testing the
test_variables.py
file. To run the tests I moved into thetests
folder and ranpytest test_variables.py
.Notes / Questions
Earthdata Login
In line 53 of
test_variables.py
I login to NASA Earthdata. This works because I have a.netrc
file saved in my environment, so anyone else who runs these tests will need to have that setup as well. It looks like we maybe have some testing CI setup, so I assume that this method of logging in will fail. How do we deal with logins in CI right now? Do we already have CI EDL credentials stored in GH Secrets?Assuming a Query will return consistently
In line 57 of
test_variables.py
there is a sort of awkward check to make sure that the Query only returned one granule. I can't come up with any real reason why that would ever change, but I wasn't sure. Do we feel quite certain that past granules (from 2019) won't be added (in which case I'd remove the if statement), or is it worth it to keep that check?Context
(As a note for you @JessicaS11 I made this PR because I was starting to work on the
getvars
branch and thought this would provide a baseline for what the Variables module does right now when local files. When thegetvars
branch enables variable search with cloud data I think ideally the calls tested here will still work swimmingly when given an s3 url instead of a local filepath.)