Commit f2816d20 authored by Babouh's avatar Babouh
Browse files

Use pytest parametrize and skip nenufar tests if nenupy is not installed

parent 18efb2a2
......@@ -3,6 +3,14 @@ from pathlib import Path
import pytest
import requests
# try importing nenupy
try:
import nenupy
except ImportError:
# if nenupy is not available, skip the corresponding tests
nenupy = None
__all__ = ["load_test_data"]
# remote test data url
......@@ -341,7 +349,20 @@ def test_filepaths():
cur_dir_name = cur_db_name / dataset_name
for file_data in DATA_FILES[database_name][dataset_name]:
file_name, file_dataset = file_data[0:2]
filepaths.append((cur_dir_name / file_name, file_dataset))
if file_dataset == "srn_nenufar_bst":
pytest_param = pytest.param(
cur_dir_name / file_name,
file_dataset,
marks=pytest.mark.skipif(
nenupy is None,
reason="the nenupy package is required to run nenufar dataset tests",
),
)
else:
pytest_param = (cur_dir_name / file_name, file_dataset)
filepaths.append(pytest_param)
return filepaths
......
......@@ -39,41 +39,47 @@ def test_bin_dataset():
assert isinstance(data, BinData)
def test_any_dataset():
for filepath, dataset in test_filepaths():
try:
data = Data(filepath)
assert data.dataset == dataset
except NotImplementedError:
print(f"Dataset not implemented {str(filepath)}")
@pytest.mark.parametrize("filepath,dataset", test_filepaths())
def test_any_dataset(filepath, dataset):
try:
data = Data(filepath)
assert data.dataset == dataset
except NotImplementedError:
print(f"Dataset not implemented {str(filepath)}")
# TEST TEMPLATE
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset():
pass
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset__times():
pass
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset__frequencies():
pass
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset__sweeps__load_data_false():
pass
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset__sweeps_for_loop():
pass
@pytest.mark.test_data_required
@pytest.mark.skip(reason="not implemented")
def test___bin_dataset__sweeps_next():
pass
......@@ -12,6 +12,13 @@ from spacepy import pycdf
from astropy.io import fits
import pytest
# try importing nenupy
try:
import nenupy
except ImportError:
# if nenupy is not available, skip the corresponding tests
nenupy = None
BASEDIR = Path(__file__).resolve().parent / "data"
......@@ -93,6 +100,9 @@ def test_srn_nda_routine_jup_edr_dataset__access_mode_error():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset():
for filepath in TEST_FILES["srn_nenufar_bst"]:
data = Data(filepath=filepath)
......@@ -100,6 +110,9 @@ def test_nenufar_bst_dataset():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__beam():
for filepath in TEST_FILES["srn_nenufar_bst"]:
data = Data(filepath=filepath, beam=1)
......@@ -107,6 +120,9 @@ def test_nenufar_bst_dataset__beam():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__beam__value_error():
for filepath in TEST_FILES["srn_nenufar_bst"]:
with pytest.raises(ValueError):
......@@ -114,6 +130,9 @@ def test_nenufar_bst_dataset__beam__value_error():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__access_mode_file():
for filepath in TEST_FILES["srn_nenufar_bst"]:
with Data(filepath=filepath, access_mode="file") as data:
......@@ -121,6 +140,9 @@ def test_nenufar_bst_dataset__access_mode_file():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__times():
filepath = TEST_FILES["srn_nenufar_bst"][0]
with Data(filepath=filepath) as data:
......@@ -131,6 +153,9 @@ def test_nenufar_bst_dataset__times():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__times__other_beam():
filepath = TEST_FILES["srn_nenufar_bst"][0]
with Data(filepath=filepath, beam=1) as data:
......@@ -141,6 +166,9 @@ def test_nenufar_bst_dataset__times__other_beam():
@pytest.mark.test_data_required
@pytest.mark.skipif(
nenupy is None, reason="the nenupy package is required to run nenufar dataset tests"
)
def test_nenufar_bst_dataset__frequencies():
filepath = TEST_FILES["srn_nenufar_bst"][0]
with Data(filepath=filepath) as data:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment