diff --git a/requirements.txt b/requirements.txt index 1b7318e6cb811a64c33f6e8b1b55c53e36bfecc7..636cb022bbb446aa2d3eb86133f7b5fdc72d9fb9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ NRSur7dq2 nestle deepdish ptemcee +mock diff --git a/test/prior_tests.py b/test/prior_tests.py index 2575854cc00c19fc7aed126ff402e2ff1561bd83..6bc4853296cc826c978dec8a1607aa65eb8482eb 100644 --- a/test/prior_tests.py +++ b/test/prior_tests.py @@ -1,5 +1,6 @@ from context import tupak import unittest +from mock import Mock import numpy as np @@ -153,5 +154,41 @@ class TestPriorClasses(unittest.TestCase): self.assertAlmostEqual(np.trapz(prior.prob(domain), domain), 1, 3) +class TestFillPrior(unittest.TestCase): + + def setUp(self): + self.likelihood = Mock() + self.likelihood.parameters = dict(a=0, b=0, c=0, d=0, asdf=0, ra=1) + self.priors = dict(a=1, b=1.1, c='string', d=tupak.prior.Uniform(0, 1)) + self.priors = tupak.prior.fill_priors(self.priors, self.likelihood) + + def tearDown(self): + del self.likelihood + del self.priors + + def test_prior_instances_are_not_changed_by_parsing(self): + self.assertIsInstance(self.priors['d'], tupak.prior.Uniform) + + def test_parsing_ints_to_delta_priors_class(self): + self.assertIsInstance(self.priors['a'], tupak.prior.DeltaFunction) + + def test_parsing_ints_to_delta_priors_with_right_value(self): + self.assertEqual(self.priors['a'].peak, 1) + + def test_parsing_floats_to_delta_priors_class(self): + self.assertIsInstance(self.priors['b'], tupak.prior.DeltaFunction) + + def test_parsing_floats_to_delta_priors_with_right_value(self): + self.assertAlmostEqual(self.priors['b'].peak, 1.1, 1e-8) + + def test_without_available_default_priors_no_prior_is_set(self): + with self.assertRaises(KeyError): + print(self.priors['asdf']) + + def test_with_available_default_priors_a_default_prior_is_set(self): + self.assertIsInstance(self.priors['ra'], tupak.prior.Uniform) + + + if __name__ == '__main__': unittest.main()