From 986a9b4768255fe0ce1571a8aa95f4a060c07b71 Mon Sep 17 00:00:00 2001 From: "Morten W. Hansen" Date: Fri, 26 Apr 2024 14:15:04 +0200 Subject: [PATCH] #15: fix syntax --- tests/conftest.py | 4 +++- tests/test_sarwind.py | 23 ++++++----------------- tests/test_scripts.py | 2 +- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index cc1a86b..bb148db 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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 @@ -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 diff --git a/tests/test_sarwind.py b/tests/test_sarwind.py index 703de0f..76ff4ea 100644 --- a/tests/test_sarwind.py +++ b/tests/test_sarwind.py @@ -1,5 +1,4 @@ import os -import sys import pytest import tempfile @@ -9,10 +8,11 @@ nansat_installed = True try: - import nansat + import nansat # noqa except ModuleNotFoundError: nansat_installed = False + class SelectMock(Mock): pass @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 1144c6a..6bfa31a 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -11,7 +11,7 @@ nansat_installed = True try: - import nansat + import nansat # noqa except ModuleNotFoundError: nansat_installed = False else: