Skip to content

Commit

Permalink
Updates tests to check for warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaura committed May 28, 2021
1 parent fce65a9 commit 7b016ef
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions plio/io/tests/test_io_controlnetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ def cnet_dataframe(tmpdir):
serials = {i:'APOLLO15/METRIC/{}'.format(j) for i, j in enumerate(serial_times.values())}
columns = ['id', 'pointType', 'serialnumber', 'measureType',
'sample', 'line', 'image_index', 'pointLog', 'measureLog',
'aprioriCovar']
'aprioriCovar', 'referenceIndex']

data = []
for i in range(npts):
aprioriCovar = None
if i == npts - 1:
aprioriCovar = np.ones((2,3))
data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar))
data.append((i, 2, serials[1], 2, 0, 0, 1, [], [io_controlnetwork.MeasureLog(2, 0.5)],aprioriCovar))
reference_idx = i % 2
data.append((i, 2, serials[0], 2, 0, 0, 0, [], [], aprioriCovar,reference_idx))
data.append((i, 2, serials[1], 2, 0, 0, 1, [], [io_controlnetwork.MeasureLog(2, 0.5)],aprioriCovar, reference_idx))

df = pd.DataFrame(data, columns=columns)

Expand Down Expand Up @@ -121,23 +122,29 @@ def test_create_point(cnet_dataframe, tmpdir):
point_protocol.ParseFromString(raw_point)
assert str(i) == point_protocol.id
assert 2 == point_protocol.type

assert i % 2 == point_protocol.referenceIndex

if i == cnet_dataframe.npts - 1:
assert point_protocol.aprioriCovar == [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
for j, m in enumerate(point_protocol.measures):
assert m.serialnumber in cnet_dataframe.serials.values()
assert 2 == m.type
assert len(m.log) == j # Only the second measure has a message

def test_create_point_reference_index(cnet_dataframe, tmpdir):
def test_create_point_wo_reference_index(cnet_dataframe, tmpdir):
# cnet_dataframe has 5 points. Set the reference on one of those to be
# the second measure.
reference_idx = [0,0,1,1,0,0,0,0,0,0]
cnet_dataframe['referenceIndex'] = reference_idx
reference_idx = [0,0,0,0,0,0,0,0,0,0]
new_cnet_dataframe = cnet_dataframe.drop(columns='referenceIndex')
cnet_file = tmpdir.join('test_w_reference.net')
io_controlnetwork.to_isis(cnet_dataframe, cnet_file, mode='wb', targetname='Moon')

# Check that the warn is raised properly
with pytest.warns(UserWarning, match='Unable to identify referenceIndex (.*)'):
io_controlnetwork.to_isis(new_cnet_dataframe, cnet_file, mode='wb', targetname='Moon')

# Check that nothing in == zeros out
test_cnet = io_controlnetwork.from_isis(cnet_file)

assert (test_cnet.referenceIndex == reference_idx).all()

def test_create_pvl_header(cnet_dataframe, tmpdir):
Expand Down

0 comments on commit 7b016ef

Please sign in to comment.