Skip to content

Commit f0eed7a

Browse files
committed
Refactor test paths
1 parent 7035132 commit f0eed7a

File tree

6 files changed

+45
-52
lines changed

6 files changed

+45
-52
lines changed

tests/__init__.py

Whitespace-only changes.

tests/test_pyglider.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1-
from pathlib import Path
2-
31
import numpy as np
42
import pytest
53
import xarray as xr
64
import yaml
75

86
import pyglider.seaexplorer as seaexplorer
9-
10-
library_dir = Path(__file__).parent.parent.absolute()
11-
example_dir = library_dir / 'tests/example-data/'
7+
from tests.utils import EXAMPLE_DIR, LIBRARY_DIR
128

139
# Create an L0 timeseries from seaexplorer data and test that the resulting netcdf
1410
# is identical to the test data
15-
rawdir = str(example_dir / 'example-seaexplorer/realtime_raw/') + '/'
16-
rawncdir = str(example_dir / 'example-seaexplorer/realtime_rawnc/') + '/'
17-
deploymentyaml = str(example_dir / 'example-seaexplorer/deploymentRealtime.yml')
18-
l0tsdir = str(example_dir / 'example-seaexplorer/L0-timeseries-test/') + '/'
11+
rawdir = str(EXAMPLE_DIR / 'example-seaexplorer/realtime_raw/') + '/'
12+
rawncdir = str(EXAMPLE_DIR / 'example-seaexplorer/realtime_rawnc/') + '/'
13+
deploymentyaml = str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml')
14+
l0tsdir = str(EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test/') + '/'
1915
seaexplorer.raw_to_rawnc(rawdir, rawncdir, deploymentyaml)
2016
seaexplorer.merge_parquet(rawncdir, rawncdir, deploymentyaml, kind='sub')
2117
outname = seaexplorer.raw_to_L0timeseries(rawncdir, l0tsdir, deploymentyaml, kind='sub')
2218
output = xr.open_dataset(outname)
2319
# Open test data file
2420
test_data = xr.open_dataset(
25-
library_dir
21+
LIBRARY_DIR
2622
/ 'tests/expected/example-seaexplorer/L0-timeseries/dfo-eva035-20190718.nc'
2723
)
2824
variables = list(output.variables)
@@ -61,12 +57,12 @@ def test_example_seaexplorer_metadata():
6157
# Test that interpolation over nans does not change the output with nrt data
6258
with open(deploymentyaml) as fin:
6359
deployment = yaml.safe_load(fin)
64-
interp_yaml = str(example_dir / 'example-seaexplorer/deploymentRealtimeInterp.yml')
60+
interp_yaml = str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtimeInterp.yml')
6561
deployment['netcdf_variables']['interpolate'] = True
6662
with open(interp_yaml, 'w') as fout:
6763
yaml.dump(deployment, fout)
6864
l0tsdir_interp = (
69-
str(example_dir / 'example-seaexplorer/L0-timeseries-test-interp/') + '/'
65+
str(EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test-interp/') + '/'
7066
)
7167

7268
outname_interp = seaexplorer.raw_to_L0timeseries(
@@ -91,10 +87,10 @@ def test_example_seaexplorer_interp_nrt(var):
9187

9288

9389
# Test raw (full resolution) seaexplorer data.
94-
rawdir = str(example_dir / 'example-seaexplorer-raw/delayed_raw/') + '/'
95-
rawncdir = str(example_dir / 'example-seaexplorer-raw/delayed_rawnc/') + '/'
96-
deploymentyaml_raw = str(example_dir / 'example-seaexplorer-raw/deployment.yml')
97-
l0tsdir = str(example_dir / 'example-seaexplorer-raw/L0-timeseries-test/') + '/'
90+
rawdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_raw/') + '/'
91+
rawncdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_rawnc/') + '/'
92+
deploymentyaml_raw = str(EXAMPLE_DIR / 'example-seaexplorer-raw/deployment.yml')
93+
l0tsdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test/') + '/'
9894
seaexplorer.raw_to_rawnc(rawdir, rawncdir, deploymentyaml_raw)
9995
seaexplorer.merge_parquet(rawncdir, rawncdir, deploymentyaml_raw, kind='raw')
10096
outname_raw = seaexplorer.raw_to_L0timeseries(
@@ -103,7 +99,7 @@ def test_example_seaexplorer_interp_nrt(var):
10399
output_raw = xr.open_dataset(outname_raw)
104100
# Open test data file
105101
test_data_raw = xr.open_dataset(
106-
library_dir
102+
LIBRARY_DIR
107103
/ 'tests/expected/example-seaexplorer-raw/L0-timeseries/dfo-bb046-20200908.nc'
108104
)
109105

@@ -138,12 +134,12 @@ def test_example_seaexplorer_metadata_raw():
138134
# Test that interpolation over nans in raw data results in a greater or equal number of non-nan values
139135
with open(deploymentyaml_raw) as fin:
140136
deployment_raw = yaml.safe_load(fin)
141-
interp_yaml = str(example_dir / 'example-seaexplorer-raw/deploymentDelayedInterp.yml')
137+
interp_yaml = str(EXAMPLE_DIR / 'example-seaexplorer-raw/deploymentDelayedInterp.yml')
142138
deployment_raw['netcdf_variables']['interpolate'] = True
143139
with open(interp_yaml, 'w') as fout:
144140
yaml.dump(deployment_raw, fout)
145141
l0tsdir_interp_raw = (
146-
str(example_dir / 'example-seaexplorer-raw/L0-timeseries-test-interp/') + '/'
142+
str(EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test-interp/') + '/'
147143
)
148144

149145
outname_interp_raw = seaexplorer.raw_to_L0timeseries(

tests/test_seaexplorer.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import os
2-
from pathlib import Path
32

43
import numpy as np
54
import polars as pl
65
import pytest
76
import yaml
87

98
os.system('rm tests/data/realtime_rawnc/*')
10-
library_dir = Path(__file__).parent.parent.absolute()
11-
example_dir = library_dir / 'tests/example-data/'
129

1310
import pyglider.seaexplorer as seaexplorer
11+
from tests.utils import EXAMPLE_DIR
1412

1513

1614
def test__outputname():
@@ -67,13 +65,13 @@ def test_merge_rawnc():
6765
result_default = seaexplorer.merge_parquet(
6866
'tests/data/realtime_rawnc/',
6967
'tests/data/realtime_rawnc/',
70-
str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'),
68+
str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'),
7169
)
7270

7371
result_sub = seaexplorer.merge_parquet(
7472
'tests/data/realtime_rawnc/',
7573
'tests/data/realtime_rawnc/',
76-
str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'),
74+
str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'),
7775
kind='sub',
7876
)
7977
assert result_default is False
@@ -107,12 +105,12 @@ def test_raw_to_timeseries():
107105
result_default = seaexplorer.raw_to_timeseries(
108106
'tests/data/realtime_rawnc/',
109107
'tests/data/l0-profiles/',
110-
str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'),
108+
str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'),
111109
)
112110
result_sub = seaexplorer.raw_to_timeseries(
113111
'tests/data/realtime_rawnc/',
114112
'tests/data/l0-profiles/',
115-
str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'),
113+
str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'),
116114
kind='sub',
117115
)
118116
assert 'No such file or directory' in str(missing_file_exc)
@@ -121,26 +119,26 @@ def test_raw_to_timeseries():
121119

122120
def test_missing_bad_timebase():
123121
# Prepare yaml files with bad timebase and no timebase
124-
with open(example_dir / 'example-seaexplorer/deploymentRealtime.yml') as fin:
122+
with open(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml') as fin:
125123
deployment = yaml.safe_load(fin)
126124
deployment['netcdf_variables']['timebase']['source'] = 'non existing sensor'
127-
with open(example_dir / 'example-seaexplorer/bad_timebase.yml', 'w') as fin:
125+
with open(EXAMPLE_DIR / 'example-seaexplorer/bad_timebase.yml', 'w') as fin:
128126
yaml.dump(deployment, fin)
129127
deployment['netcdf_variables'].pop('timebase')
130-
with open(example_dir / 'example-seaexplorer/no_timebase.yml', 'w') as fin:
128+
with open(EXAMPLE_DIR / 'example-seaexplorer/no_timebase.yml', 'w') as fin:
131129
yaml.dump(deployment, fin)
132130
with pytest.raises(ValueError) as bad_timebase_exc:
133131
result_bad_timebase = seaexplorer.raw_to_timeseries(
134132
'tests/data/realtime_rawnc/',
135133
'tests/data/l0-profiles/',
136-
str(example_dir / 'example-seaexplorer/bad_timebase.yml'),
134+
str(EXAMPLE_DIR / 'example-seaexplorer/bad_timebase.yml'),
137135
kind='sub',
138136
)
139137
with pytest.raises(ValueError) as no_timebase_exc:
140138
result_no_timebase = seaexplorer.raw_to_timeseries(
141139
'tests/data/realtime_rawnc/',
142140
'tests/data/l0-profiles/',
143-
str(example_dir / 'example-seaexplorer/no_timebase.yml'),
141+
str(EXAMPLE_DIR / 'example-seaexplorer/no_timebase.yml'),
144142
kind='sub',
145143
)
146144
assert 'sensor not found in pld1 columns' in str(bad_timebase_exc)

tests/test_slocum.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import json
2-
from pathlib import Path
32

43
import numpy as np
54
import pytest
@@ -8,21 +7,19 @@
87

98
import pyglider.ncprocess as ncprocess
109
import pyglider.slocum as slocum
11-
12-
library_dir = Path(__file__).parent.parent.absolute()
13-
example_dir = library_dir / 'tests/example-data/'
10+
from tests.utils import EXAMPLE_DIR, LIBRARY_DIR
1411

1512
# Create an L0 timeseries from slocum data and test that the resulting netcdf is
1613
# identical to the test data
17-
cacdir = example_dir / 'example-slocum/cac/'
18-
sensorlist = str(example_dir / 'example-slocum/dfo-rosie713_sensors.txt')
19-
binarydir = str(example_dir / 'example-slocum/realtime_raw/') + '/'
20-
rawdir_slocum = str(example_dir / 'example-slocum/realtime_rawnc/') + '/'
21-
deploymentyaml_slocum = str(example_dir / 'example-slocum/deploymentRealtime.yml')
22-
tsdir = str(example_dir / 'example-slocum/L0-timeseries/') + '/'
14+
cacdir = EXAMPLE_DIR / 'example-slocum/cac/'
15+
sensorlist = str(EXAMPLE_DIR / 'example-slocum/dfo-rosie713_sensors.txt')
16+
binarydir = str(EXAMPLE_DIR / 'example-slocum/realtime_raw/') + '/'
17+
rawdir_slocum = str(EXAMPLE_DIR / 'example-slocum/realtime_rawnc/') + '/'
18+
deploymentyaml_slocum = str(EXAMPLE_DIR / 'example-slocum/deploymentRealtime.yml')
19+
tsdir = str(EXAMPLE_DIR / 'example-slocum/L0-timeseries/') + '/'
2320
scisuffix = 'tbd'
2421
glidersuffix = 'sbd'
25-
profiledir = str(example_dir / 'example-slocum/L0-profiles/')
22+
profiledir = str(EXAMPLE_DIR / 'example-slocum/L0-profiles/')
2623
do_direct = True
2724

2825
# This needs to get run every time the tests are run, so do at top level:
@@ -45,7 +42,7 @@
4542
output_slocum = xr.open_dataset(outname_slocum)
4643
# Open test data file
4744
test_data_slocum = xr.open_dataset(
48-
library_dir / 'tests/expected/example-slocum/L0-timeseries/dfo-rosie713-20190615.nc'
45+
LIBRARY_DIR / 'tests/expected/example-slocum/L0-timeseries/dfo-rosie713-20190615.nc'
4946
)
5047
variables_slocum = list(output_slocum.variables)
5148

@@ -95,7 +92,7 @@ def test_profiles_compliant():
9592
checker_names = ['gliderdac', 'cf:1.8']
9693
verbose = 0
9794
criteria = 'normal'
98-
output_filename = example_dir / 'report.json'
95+
output_filename = EXAMPLE_DIR / 'report.json'
9996
output_format = 'json'
10097
"""
10198
Inputs to ComplianceChecker.run_checker
@@ -139,7 +136,7 @@ def test_timeseries_compliant():
139136
checker_names = ['cf:1.8']
140137
verbose = 0
141138
criteria = 'normal'
142-
output_filename = example_dir / 'report.json'
139+
output_filename = EXAMPLE_DIR / 'report.json'
143140
output_format = 'json'
144141
"""
145142
Inputs to ComplianceChecker.run_checker

tests/test_utils.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
from pathlib import Path
2-
31
import numpy as np
42
import pytest
53
import xarray as xr
64
import yaml
75

86
import pyglider.utils as utils
9-
10-
library_dir = Path(__file__).parent.parent.absolute()
11-
example_dir = library_dir / 'tests/example-data/'
7+
from tests.utils import EXAMPLE_DIR, LIBRARY_DIR
128

139
test_data = xr.open_dataset(
14-
library_dir
10+
LIBRARY_DIR
1511
/ 'tests/expected/example-seaexplorer/L0-timeseries/dfo-eva035-20190718.nc'
1612
)
1713
deploymentyaml = (
18-
example_dir / 'example-seaexplorer-legato-flntu-arod-ad2cp/deploymentRealtime.yml'
14+
EXAMPLE_DIR / 'example-seaexplorer-legato-flntu-arod-ad2cp/deploymentRealtime.yml'
1915
)
2016
with open(deploymentyaml) as fin:
2117
deployment = yaml.safe_load(fin)

tests/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Utilities specific to the test suite."""
2+
3+
from pathlib import Path
4+
5+
LIBRARY_DIR = Path(__file__).parent.parent.absolute()
6+
EXAMPLE_DIR = LIBRARY_DIR / 'tests/example-data/'

0 commit comments

Comments
 (0)