Skip to content

Commit

Permalink
conf, #296: Also print the subclasses of each configurable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ankostis committed Sep 21, 2016
1 parent eefb9bb commit ea395a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
3 changes: 2 additions & 1 deletion traitlets/config/configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ class defaults.
"""
assert inst is None or isinstance(inst, cls)
final_help = []
final_help.append(u'%s options' % cls.__name__)
base_classes = ','.join(p.__name__ for p in cls.__bases__)
final_help.append(u'%s(%s) options' % (cls.__name__, base_classes))
final_help.append(len(final_help[0])*u'-')
for k, v in sorted(cls.class_traits(config=True).items()):
help = cls.class_get_trait_help(v, inst)
Expand Down
40 changes: 20 additions & 20 deletions traitlets/config/tests/test_configurable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ class MyConfigurable(Configurable):
c = Unicode('no config')


mc_help=u"""MyConfigurable options
----------------------
mc_help=u"""MyConfigurable(Configurable) options
------------------------------------
--MyConfigurable.a=<Integer>
Default: 1
The integer a.
--MyConfigurable.b=<Float>
Default: 1.0
The integer b."""

mc_help_inst=u"""MyConfigurable options
----------------------
mc_help_inst=u"""MyConfigurable(Configurable) options
------------------------------------
--MyConfigurable.a=<Integer>
Current: 5
The integer a.
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_custom(self):
self.assertTrue(c3.config is config)
self.assertTrue(c1.config is c2.config)
self.assertTrue(c2.config is c3.config)

def test_inheritance(self):
config = Config()
config.MyConfigurable.a = 2
Expand Down Expand Up @@ -179,7 +179,7 @@ class MyParent2(MyParent):
pass

class TestParentConfigurable(TestCase):

def test_parent_config(self):
cfg = Config({
'MyParent' : {
Expand Down Expand Up @@ -275,11 +275,11 @@ class Containers(Configurable):
lis = List().tag(config=True)
def _lis_default(self):
return [-1]

s = Set().tag(config=True)
def _s_default(self):
return {'a'}

d = Dict().tag(config=True)
def _d_default(self):
return {'a' : 'b'}
Expand Down Expand Up @@ -346,22 +346,22 @@ def test_dict_update(self):
c.Containers.d.update({'e' : 'f'})
obj = Containers(config=c)
self.assertEqual(obj.d, {'a':'b', 'c':'d', 'e':'f'})

def test_update_twice(self):
c = Config()
c.MyConfigurable.a = 5
m = MyConfigurable(config=c)
self.assertEqual(m.a, 5)

c2 = Config()
c2.MyConfigurable.a = 10
m.update_config(c2)
self.assertEqual(m.a, 10)

c2.MyConfigurable.a = 15
m.update_config(c2)
self.assertEqual(m.a, 15)

def test_update_self(self):
"""update_config with same config object still triggers config_changed"""
c = Config()
Expand All @@ -371,7 +371,7 @@ def test_update_self(self):
c.MyConfigurable.a = 10
m.update_config(c)
self.assertEqual(m.a, 10)

def test_config_default(self):
class SomeSingleton(SingletonConfigurable):
pass
Expand All @@ -388,9 +388,9 @@ def _config_default(self):

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)
Expand All @@ -415,9 +415,9 @@ def _config_default(self):

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)
Expand All @@ -429,22 +429,22 @@ class A(LoggingConfigurable):
foo = Integer(config=True)
bar = Integer(config=True)
baz = Integer(config=True)

@mark.skipif(not hasattr(TestCase, 'assertLogs'), reason='requires TestCase.assertLogs')
def test_warn_match(self):
logger = logging.getLogger('test_warn_match')
cfg = Config({'A': {'bat': 5}})
with self.assertLogs(logger, logging.WARNING) as captured:
a = TestLogger.A(config=cfg, log=logger)

output = '\n'.join(captured.output)
self.assertIn('Did you mean one of: `bar, baz`?', output)
self.assertIn('Config option `bat` not recognized by `A`.', output)

cfg = Config({'A': {'fool': 5}})
with self.assertLogs(logger, logging.WARNING) as captured:
a = TestLogger.A(config=cfg, log=logger)

output = '\n'.join(captured.output)
self.assertIn('Config option `fool` not recognized by `A`.', output)
self.assertIn('Did you mean `foo`?', output)
Expand Down

0 comments on commit ea395a3

Please sign in to comment.