class Copy(TestCase): """Test copying a model correctly copies the underlying class data""" def setUp(self) -> None: self.model = SNModel(source=sncosmo_test_models.flatsource(), effects=[sncosmo.CCM89Dust()], effect_frames=['obs'], effect_names=['mw']) self.model.set(z=0.0001) def test_copy_returns_correct_type(self) -> None: """Test copied objects are of ``modeling.SNModel`` type""" copied = copy(self.model) self.assertIsInstance(copied, SNModel) def test_copy_copies_parameters(self) -> None: """Test parameter values are copied to new id values""" copied = copy(self.model) for original_param, copied_param in zip(self.model._parameters, copied.parameters): self.assertNotEqual(id(original_param), id(copied_param)) self.assertEqual(original_param, copied_param) def test_copied_parameters_are_not_linked(self) -> None: """Test parameters of a copied model are independent from the original model""" old_params = copy(self.model.parameters) copied_model = copy(self.model) copied_model.set(z=1) np.testing.assert_equal(old_params, self.model.parameters)
class SncosmoBaseTests(sncosmo_test_models.TestModel, TestCase): """Includes all tests written for the ``sncosmo.Model`` class.""" def setUp(self) -> None: # Same as the base sncosmo setup procedure, but using a ``SNModel`` # instance instead of ``sncosmo.Model`` self.model = SNModel(source=sncosmo_test_models.flatsource(), effects=[sncosmo.CCM89Dust()], effect_frames=['obs'], effect_names=['mw']) self.model.set(z=0.0001)