@@ -115,6 +115,32 @@ def test_config_propagation(self):
115115 self .assertEqual (app .foo .i , 10 )
116116 self .assertEqual (app .foo .j , 10 )
117117 self .assertEqual (app .bar .enabled , False )
118+
119+ def test_ipython_cli_priority (self ):
120+ name = 'config.py'
121+ class TestApp (Application ):
122+ value = Unicode ().tag (config = True )
123+ aliases = {'v' : 'TestApp.value' }
124+ app = TestApp ()
125+ with TemporaryDirectory () as td :
126+ config_file = pjoin (td , name )
127+ with open (config_file , 'w' ) as f :
128+ f .write ("c.TestApp.value = 'config file'" )
129+ # follow IPython's config-loading sequence to ensure CLI priority is preserved
130+ app .parse_command_line (['--v=cli' ])
131+ # this is where IPython makes a mistake:
132+ # it assumes app.config will not be modified,
133+ # and storing a reference is storing a copy
134+ cli_config = app .config
135+ assert 'value' in app .config .TestApp
136+ assert app .config .TestApp .value == 'cli'
137+ app .load_config_file (name , path = [td ])
138+ assert app .config .TestApp .value == 'config file'
139+ # enforce cl-opts override config file opts:
140+ # this is where IPython makes a mistake: it assumes
141+ # that cl_config is a different object, but it isn't.
142+ app .update_config (cli_config )
143+ assert app .config .TestApp .value == 'cli'
118144
119145 def test_flags (self ):
120146 app = MyApp ()
0 commit comments