##// END OF EJS Templates
disallow no-prefix `ipython foo=bar` argument style....
disallow no-prefix `ipython foo=bar` argument style. This style is in rc1, but will be removed in rc2. Since they don't match any flag pattern, rc1-style arguments will be interpreted by IPython as files to be run. So `ipython gui=foo -i` will exec gui=foo, and pass '-i' to gui=foo. Presumably this file won't exist, so there will be an error: Error in executing file in user namespace: gui=foo Assignments *must* have two leading '-', as in: ipython --foo=bar all flags (non-assignments) can be specified with one or two leading '-', as in: ipython -i --pylab -pdb --pprint script.py or ipython --i -pylab --pdb -pprint script.py but help only reports two-leading, as single-leading options will likely be removed on moving to argparse, where they will be replaced by single-letter aliases. The common remaining invalid option will be: ipython -foo=bar and a suggestion for 'did you mean --foo=bar'? will be presented in these cases.

File last commit:

r4197:368e365a
r4197:368e365a
Show More
test_application.py
135 lines | 4.2 KiB | text/x-python | PythonLexer
Brian Granger
Adding more documentation to config.application related files.
r3796 """
Tests for IPython.config.application.Application
Authors:
* Brian Granger
"""
#-----------------------------------------------------------------------------
# Copyright (C) 2008-2011 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from unittest import TestCase
from IPython.config.configurable import Configurable
from IPython.config.application import (
Application
)
from IPython.utils.traitlets import (
MinRK
rename macros/shortnames to flags/aliases...
r3861 Bool, Unicode, Int, Float, List, Dict
Brian Granger
Adding more documentation to config.application related files.
r3796 )
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
class Foo(Configurable):
MinRK
move shortname to Application...
r3852 i = Int(0, config=True, help="The integer i.")
j = Int(1, config=True, help="The integer j.")
name = Unicode(u'Brian', config=True, help="First name.")
Brian Granger
Adding more documentation to config.application related files.
r3796
class Bar(Configurable):
MinRK
prevent flags from clobbering entire config sections...
r3957 b = Int(0, config=True, help="The integer b.")
MinRK
move shortname to Application...
r3852 enabled = Bool(True, config=True, help="Enable bar.")
Brian Granger
Adding more documentation to config.application related files.
r3796
class MyApp(Application):
Brian Granger
Fixing bugs in BaseIPythonApplication....
r3942 name = Unicode(u'myapp')
MinRK
rename macros/shortnames to flags/aliases...
r3861 running = Bool(False, config=True,
Brian Granger
Adding more documentation to config.application related files.
r3796 help="Is the app running?")
classes = List([Bar, Foo])
MinRK
rename macros/shortnames to flags/aliases...
r3861 config_file = Unicode(u'', config=True,
Brian Granger
Adding more documentation to config.application related files.
r3796 help="Load this config file")
MinRK
rename macros/shortnames to flags/aliases...
r3861 aliases = Dict(dict(i='Foo.i',j='Foo.j',name='Foo.name',
enabled='Bar.enabled', log_level='MyApp.log_level'))
flags = Dict(dict(enable=({'Bar': {'enabled' : True}}, "Set Bar.enabled to True"),
disable=({'Bar': {'enabled' : False}}, "Set Bar.enabled to False")))
MinRK
move shortname to Application...
r3852
Brian Granger
Adding more documentation to config.application related files.
r3796 def init_foo(self):
self.foo = Foo(config=self.config)
def init_bar(self):
self.bar = Bar(config=self.config)
class TestApplication(TestCase):
def test_basic(self):
app = MyApp()
Brian Granger
Fixing bugs in BaseIPythonApplication....
r3942 self.assertEquals(app.name, u'myapp')
Brian Granger
Adding more documentation to config.application related files.
r3796 self.assertEquals(app.running, False)
self.assertEquals(app.classes, [MyApp,Bar,Foo])
self.assertEquals(app.config_file, u'')
def test_config(self):
app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log_level=50"])
Brian Granger
Adding more documentation to config.application related files.
r3796 config = app.config
self.assertEquals(config.Foo.i, 10)
self.assertEquals(config.Foo.j, 10)
self.assertEquals(config.Bar.enabled, False)
MinRK
raise test log_level, to prevent output during tests
r3948 self.assertEquals(config.MyApp.log_level,50)
Brian Granger
Adding more documentation to config.application related files.
r3796
def test_config_propagation(self):
app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log_level=50"])
Brian Granger
Adding more documentation to config.application related files.
r3796 app.init_foo()
app.init_bar()
self.assertEquals(app.foo.i, 10)
self.assertEquals(app.foo.j, 10)
self.assertEquals(app.bar.enabled, False)
MinRK
prevent flags from clobbering entire config sections...
r3957 def test_flags(self):
MinRK
move shortname to Application...
r3852 app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--disable"])
MinRK
move shortname to Application...
r3852 app.init_bar()
self.assertEquals(app.bar.enabled, False)
app.parse_command_line(["--enable"])
app.init_bar()
self.assertEquals(app.bar.enabled, True)
MinRK
prevent flags from clobbering entire config sections...
r3957 def test_aliases(self):
app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--i=5", "--j=10"])
MinRK
prevent flags from clobbering entire config sections...
r3957 app.init_foo()
self.assertEquals(app.foo.i, 5)
app.init_foo()
self.assertEquals(app.foo.j, 10)
def test_flag_clobber(self):
"""test that setting flags doesn't clobber existing settings"""
app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--Bar.b=5", "--disable"])
MinRK
prevent flags from clobbering entire config sections...
r3957 app.init_bar()
self.assertEquals(app.bar.enabled, False)
self.assertEquals(app.bar.b, 5)
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--enable", "--Bar.b=10"])
MinRK
prevent flags from clobbering entire config sections...
r3957 app.init_bar()
self.assertEquals(app.bar.enabled, True)
self.assertEquals(app.bar.b, 10)
MinRK
allow extra_args in applications
r3958 def test_extra_args(self):
app = MyApp()
MinRK
disallow no-prefix `ipython foo=bar` argument style....
r4197 app.parse_command_line(["--Bar.b=5", 'extra', "--disable", 'args'])
MinRK
allow extra_args in applications
r3958 app.init_bar()
MinRK
parse cl_args agnostic of leading '-'...
r4189 self.assertEquals(app.bar.enabled, True)
MinRK
allow extra_args in applications
r3958 self.assertEquals(app.bar.b, 5)
MinRK
parse cl_args agnostic of leading '-'...
r4189 self.assertEquals(app.extra_args, ['extra', "--disable", 'args'])
MinRK
allow extra_args in applications
r3958
MinRK
prevent flags from clobbering entire config sections...
r3957