コード例 #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)
コード例 #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
コード例 #3
0
ファイル: base.py プロジェクト: lpsinger/astropy
    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)
コード例 #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
コード例 #5
0
 def teardown_class(self):
     super().teardown_class(self)
     _COSMOLOGY_CLASSES.pop("TestFLRW.setup_class.<locals>.SubFLRW", None)
コード例 #6
0
 def teardown_class(self):
     _COSMOLOGY_CLASSES.pop("SubCosmology", None)
コード例 #7
0
ファイル: test_parameter.py プロジェクト: lpsinger/astropy
 def teardown_class(self):
     for cls in self.classes.values():
         _COSMOLOGY_CLASSES.pop(cls.__qualname__)
コード例 #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)
コード例 #9
0
 def teardown_class(self):
     super().teardown_class(self)
     _COSMOLOGY_CLASSES.pop("SubFLRW", None)
コード例 #10
0
 def teardown_class(self):
     _COSMOLOGY_CLASSES.pop("TestCosmology.setup_class.<locals>.SubCosmology", None)