-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional test using planetary rover sample data. (#14)
- Loading branch information
1 parent
957b675
commit 4110577
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
markers = | ||
functional: Functional test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
# Functional tests with planetary science data. | ||
# Inspired by Gary's PDSC functional tests, e.g.: | ||
# https://github-fn.jpl.nasa.gov/COSMIC/COSMIC_PDSC/blob/master/test/test_ingest.py | ||
# | ||
# Kiri Wagstaff | ||
# 8/19/21 | ||
|
||
import os | ||
import shutil | ||
import pytest | ||
from unittest import TestCase | ||
from dora_exp_pipeline.dora_exp import start | ||
from test_utils import check_results | ||
|
||
@pytest.mark.functional | ||
class TestPlanetary(TestCase): | ||
|
||
def setUp(self): | ||
|
||
self.outdir = '/tmp/dora/test/planetary' | ||
if not os.path.exists(self.outdir): | ||
os.makedirs(self.outdir) | ||
|
||
def test_run(self): | ||
|
||
config_file = 'sample_data/planetary_rover/png/exp/navcam.config' | ||
|
||
# Run the experiment; also tests ability to parse config file | ||
start(config_file, self.outdir) | ||
|
||
# Check results for each algorithm | ||
for file_base in ['demud-k=5/selections-demud.csv', | ||
'iforest/selections-iforest.csv', | ||
'negative_sampling-percent_increase=20/selections-negative_sampling.csv', | ||
'pca-k=5/selections-pca.csv' | ||
]: | ||
correct_file = 'test/ref-results/planetary_rover/%s' % file_base | ||
output_file = '%s/%s' % (self.outdir, file_base) | ||
|
||
# Check results against correct output | ||
assert(check_results(output_file, correct_file)) | ||
|
||
def tearDown(self): | ||
# Remove any intermediate files | ||
shutil.rmtree(self.outdir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Helper functions for pytests | ||
import numpy as np | ||
|
||
def read_selections(f): | ||
|
||
sels = [] | ||
|
||
with open(f, 'r') as inf: | ||
for l in inf: | ||
if l[0] == '#': | ||
continue | ||
sels += [l.split(',')[2].split('.')[0]] # name excluding extension | ||
|
||
return sels | ||
|
||
|
||
def read_selections_and_scores(f): | ||
|
||
sels = [] | ||
scores = [] | ||
|
||
with open(f, 'r') as inf: | ||
for l in inf: | ||
if l[0] == '#': | ||
continue | ||
# Get the image filename and numeric score | ||
vals = l.split(',')[2:4] | ||
sels += [vals[0].split('.')[0]] # exclude extension | ||
scores += [float(vals[1])] # convert score to float | ||
|
||
return sels, scores | ||
|
||
|
||
def check_results(outfile, correct_file): | ||
|
||
sels, scores = read_selections_and_scores(outfile) | ||
correct_sels, correct_scores = read_selections_and_scores(correct_file) | ||
|
||
# Check the selections by name | ||
if sels != correct_sels: | ||
return False | ||
|
||
# Check the numeric scores | ||
return np.isclose(scores, correct_scores, atol=1e-6).all() | ||
|
||
|