##// END OF EJS Templates
prevent flags from clobbering entire config sections...
MinRK -
Show More
@@ -355,8 +355,6 b" def boolean_flag(name, configurable, set_help='', unset_help=''):"
355
355
356 cls,trait = configurable.split('.')
356 cls,trait = configurable.split('.')
357
357
358 setter = Config()
358 setter = {cls : {trait : True}}
359 setter[cls][trait] = True
359 unsetter = {cls : {trait : False}}
360 unsetter = Config()
361 unsetter[cls][trait] = False
362 return {name : (setter, set_help), 'no-'+name : (unsetter, unset_help)}
360 return {name : (setter, set_help), 'no-'+name : (unsetter, unset_help)}
@@ -408,8 +408,10 b' class KeyValueConfigLoader(CommandLineConfigLoader):'
408 if cfg is None:
408 if cfg is None:
409 raise ArgumentError("Unrecognized flag: %r"%item)
409 raise ArgumentError("Unrecognized flag: %r"%item)
410 elif isinstance(cfg, (dict, Config)):
410 elif isinstance(cfg, (dict, Config)):
411 # update self.config with Config:
411 # don't clobber whole config sections, update
412 self.config.update(cfg)
412 # each section from config:
413 for sec,c in cfg.iteritems():
414 self.config[sec].update(c)
413 else:
415 else:
414 raise ValueError("Invalid flag: %r"%flag)
416 raise ValueError("Invalid flag: %r"%flag)
415 else:
417 else:
@@ -42,6 +42,7 b' class Foo(Configurable):'
42
42
43 class Bar(Configurable):
43 class Bar(Configurable):
44
44
45 b = Int(0, config=True, help="The integer b.")
45 enabled = Bool(True, config=True, help="Enable bar.")
46 enabled = Bool(True, config=True, help="Enable bar.")
46
47
47
48
@@ -94,7 +95,7 b' class TestApplication(TestCase):'
94 self.assertEquals(app.foo.j, 10)
95 self.assertEquals(app.foo.j, 10)
95 self.assertEquals(app.bar.enabled, False)
96 self.assertEquals(app.bar.enabled, False)
96
97
97 def test_alias(self):
98 def test_flags(self):
98 app = MyApp()
99 app = MyApp()
99 app.parse_command_line(["--disable"])
100 app.parse_command_line(["--disable"])
100 app.init_bar()
101 app.init_bar()
@@ -103,3 +104,26 b' class TestApplication(TestCase):'
103 app.init_bar()
104 app.init_bar()
104 self.assertEquals(app.bar.enabled, True)
105 self.assertEquals(app.bar.enabled, True)
105
106
107 def test_aliases(self):
108 app = MyApp()
109 app.parse_command_line(["i=5", "j=10"])
110 app.init_foo()
111 self.assertEquals(app.foo.i, 5)
112 app.init_foo()
113 self.assertEquals(app.foo.j, 10)
114
115 def test_flag_clobber(self):
116 """test that setting flags doesn't clobber existing settings"""
117 app = MyApp()
118 app.parse_command_line(["Bar.b=5", "--disable"])
119 print app.config
120 app.init_bar()
121 self.assertEquals(app.bar.enabled, False)
122 self.assertEquals(app.bar.b, 5)
123 app.parse_command_line(["--enable", "Bar.b=10"])
124 print app.config
125 app.init_bar()
126 self.assertEquals(app.bar.enabled, True)
127 self.assertEquals(app.bar.b, 10)
128
129
@@ -233,13 +233,13 b' base_aliases = dict('
233 )
233 )
234
234
235 base_flags = dict(
235 base_flags = dict(
236 debug = ({'Application' : Config({'log_level' : logging.DEBUG})},
236 debug = ({'Application' : {'log_level' : logging.DEBUG}},
237 "set log level to logging.DEBUG (maximize logging output)"),
237 "set log level to logging.DEBUG (maximize logging output)"),
238 quiet = ({'Application' : Config({'log_level' : logging.CRITICAL})},
238 quiet = ({'Application' : {'log_level' : logging.CRITICAL}},
239 "set log level to logging.CRITICAL (minimize logging output)"),
239 "set log level to logging.CRITICAL (minimize logging output)"),
240 init = ({'BaseIPythonApplication' : Config({
240 init = ({'BaseIPythonApplication' : {
241 'copy_config_files' : True,
241 'copy_config_files' : True,
242 'auto_create' : True})
242 'auto_create' : True}
243 }, "Initialize profile with default config files")
243 }, "Initialize profile with default config files")
244 )
244 )
245
245
General Comments 0
You need to be logged in to leave comments. Login now