From acbb0ba1957fed082cbf9a589659b236dc6e4f46 2017-05-11 19:17:40 From: Sang Min Park Date: 2017-05-11 19:17:40 Subject: [PATCH] Sort and unique %config results --- diff --git a/IPython/core/magics/config.py b/IPython/core/magics/config.py index 230a2c6..044614b 100644 --- a/IPython/core/magics/config.py +++ b/IPython/core/magics/config.py @@ -108,8 +108,9 @@ class ConfigMagics(Magics): # some IPython objects are Configurable, but do not yet have # any configurable traits. Exclude them from the effects of # this magic, as their presence is just noise: - configurables = [ c for c in self.shell.configurables - if c.__class__.class_traits(config=True) ] + configurables = sorted(set([ c for c in self.shell.configurables + if c.__class__.class_traits(config=True) + ]), key=lambda x: x.__class__.__name__) classnames = [ c.__class__.__name__ for c in configurables ] line = s.strip() diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index dd26ba9..0ab5bb7 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -80,6 +80,24 @@ def test_config(): ## should not raise. _ip.magic('config') +def test_config_available_configs(): + """ test that config magic prints available configs in unique and + sorted order. """ + with capture_output() as captured: + _ip.magic('config') + + stdout = captured.stdout + config_classes = stdout.strip().split('\n')[1:] + nt.assert_list_equal(config_classes, sorted(set(config_classes))) + +def test_config_print_class(): + """ test that config with a classname prints the class's options. """ + with capture_output() as captured: + _ip.magic('config TerminalInteractiveShell') + + stdout = captured.stdout + nt.assert_in("TerminalInteractiveShell options", stdout) + def test_rehashx(): # clear up everything _ip.alias_manager.clear_aliases()