def test_config_default_deprecated(self): """Make sure configurables work even with the deprecations in traitlets""" class SomeSingleton(SingletonConfigurable): pass # reset deprecation limiter _deprecations_shown.clear() with expected_warnings([]): class DefaultConfigurable(Configurable): a = Integer(config=True) def _config_default(self): if SomeSingleton.initialized(): return SomeSingleton.instance().config return Config() c = Config() c.DefaultConfigurable.a = 5 d1 = DefaultConfigurable() self.assertEqual(d1.a, 0) single = SomeSingleton.instance(config=c) d2 = DefaultConfigurable() self.assertIs(d2.config, single.config) self.assertEqual(d2.a, 5)
def test_config_default_deprecated(self): """Make sure configurables work even with the deprecations in traitlets""" class SomeSingleton(SingletonConfigurable): pass # reset deprecation limiter _deprecations_shown.clear() with expected_warnings(["metadata should be set using the \.tag\(\) method"]): class DefaultConfigurable(Configurable): a = Integer(config=True) def _config_default(self): if SomeSingleton.initialized(): return SomeSingleton.instance().config return Config() c = Config() c.DefaultConfigurable.a = 5 d1 = DefaultConfigurable() self.assertEqual(d1.a, 0) single = SomeSingleton.instance(config=c) d2 = DefaultConfigurable() self.assertIs(d2.config, single.config) self.assertEqual(d2.a, 5)