Ejemplo n.º 1
0
    def test_init_subclass(self, cosmo_cls):
        """Test initializing subclass, mostly that can't have Ode0 in init."""
        super().test_init_subclass(cosmo_cls)

        with pytest.raises(TypeError, match="subclasses of"):

            class HASOde0SubClass(cosmo_cls):
                def __init__(self, Ode0):
                    pass

            _COSMOLOGY_CLASSES.pop(HASOde0SubClass.__qualname__, None)
Ejemplo n.º 2
0
    def test_Parameter_doesnt_change_with_cosmology(self, cosmo_cls):
        """Cosmology reinitializes all descriptors when a subclass is defined."""

        # define subclass to show param is same
        class Example(cosmo_cls): pass

        assert Example.param is cosmo_cls.param

        # unregister
        _COSMOLOGY_CLASSES.pop(Example.__qualname__)
        assert Example.__qualname__ not in _COSMOLOGY_CLASSES
Ejemplo n.º 3
0
    def setup(self):
        """Setup and teardown for tests."""

        class CosmologyWithKwargs(Cosmology):
            Tcmb0 = Parameter(unit=u.K)

            def __init__(self, Tcmb0=0, name="cosmology with kwargs", meta=None, **kwargs):
                super().__init__(name=name, meta=meta)
                self._Tcmb0 = Tcmb0 << u.K

        yield  # run tests

        # pop CosmologyWithKwargs from registered classes
        # but don't error b/c it can fail in parallel
        _COSMOLOGY_CLASSES.pop(CosmologyWithKwargs.__qualname__, None)
Ejemplo n.º 4
0
    def test_init_subclass(self, cosmo_cls):
        """Test creating subclasses registers classes and manages Parameters."""
        class InitSubclassTest(cosmo_cls):
            pass

        # test parameters
        assert InitSubclassTest.__parameters__ == cosmo_cls.__parameters__

        # test and cleanup registry
        registrant = _COSMOLOGY_CLASSES.pop(InitSubclassTest.__qualname__)
        assert registrant is InitSubclassTest
Ejemplo n.º 5
0
 def teardown_class(self):
     super().teardown_class(self)
     _COSMOLOGY_CLASSES.pop("TestFLRW.setup_class.<locals>.SubFLRW", None)
Ejemplo n.º 6
0
 def teardown_class(self):
     _COSMOLOGY_CLASSES.pop("SubCosmology", None)
Ejemplo n.º 7
0
 def teardown_class(self):
     for cls in self.classes.values():
         _COSMOLOGY_CLASSES.pop(cls.__qualname__)
Ejemplo n.º 8
0
def teardown_module(module):
    # pop CosmologyWithKwargs from registered classes
    # but don't error b/c it fails in parallel
    _COSMOLOGY_CLASSES.pop(CosmologyWithKwargs.__qualname__, None)
Ejemplo n.º 9
0
 def teardown_class(self):
     super().teardown_class(self)
     _COSMOLOGY_CLASSES.pop("SubFLRW", None)
Ejemplo n.º 10
0
 def teardown_class(self):
     _COSMOLOGY_CLASSES.pop("TestCosmology.setup_class.<locals>.SubCosmology", None)