Skip to content

Commit 44ea966

Browse files
committed
Add test workflow
1 parent 035d646 commit 44ea966

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

.github/workflows/python-app.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ jobs:
3131
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3232
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3333
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34-
# - name: Test with pytest
35-
# run: |
36-
# pytest
34+
- name: Test with pytest
35+
run: |
36+
pytest

tests/test_grid.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from py_eddy_tracker.dataset.grid import RegularGridDataset
2+
from py_eddy_tracker.data import get_path
3+
from matplotlib.path import Path
4+
from pytest import approx
5+
6+
G = RegularGridDataset(get_path("mask_1_60.nc"), "lon", "lat")
7+
X = 0.025
8+
contour = Path(((-X, 0), (X, 0), (X, X), (-X, X), (-X, 0),))
9+
10+
# contour
11+
def test_contour_lon():
12+
assert (contour.lon == (-X, X, X, -X, -X)).all()
13+
14+
15+
def test_contour_lat():
16+
assert (contour.lat == (0, 0, X, X, 0)).all()
17+
18+
19+
def test_contour_mean():
20+
assert (contour.mean_coordinates == (0, X / 2)).all()
21+
22+
23+
def test_contour_fit_circle():
24+
x, y, r, err = contour.fit_circle()
25+
assert x == approx(0)
26+
assert y == approx(X / 2)
27+
assert r == approx(3108, rel=1e-1)
28+
assert err == approx(49.1, rel=1e-1)
29+
30+
31+
def test_pixels_in():
32+
i, j = contour.pixels_in(G)
33+
assert (i == (21599, 0, 1)).all()
34+
assert (j == (5401, 5401, 5401)).all()
35+
36+
37+
def test_contour_grid_slice():
38+
assert contour.bbox_slice == ((21598, 4), (5400, 5404))
39+
40+
41+
# grid
42+
def test_bounds():
43+
x0, x1, y0, y1 = G.bounds
44+
assert x0 == -1 / 120.0 and x1 == 360 - 1 / 120
45+
assert y0 == approx(-90 - 1 / 120.0) and y1 == approx(90 - 1 / 120)
46+

tests/test_id.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from py_eddy_tracker.dataset.grid import RegularGridDataset
2+
from py_eddy_tracker.data import get_path
3+
from datetime import datetime
4+
5+
g = RegularGridDataset(
6+
get_path("dt_med_allsat_phy_l4_20160515_20190101.nc"), "longitude", "latitude"
7+
)
8+
9+
10+
def test_id():
11+
g.add_uv("adt")
12+
a, c = g.eddy_identification("adt", "u", "v", datetime(2019, 2, 23))
13+
assert len(a) == 35
14+
assert len(c) == 36

tests/test_obs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from py_eddy_tracker.observations.observation import EddiesObservations
2+
from py_eddy_tracker.data import get_path
3+
from netCDF4 import Dataset
4+
5+
a = EddiesObservations.load_file(get_path("Anticyclonic_20190223.nc"))
6+
c = EddiesObservations.load_file(get_path("Cyclonic_20190223.nc"))
7+
8+
9+
def test_merge():
10+
new = a.merge(c)
11+
assert len(new) == len(a) + len(c)
12+
13+
14+
# def test_write():
15+
# with Dataset

0 commit comments

Comments
 (0)