Skip to content

Commit 2fff3c5

Browse files
authored
Merge pull request #158 from Stanford-NavLab/derek/conftest
Unified `conftest` framework to avoid repeated fixtures and unify fixture naming.
2 parents 1ae992d + f3c7a1f commit 2fff3c5

27 files changed

Lines changed: 558 additions & 1325 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Test with pytest
6767
run: |
6868
source $VENV
69-
pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov-report=xml
69+
poetry run pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/navdata --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov=gnss_lib_py/visualizations --cov-report=xml
7070
- name: Upload coverage report to code-cov
7171
uses: codecov/codecov-action@v3
7272
with:

docs/source/contributing/development.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Standard GitHub Workflow
5959

6060
.. code-block:: bash
6161
62-
poetry run pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov-report=xml
62+
poetry run pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/navdata --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov=gnss_lib_py/visualizations --cov-report=html
6363
poetry run coverage report
6464
6565
See the :ref:`Coverage Report<coverage>` section for more details.
@@ -142,7 +142,7 @@ NAVLab GitHub Workflow
142142

143143
.. code-block:: bash
144144
145-
poetry run pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov-report=xml
145+
poetry run pytest --cov=gnss_lib_py/algorithms --cov=gnss_lib_py/navdata --cov=gnss_lib_py/parsers --cov=gnss_lib_py/utils --cov=gnss_lib_py/visualizations --cov-report=html
146146
poetry run coverage report
147147
148148
See the :ref:`Coverage Report<coverage>` section for more details.

docs/source/reference/test_navdata/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_navdata/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ navdata
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_navdata
98
test_operations

docs/source/reference/test_utils/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_utils/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ utils
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_coordinates
98
test_dop
109
test_ephemeris_downloader

docs/source/reference/test_visualizations/conftest.rst

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/source/reference/test_visualizations/modules.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ visualizations
44
.. toctree::
55
:maxdepth: 4
66

7-
conftest
87
test_plot_map
98
test_plot_metric
109
test_plot_skyplot

gnss_lib_py/algorithms/gnss_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def solve_gnss_ekf(measurements, init_dict = None,
9898
corr_pr_m = measurement_subset["corr_pr_m"].reshape(-1,1)
9999

100100
# remove NaN indexes
101-
not_nan_indexes = ~np.isnan(pos_sv_m).any(axis=1)
101+
not_nan_indexes = ~np.isnan(pos_sv_m).any(axis=1) & ~np.isnan(corr_pr_m).any(axis=1)
102102
pos_sv_m = pos_sv_m[not_nan_indexes]
103103
corr_pr_m = corr_pr_m[not_nan_indexes]
104104

tests/algorithms/test_fde.py

Lines changed: 12 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -11,113 +11,43 @@
1111
import numpy as np
1212

1313
from gnss_lib_py.navdata.navdata import NavData
14-
from gnss_lib_py.parsers.google_decimeter import AndroidDerived2022
1514
from gnss_lib_py.algorithms.fde import solve_fde, evaluate_fde
1615

17-
@pytest.fixture(name="root_path_2022")
18-
def fixture_root_path_2022():
19-
"""Location of measurements for unit test.
20-
21-
Returns
22-
-------
23-
root_path_2022 : string
24-
Folder location containing measurements.
25-
26-
"""
27-
root_path = os.path.dirname(
28-
os.path.dirname(
29-
os.path.dirname(
30-
os.path.realpath(__file__))))
31-
root_path_2022 = os.path.join(root_path, 'data','unit_test','google_decimeter_2022')
32-
return root_path_2022
33-
34-
@pytest.fixture(name="derived_2022_path")
35-
def fixture_derived_2022_path(root_path_2022):
36-
"""Filepath of Android Derived measurements.
37-
38-
Parameters
39-
----------
40-
root_path_2022 : string
41-
Folder location containing measurements.
42-
43-
Returns
44-
-------
45-
derived_2022_path : string
46-
Location for the unit_test Android derived 2022 measurements.
47-
48-
Notes
49-
-----
50-
Test data is a subset of the Android Raw Measurement Dataset [1]_,
51-
from the 2022 Decimeter Challenge. Particularly, the
52-
train/2021-04-29-MTV-2/SamsungGalaxyS20Ultra trace. The dataset
53-
was retrieved from
54-
https://www.kaggle.com/competitions/smartphone-decimeter-2022/data
55-
56-
References
57-
----------
58-
.. [1] Fu, Guoyu Michael, Mohammed Khider, and Frank van Diggelen.
59-
"Android Raw GNSS Measurement Datasets for Precise Positioning."
60-
Proceedings of the 33rd International Technical Meeting of the
61-
Satellite Division of The Institute of Navigation (ION GNSS+
62-
2020). 2020.
63-
64-
"""
65-
derived_2022_path = os.path.join(root_path_2022, 'device_gnss.csv')
66-
return derived_2022_path
67-
68-
@pytest.fixture(name="derived")
69-
def fixture_load_derived(derived_2022_path):
70-
"""Load instance of AndroidDerived2022.
71-
72-
Parameters
73-
----------
74-
derived_2022_path : pytest.fixture
75-
String with location of Android derived measurement file.
76-
77-
Returns
78-
-------
79-
derived : AndroidDerived2022
80-
Instance of AndroidDerived2022 for testing.
81-
82-
"""
83-
derived = AndroidDerived2022(derived_2022_path)
84-
return derived
85-
8616
@pytest.mark.parametrize('method',
8717
[
8818
"residual",
8919
"edm",
9020
])
91-
def test_solve_fde(derived, method):
21+
def test_solve_fde(derived_2022, method):
9222
"""Test residual-based FDE.
9323
9424
Parameters
9525
----------
96-
derived : AndroidDerived2022
26+
derived_2022 : AndroidDerived2022
9727
Instance of AndroidDerived2022 for testing.
9828
method : string
9929
Method for fault detection and exclusion.
10030
10131
"""
10232

10333
# test without removing outliers
104-
navdata = derived.copy()
34+
navdata = derived_2022.copy()
10535
navdata = solve_fde(navdata, method=method)
10636
assert "fault_" + method in navdata.rows
10737

10838
# max thresholds shouldn't remove any
109-
navdata = derived.copy()
39+
navdata = derived_2022.copy()
11040
navdata = solve_fde(navdata, threshold=np.inf, method=method)
11141
assert sum(navdata.where("fault_" + method,1)["fault_" + method]) == 0
11242

11343
# min threshold should remove most all
114-
navdata = derived.copy()
44+
navdata = derived_2022.copy()
11545
navdata = solve_fde(navdata, threshold=-np.inf, method=method)
11646
print(sum(navdata.where("fault_" + method,1)["fault_" + method]))
11747
assert len(navdata.where("fault_" + method,0)) == 24
11848
num_unknown = len(navdata.where("fault_" + method,2))
11949

120-
navdata = derived.copy()
50+
navdata = derived_2022.copy()
12151
original_length = len(navdata)
12252
navdata = solve_fde(navdata,
12353
threshold=-np.inf,
@@ -130,38 +60,38 @@ def test_solve_fde(derived, method):
13060
np.array([0]))
13161
assert len(navdata) == original_length - num_unknown - 6
13262

133-
def test_fde_fails(derived):
63+
def test_fde_fails(derived_2022):
13464
"""Test that solve_fde fails when it should.
13565
13666
Parameters
13767
----------
138-
derived : AndroidDerived2022
68+
derived_2022 : AndroidDerived2022
13969
Instance of AndroidDerived2022 for testing.
14070
14171
"""
14272

14373
with pytest.raises(ValueError) as excinfo:
144-
solve_fde(derived, method="perfect_method")
74+
solve_fde(derived_2022, method="perfect_method")
14575
assert "invalid method" in str(excinfo.value)
14676

14777
@pytest.mark.parametrize('method',
14878
[
14979
"residual",
15080
"edm",
15181
])
152-
def test_evaluate_fde(derived, method):
82+
def test_evaluate_fde(derived_2022, method):
15383
"""Evaluate FDE methods.
15484
15585
Parameters
15686
----------
157-
derived : AndroidDerived2022
87+
derived_2022 : AndroidDerived2022
15888
Instance of AndroidDerived2022 for testing.
15989
method : string
16090
Method for fault detection and exclusion.
16191
16292
"""
16393

164-
navdata = derived.copy()
94+
navdata = derived_2022.copy()
16595
evaluate_fde(navdata,
16696
method=method,
16797
fault_truth_row="MultipathIndicator",

0 commit comments

Comments
 (0)