##// END OF EJS Templates
Merge pull request #7183 from minrk/global-config...
Matthias Bussonnier -
r19554:17b333fa merge
parent child Browse files
Show More
@@ -1,17 +1,7 b''
1 1 # encoding: utf-8
2 2
3 __docformat__ = "restructuredtext en"
4
5 #-------------------------------------------------------------------------------
6 # Copyright (C) 2008 The IPython Development Team
7 #
8 # Distributed under the terms of the BSD License. The full license is in
9 # the file COPYING, distributed as part of this software.
10 #-------------------------------------------------------------------------------
11
12 #-------------------------------------------------------------------------------
13 # Imports
14 #-------------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
15 5
16 6 from .application import *
17 7 from .configurable import *
@@ -609,3 +609,13 b" def boolean_flag(name, configurable, set_help='', unset_help=''):"
609 609 unsetter = {cls : {trait : False}}
610 610 return {name : (setter, set_help), 'no-'+name : (unsetter, unset_help)}
611 611
612
613 def get_config():
614 """Get the config object for the global Application instance, if there is one
615
616 otherwise return an empty config object
617 """
618 if Application.initialized():
619 return Application.instance().config
620 else:
621 return Config()
@@ -78,6 +78,9 b' class Configurable(HasTraits):'
78 78 # making that a class attribute.
79 79 # self.config = deepcopy(config)
80 80 self.config = config
81 else:
82 # allow _config_default to return something
83 self._load_config(self.config)
81 84 # This should go second so individual keyword arguments override
82 85 # the values in config.
83 86 super(Configurable, self).__init__(**kwargs)
@@ -1,23 +1,8 b''
1 1 # encoding: utf-8
2 """
3 Tests for IPython.config.configurable
2 """Tests for IPython.config.configurable"""
4 3
5 Authors:
6
7 * Brian Granger
8 * Fernando Perez (design help)
9 """
10
11 #-----------------------------------------------------------------------------
12 # Copyright (C) 2008-2011 The IPython Development Team
13 #
14 # Distributed under the terms of the BSD License. The full license is in
15 # the file COPYING, distributed as part of this software.
16 #-----------------------------------------------------------------------------
17
18 #-----------------------------------------------------------------------------
19 # Imports
20 #-----------------------------------------------------------------------------
4 # Copyright (c) IPython Development Team.
5 # Distributed under the terms of the Modified BSD License.
21 6
22 7 from unittest import TestCase
23 8
@@ -33,10 +18,6 b' from IPython.utils.traitlets import ('
33 18 from IPython.config.loader import Config
34 19 from IPython.utils.py3compat import PY3
35 20
36 #-----------------------------------------------------------------------------
37 # Test cases
38 #-----------------------------------------------------------------------------
39
40 21
41 22 class MyConfigurable(Configurable):
42 23 a = Integer(1, config=True, help="The integer a.")
@@ -372,4 +353,26 b' class TestConfigContainers(TestCase):'
372 353 m.update_config(c2)
373 354 self.assertEqual(m.a, 15)
374 355
356 def test_config_default(self):
357 class SomeSingleton(SingletonConfigurable):
358 pass
359
360 class DefaultConfigurable(Configurable):
361 a = Integer(config=True)
362 def _config_default(self):
363 if SomeSingleton.initialized():
364 return SomeSingleton.instance().config
365 return Config()
366
367 c = Config()
368 c.DefaultConfigurable.a = 5
369
370 d1 = DefaultConfigurable()
371 self.assertEqual(d1.a, 0)
372
373 single = SomeSingleton.instance(config=c)
374
375 d2 = DefaultConfigurable()
376 self.assertIs(d2.config, single.config)
377 self.assertEqual(d2.a, 5)
375 378
General Comments 0
You need to be logged in to leave comments. Login now