def test_validate_specific(): """Test method ``validate`` for specific values.""" value = default_cosmology.validate(None) assert value is realizations.Planck18 with pytest.warns(AstropyDeprecationWarning) as e: value = default_cosmology.validate("Planck18_arXiv_v2") assert "use Planck18 instead" in str(e.list[0].message) assert value is realizations.Planck18_arXiv_v2 with pytest.raises(TypeError) as e: default_cosmology.validate(TypeError) assert "string or Cosmology instance" in str(e.value)
def test_validate_fail(self): """Test :meth:`astropy.cosmology.default_cosmology.validate`.""" # bad input type with pytest.raises(TypeError, match="must be a string or Cosmology"): default_cosmology.validate(TypeError) # a not-valid option, but still a str with pytest.raises(ValueError, match="Unknown cosmology"): default_cosmology.validate("fail!") # a not-valid type with pytest.raises(TypeError, match="cannot find a Cosmology"): default_cosmology.validate("available")
def test_validate_no_default(self): """Test :meth:`astropy.cosmology.default_cosmology.get` to `None`.""" cosmo = default_cosmology.validate("no_default") assert cosmo is None
def test_validate_cosmo(self, name): """Test method ``validate`` for cosmology instance input.""" cosmo = getattr(realizations, name) value = default_cosmology.validate(cosmo) assert value is cosmo
def test_validate_str(self, name): """Test method ``validate`` for string input.""" value = default_cosmology.validate(name) assert value is getattr(realizations, name)
def test_validate_default(self): """Test method ``validate`` for specific values.""" value = default_cosmology.validate(None) assert value is realizations.Planck18
def test_get_current(self): """Test :meth:`astropy.cosmology.default_cosmology.get` current value.""" cosmo = default_cosmology.get() assert cosmo is default_cosmology.validate(default_cosmology._value)
def test_validate_fail(self): """Test :meth:`astropy.cosmology.default_cosmology.validate`.""" # bad input type with pytest.raises(TypeError, match="must be a string or Cosmology"): default_cosmology.validate(TypeError)