Skip to content

Commit

Permalink
Adding tests for new code.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Sep 19, 2024
1 parent 0610813 commit 92e3285
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions firecrown/connector/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ def asdict(self) -> dict[str, float | list[float]]:
cosmo_dict["A_s"] = self.A_s
if self.sigma8 is not None:
cosmo_dict["sigma8"] = self.sigma8
if self.Omega_g is not None:
cosmo_dict["Omega_g"] = self.Omega_g
# Currently we do not support Omega_g
# if self.Omega_g is not None:
# cosmo_dict["Omega_g"] = self.Omega_g
if self.m_nu is not None:
cosmo_dict["m_nu"] = self.m_nu

Expand Down
13 changes: 13 additions & 0 deletions tests/likelihood/test_likelihood.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,16 @@ def test_load_likelihood_not_in_path():
"lkscript_not_in_path.",
):
_ = load_likelihood("lkscript_not_in_path", NamedParameters())


def test_load_likelihood_from_module_function_missing_likelihood_config():
dir_path = os.path.dirname(os.path.realpath(__file__))
module_path = os.path.join(dir_path, "lkdir")

sys.path.append(module_path)

with pytest.raises(KeyError, match="likelihood_config"):
_ = load_likelihood_from_module(
"firecrown.likelihood.factories.build_two_point_likelihood",
NamedParameters(),
)
14 changes: 14 additions & 0 deletions tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ def test_params_map():
_ = my_params.get_from_prefix_param(None, "no_such_name")


def test_params_map_wrong_type():
with pytest.raises(
TypeError, match="Value for parameter a is not a float or a list of floats.*"
):
_ = ParamsMap({"a": "not a float or a list of floats"})


def test_params_map_wrong_type_list():
with pytest.raises(
TypeError, match="Value for parameter a is not a float or a list of floats.*"
):
_ = ParamsMap({"a": ["not a float or a list of floats"]})


def test_parameter_get_full_name_reject_empty_name():
with pytest.raises(ValueError):
_ = parameter_get_full_name(None, "")
Expand Down

0 comments on commit 92e3285

Please sign in to comment.