Skip to content

Commit

Permalink
Close test gap on filter.py (#126)
Browse files Browse the repository at this point in the history
* WIP - testing are failing to find a default filter file.

* Using new test fixture to set the environment variables to point to test/data.
  • Loading branch information
drewoldag authored May 10, 2024
1 parent aee2c9e commit c681b48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ def data_registry_file(test_data_dir):
def unset_env_vars():
os.environ.pop("LEPHAREDIR", None)
os.environ.pop("LEPHAREWORK", None)


@pytest.fixture
def set_env_vars():
test_dir = os.path.abspath(os.path.dirname(__file__))
os.environ["LEPHAREDIR"] = os.path.join(test_dir, "data")
os.environ["LEPHAREWORK"] = os.path.join(test_dir, "tmp")
21 changes: 21 additions & 0 deletions tests/lephare/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np
import pytest
from lephare import (
Filter,
flt, # noqa: E402
)
from lephare.filterSvc import FilterSvc # noqa: E402
Expand Down Expand Up @@ -37,3 +38,23 @@ def test_filtersvc(test_data_dir, filter_file):
# filters in COSMOS.para not available to the unit tests
fltvec = FilterSvc.from_config(os.path.join(test_data_dir, "examples/COSMOS.para"))
assert len(fltvec) == 1


def test_filter_base_class(test_data_dir, set_env_vars):
"""Simple test to ensure that we can create an instance of a Filter object."""
config_file_path = os.path.join(test_data_dir, "examples/COSMOS.para")
filter = Filter(config_file=config_file_path)
filter.run()
assert len(filter.keymap)


def test_filter_with_kwargs(test_data_dir, set_env_vars):
"""Simple test to ensure that we can create an instance of a Filter object
and that we can pass kwargs when instantiating the object."""
config_file_path = os.path.join(test_data_dir, "examples/COSMOS.para")
input_args = {"verbose": True, "TRANS_TYPE": 42}
filter = Filter(config_file=config_file_path)
filter.run(**input_args)
assert len(filter.keymap)
assert filter.verbose
assert filter.keymap["TRANS_TYPE"].value == "42"

0 comments on commit c681b48

Please sign in to comment.