##// END OF EJS Templates
Merge pull request #1852 from minrk/resubmitbufs...
Merge pull request #1852 from minrk/resubmitbufs Fix chained resubmissions, tiny fix for missing buffers, and test. closes #1848

File last commit:

r5390:c82649ea
r7301:344e5435 merge
Show More
test_configurable.py
183 lines | 5.7 KiB | text/x-python | PythonLexer
/ IPython / config / tests / test_configurable.py
Brian Granger
First draft of refactored Component->Configurable.
r2731 # encoding: utf-8
"""
Tests for IPython.config.configurable
Authors:
* Brian Granger
* Fernando Perez (design help)
"""
#-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2008-2011 The IPython Development Team
Brian Granger
First draft of refactored Component->Configurable.
r2731 #
# 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
Brian Granger
Added SingletonConfigurable with instance method....
r3792 from IPython.config.configurable import (
Configurable,
SingletonConfigurable
)
Brian Granger
First draft of refactored Component->Configurable.
r2731 from IPython.utils.traitlets import (
MinRK
add Integer traitlet...
r5344 Integer, Float, Unicode
Brian Granger
First draft of refactored Component->Configurable.
r2731 )
Brian Granger
Added SingletonConfigurable with instance method....
r3792
Brian Granger
First draft of refactored Component->Configurable.
r2731 from IPython.config.loader import Config
Thomas Kluyver
Fix configurable test for Python 3.
r5351 from IPython.utils.py3compat import PY3
Brian Granger
First draft of refactored Component->Configurable.
r2731
#-----------------------------------------------------------------------------
# Test cases
#-----------------------------------------------------------------------------
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 class MyConfigurable(Configurable):
MinRK
add Integer traitlet...
r5344 a = Integer(1, config=True, help="The integer a.")
MinRK
move shortname to Application...
r3852 b = Float(1.0, config=True, help="The integer b.")
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 c = Unicode('no config')
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740
Brian Granger
Added new tests for config.loader and configurable.
r3791 mc_help=u"""MyConfigurable options
----------------------
MinRK
add Integer traitlet...
r5344 --MyConfigurable.a=<Integer>
MinRK
catch up tests to recent changes...
r4029 Default: 1
Brian Granger
Added new tests for config.loader and configurable.
r3791 The integer a.
MinRK
parse cl_args agnostic of leading '-'...
r4189 --MyConfigurable.b=<Float>
MinRK
catch up tests to recent changes...
r4029 Default: 1.0
Brian Granger
Added new tests for config.loader and configurable.
r3791 The integer b."""
MinRK
allow using instance values in place of defaults in Configurable.class_get_help
r5224 mc_help_inst=u"""MyConfigurable options
----------------------
MinRK
add Integer traitlet...
r5344 --MyConfigurable.a=<Integer>
MinRK
allow using instance values in place of defaults in Configurable.class_get_help
r5224 Current: 5
The integer a.
--MyConfigurable.b=<Float>
Current: 4.0
The integer b."""
Thomas Kluyver
Fix configurable test for Python 3.
r5351 # On Python 3, the Integer trait is a synonym for Int
if PY3:
mc_help = mc_help.replace(u"<Integer>", u"<Int>")
mc_help_inst = mc_help_inst.replace(u"<Integer>", u"<Int>")
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 class Foo(Configurable):
MinRK
add Integer traitlet...
r5344 a = Integer(0, config=True, help="The integer a.")
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 b = Unicode('nope', config=True)
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740
class Bar(Foo):
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 b = Unicode('gotit', config=False, help="The string b.")
MinRK
move shortname to Application...
r3852 c = Float(config=True, help="The string c.")
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740
Brian Granger
Added SingletonConfigurable with instance method....
r3792 class TestConfigurable(TestCase):
Brian Granger
First draft of refactored Component->Configurable.
r2731
def test_default(self):
c1 = Configurable()
c2 = Configurable(config=c1.config)
c3 = Configurable(config=c2.config)
self.assertEquals(c1.config, c2.config)
self.assertEquals(c2.config, c3.config)
def test_custom(self):
config = Config()
config.foo = 'foo'
config.bar = 'bar'
c1 = Configurable(config=config)
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 c2 = Configurable(config=c1.config)
c3 = Configurable(config=c2.config)
Brian Granger
First draft of refactored Component->Configurable.
r2731 self.assertEquals(c1.config, config)
self.assertEquals(c2.config, config)
self.assertEquals(c3.config, config)
# Test that copies are not made
self.assert_(c1.config is config)
self.assert_(c2.config is config)
self.assert_(c3.config is config)
self.assert_(c1.config is c2.config)
self.assert_(c2.config is c3.config)
def test_inheritance(self):
config = Config()
config.MyConfigurable.a = 2
config.MyConfigurable.b = 2.0
c1 = MyConfigurable(config=config)
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 c2 = MyConfigurable(config=c1.config)
Brian Granger
First draft of refactored Component->Configurable.
r2731 self.assertEquals(c1.a, config.MyConfigurable.a)
self.assertEquals(c1.b, config.MyConfigurable.b)
self.assertEquals(c2.a, config.MyConfigurable.a)
self.assertEquals(c2.b, config.MyConfigurable.b)
def test_parent(self):
config = Config()
config.Foo.a = 10
config.Foo.b = "wow"
config.Bar.b = 'later'
config.Bar.c = 100.0
f = Foo(config=config)
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 b = Bar(config=f.config)
Brian Granger
First draft of refactored Component->Configurable.
r2731 self.assertEquals(f.a, 10)
self.assertEquals(f.b, 'wow')
self.assertEquals(b.b, 'gotit')
self.assertEquals(b.c, 100.0)
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740
def test_override1(self):
config = Config()
config.MyConfigurable.a = 2
config.MyConfigurable.b = 2.0
c = MyConfigurable(a=3, config=config)
self.assertEquals(c.a, 3)
self.assertEquals(c.b, config.MyConfigurable.b)
self.assertEquals(c.c, 'no config')
def test_override2(self):
config = Config()
config.Foo.a = 1
config.Bar.b = 'or' # Up above b is config=False, so this won't do it.
config.Bar.c = 10.0
c = Bar(config=config)
self.assertEquals(c.a, config.Foo.a)
self.assertEquals(c.b, 'gotit')
self.assertEquals(c.c, config.Bar.c)
c = Bar(a=2, b='and', c=20.0, config=config)
self.assertEquals(c.a, 2)
self.assertEquals(c.b, 'and')
self.assertEquals(c.c, 20.0)
Brian Granger
Added new tests for config.loader and configurable.
r3791
def test_help(self):
self.assertEquals(MyConfigurable.class_get_help(), mc_help)
MinRK
allow using instance values in place of defaults in Configurable.class_get_help
r5224 def test_help_inst(self):
inst = MyConfigurable(a=5, b=4)
self.assertEquals(MyConfigurable.class_get_help(inst), mc_help_inst)
Brian Granger
Added SingletonConfigurable with instance method....
r3792
class TestSingletonConfigurable(TestCase):
def test_instance(self):
from IPython.config.configurable import SingletonConfigurable
class Foo(SingletonConfigurable): pass
Brian Granger
Made InteractiveShell a SingletonConfigurable....
r3793 self.assertEquals(Foo.initialized(), False)
Brian Granger
Added SingletonConfigurable with instance method....
r3792 foo = Foo.instance()
Brian Granger
Made InteractiveShell a SingletonConfigurable....
r3793 self.assertEquals(Foo.initialized(), True)
Brian Granger
Added SingletonConfigurable with instance method....
r3792 self.assertEquals(foo, Foo.instance())
self.assertEquals(SingletonConfigurable._instance, None)
def test_inheritance(self):
class Bar(SingletonConfigurable): pass
class Bam(Bar): pass
Brian Granger
Made InteractiveShell a SingletonConfigurable....
r3793 self.assertEquals(Bar.initialized(), False)
self.assertEquals(Bam.initialized(), False)
Brian Granger
Added SingletonConfigurable with instance method....
r3792 bam = Bam.instance()
bam == Bar.instance()
Brian Granger
Made InteractiveShell a SingletonConfigurable....
r3793 self.assertEquals(Bar.initialized(), True)
self.assertEquals(Bam.initialized(), True)
Brian Granger
Added SingletonConfigurable with instance method....
r3792 self.assertEquals(bam, Bam._instance)
self.assertEquals(bam, Bar._instance)
self.assertEquals(SingletonConfigurable._instance, None)