Skip to content

Commit

Permalink
#15: fix syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh committed Apr 26, 2024
1 parent 9a21fa3 commit 986a9b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self, *a, **k):

def set_metadata(self, *args, **kwargs):
return None

def has_band(self, *args, **kwargs):
return None

Expand All @@ -175,11 +175,13 @@ def get_metadata(self, *args, **kwargs):
def __getitem__(self, *args, **kwargs):
return None


class mocked_nansat:
"""Mock of nansat module
"""
Nansat = MockNansat


@pytest.fixture(scope="function")
def mock_nansat(monkeypatch):
"""Mocks nansat module and Nansat class
Expand Down
23 changes: 6 additions & 17 deletions tests/test_sarwind.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import pytest
import tempfile

Expand All @@ -9,10 +8,11 @@

nansat_installed = True
try:
import nansat
import nansat # noqa
except ModuleNotFoundError:
nansat_installed = False


class SelectMock(Mock):
pass

Expand Down Expand Up @@ -86,8 +86,8 @@ def testSARWind_get_model_wind_field(mock_nansat, arome, monkeypatch):
with monkeypatch.context() as mp:
smock = SelectMock()
smock.side_effect = [
np.array([0, 0]), #
np.array([1, 1]) #
np.array([0, 0]),
np.array([1, 1])
]
mp.setattr("sarwind.sarwind.Nansat.__getitem__", smock)

Expand Down Expand Up @@ -140,7 +140,7 @@ def testSARWind_set_related_dataset(mock_nansat, monkeypatch):
auxm = {"id": "d1863d82-47b3-4048-9dcd-b4dafc45eb7c"}
related_ds = w.set_related_dataset(metadata, auxm)
assert related_ds == "d1863d82-47b3-4048-9dcd-b4dafc45eb7c (auxiliary)"

metadata = {"id": "11d33864-75ea-4a36-9a4e-68c5b3e97853"}
auxm = {}
related_ds = w.set_related_dataset(metadata, auxm)
Expand Down Expand Up @@ -253,7 +253,7 @@ def testSARWind_set_related_dataset_with_nansat(monkeypatch, meps_20240416, s1a_
auxm = {"id": "d1863d82-47b3-4048-9dcd-b4dafc45eb7c"}
related_ds = w.set_related_dataset(metadata, auxm)
assert related_ds == "d1863d82-47b3-4048-9dcd-b4dafc45eb7c (auxiliary)"

metadata = {"id": "11d33864-75ea-4a36-9a4e-68c5b3e97853"}
auxm = {}
related_ds = w.set_related_dataset(metadata, auxm)
Expand All @@ -265,17 +265,6 @@ def testSARWind_set_related_dataset_with_nansat(monkeypatch, meps_20240416, s1a_
assert related_ds == ""




#reld = ("no.met:11d33864-75ea-4a36-9a4e-68c5b3e97853 (auxiliary), "
# "no.met:d1863d82-47b3-4048-9dcd-b4dafc45eb7c (auxiliary)")
#assert w.get_metadata("related_dataset") == reld
#with tempfile.NamedTemporaryFile(delete=True) as fp:
# w.export(filename=fp.name)
# assert os.path.isfile(fp.name)
#assert not os.path.isfile(fp.name)


@pytest.mark.skipif(not nansat_installed, reason="Only works when nansat is installed")
def testSARWind_export(monkeypatch, sarIW_SAFE, meps):
""" Test the export function
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

nansat_installed = True
try:
import nansat
import nansat # noqa
except ModuleNotFoundError:
nansat_installed = False
else:
Expand Down

0 comments on commit 986a9b4

Please sign in to comment.