Skip to content
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 some tests (APIformatting and granules) and fix bugs found during test writing #60

Merged
merged 2 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions icepyx/core/APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ def check_req_values(self):
Check that all of the required keys have values, if the key was passed in with
the values parameter.
"""

assert self.partype == 'required', "You cannot call this function for your parameter type"
reqkeys = self.poss_keys[self._reqtype]

if all(keys in self.fmted_keys.keys() for keys in reqkeys):
assert all(values in self.fmted_keys.values() for keys in reqkeys), "One of your formated parameters is missing a value"
assert all(self.fmted_keys.get(key, -9999) != -9999 for key in reqkeys),"One of your formated parameters is missing a value"
return True
else:
return False
Expand All @@ -249,16 +251,17 @@ def check_values(self):
Check that the non-required keys have values, if the key was
passed in with the values parameter.
"""
assert self.partype != 'required', "You cannot call this function for your parameter type"

default_keys = self.poss_keys['default']

spatial_keys = self.poss_keys['spatial']

if all(keys in self._fmted_keys.keys() for keys in default_keys):
assert all(values in self._fmted_keys.values() for keys in default_keys), "One of your formated parameters is missing a value"

assert all(self.fmted_keys.get(key, -9999) != -9999 for key in default_keys),"One of your formated parameters is missing a value"
#not the most robust check, but better than nothing...
if any(keys in self._fmted_keys.keys() for keys in spatial_keys):
assert any(values in self._fmted_keys.values() for keys in default_keys), "One of your formated parameters is missing a value"
assert any(self.fmted_keys.get(key, -9999) != -9999 for key in default_keys),"One of your formated parameters is missing a value"
return True
else: return False
else:
Expand All @@ -272,8 +275,14 @@ def build_params(self, **kwargs):
Parameters
----------
**kwargs
optional keyword arguments to be passed to the subsetter. Valid keywords are
time, bbox OR Boundingshape, format, projection, projection_parameters, and Coverage.
Keyword inputs containing the needed information to build the parameter list, depending on
parameter type, if the already formatted key:value is not submitted as a kwarg.
May include optional keyword arguments to be passed to the subsetter. Valid keywords
are time, bbox OR Boundingshape, format, projection, projection_parameters, and Coverage.

Keyword argument inputs for 'CMR' may include: dataset, version, start, end, extent_type, spatial_extent
Keyword argument inputs for 'required' may include: page_size, page_num, request_mode, include_meta
Keyword argument inputs for 'subset' may include: geom_filepath, start, end, extent_type, spatial_extent

"""

Expand Down
1 change: 0 additions & 1 deletion icepyx/core/granules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import icepyx.core.APIformatting as apifmt

#DevNote: currently this fn is not tested
def info(grans):
"""
Return some basic summary information about a set of granules for an
Expand Down
2 changes: 2 additions & 0 deletions icepyx/core/is2ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from xml.etree import ElementTree as ET
import json

import icepyx

#ICESat-2 specific reference functions
#options to get customization options for ICESat-2 data (though could be used generally)

Expand Down
4 changes: 2 additions & 2 deletions icepyx/tests/behind_NSIDC_API_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
#check that downloaded data is subset

@pytest.fixture
def reg_a():
def reg_a(scope='module'):
return ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-22','2019-02-28'])

#@patch('my_module.__get_input', return_value='y')

@pytest.fixture
def session(reg_a):
def session(reg_a, scope='module'):
return reg_a._start_earthdata_session('icepyx_devteam', 'icepyx.dev@gmail.com', os.getenv('NSIDC_LOGIN'))

#QUESTION: should we be testing to make sure the session starts? If so, how? The below doesn't work because the 'requests.sessions.Session' isn't recognized... is this a case where I'd need to have a mock session to compare it to?
Expand Down
11 changes: 0 additions & 11 deletions icepyx/tests/is2class_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,7 @@ def test_properties():

#BestPractices: should do additional properties tests for each potential property type (e.g. spatial extent can have type bounding_box or polygon)

def test_no_granules_in_search_results():
ermsg = "Your search returned no results; try different search parameters"
with pytest.raises(AssertionError, match=ermsg):
ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-20'], version='2').avail_granules()

def test_correct_granule_list_returned():
reg_a = ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28'], version='2')
reg_a.avail_granules()
obs_grans = [gran['producer_granule_id'] for gran in reg_a.granules]
exp_grans = ['ATL06_20190221121851_08410203_002_01.h5', 'ATL06_20190222010344_08490205_002_01.h5', 'ATL06_20190225121032_09020203_002_01.h5', 'ATL06_20190226005526_09100205_002_01.h5']

assert set(obs_grans) == set(exp_grans)



Expand Down
30 changes: 30 additions & 0 deletions icepyx/tests/test_APIformatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,33 @@ def test_combine_params():

########## Parameters (class) ##########


# @pytest.fixture
# def CMRparams(scope='module'):
# return apifmt.Parameters('CMR')

def test_CMRparams_no_other_inputs():
CMRparams = apifmt.Parameters('CMR')
#TestQuestion: the next statement essentially tests _get_possible_keys as well, so how would I test them independently?
assert CMRparams.poss_keys == {'default': ['short_name','version','temporal'], 'spatial': ['bounding_box','polygon'], 'optional': []}
assert CMRparams.fmted_keys == {}
assert CMRparams._check_valid_keys
#Note: this test must be done before the next one
if CMRparams.partype == 'required':
assert CMRparams.check_req_values() == False
else:
assert CMRparams.check_values() == False

CMRparams.build_params(dataset='ATL06', version='003',
start=dt.datetime(2019, 2, 20, 0, 0),
end=dt.datetime(2019, 2, 24, 23, 59, 59),
extent_type='bounding_box',
spatial_extent=[-55, 68, -48, 71])
obs_fmted_params = CMRparams.fmted_keys
exp_fmted_params = {'short_name': 'ATL06', 'version': '003',
'temporal': '2019-02-20T00:00:00Z,2019-02-24T23:59:59Z',
'bounding_box': '-55,68,-48,71'}
assert obs_fmted_params == exp_fmted_params



Loading