##// END OF EJS Templates
update copyright to 2011/20xx-2011...
update copyright to 2011/20xx-2011 Closes #1033 (rebased to prevent recursive merge). Closes #2. 459 *.py files in : 39 empty files 176 files without copyright 36 have copyright but don't cite the dev team 208 have copyright and cite the dev team ----------------------------------------- 0 not up to date (cite dev team but not right year) FYI, list of files that don't have copyright (and are not empty..) [ 'IPython/config/profile/cluster/ipython_config.py', 'IPython/config/profile/math/ipython_config.py', 'IPython/config/profile/pylab/ipython_config.py', 'IPython/config/profile/pysh/ipython_config.py', 'IPython/config/profile/python3/ipython_config.py', 'IPython/config/profile/sympy/ipython_config.py', 'IPython/core/shadowns.py', 'IPython/core/tests/refbug.py', 'IPython/core/tests/simpleerr.py', 'IPython/core/tests/tclass.py', 'IPython/core/tests/test_application.py', 'IPython/core/tests/test_autocall.py', 'IPython/core/tests/test_completer.py', 'IPython/core/tests/test_fakemodule.py', 'IPython/core/tests/test_formatters.py', 'IPython/core/tests/test_handlers.py', 'IPython/core/tests/test_history.py', 'IPython/core/tests/test_imports.py', 'IPython/core/tests/test_iplib.py', 'IPython/core/tests/test_logger.py', 'IPython/core/tests/test_magic.py', 'IPython/core/tests/test_plugin.py', 'IPython/core/tests/test_prefilter.py', 'IPython/core/tests/test_profile.py', 'IPython/core/tests/test_run.py', 'IPython/core/tests/test_splitinput.py', 'IPython/deathrow/astyle.py', 'IPython/deathrow/dtutils.py', 'IPython/deathrow/Gnuplot2.py', 'IPython/deathrow/GnuplotInteractive.py', 'IPython/deathrow/GnuplotRuntime.py', 'IPython/deathrow/gui/wx/ipshell_nonblocking.py', 'IPython/deathrow/gui/wx/ipython_history.py', 'IPython/deathrow/gui/wx/thread_ex.py', 'IPython/deathrow/ibrowse.py', 'IPython/deathrow/igrid.py', 'IPython/deathrow/ipipe.py', 'IPython/deathrow/ipy_defaults.py', 'IPython/deathrow/ipy_kitcfg.py', 'IPython/deathrow/ipy_legacy.py', 'IPython/deathrow/ipy_p4.py', 'IPython/deathrow/ipy_profile_none.py', 'IPython/deathrow/ipy_profile_numpy.py', 'IPython/deathrow/ipy_profile_scipy.py', 'IPython/deathrow/ipy_profile_sh.py', 'IPython/deathrow/ipy_traits_completer.py', 'IPython/deathrow/ipy_vimserver.py', 'IPython/deathrow/numeric_formats.py', 'IPython/deathrow/oldfrontend/process/__init__.py', 'IPython/deathrow/oldfrontend/wx/ipythonx.py', 'IPython/deathrow/scitedirector.py', 'IPython/deathrow/tests/test_prefilter.py', 'IPython/deathrow/twshell.py', 'IPython/extensions/__init__.py', 'IPython/extensions/autoreload.py', 'IPython/extensions/storemagic.py', 'IPython/extensions/tests/test_autoreload.py', 'IPython/external/__init__.py', 'IPython/external/argparse/__init__.py', 'IPython/external/decorator/__init__.py', 'IPython/external/decorators/__init__.py', 'IPython/external/decorators/_decorators.py', 'IPython/external/decorators/_numpy_testing_noseclasses.py', 'IPython/external/decorators/_numpy_testing_utils.py', 'IPython/external/guid/__init__.py', 'IPython/external/Itpl/__init__.py', 'IPython/external/mglob/__init__.py', 'IPython/external/mglob/_mglob.py', 'IPython/external/path/__init__.py', 'IPython/external/path/_path.py', 'IPython/external/pexpect/__init__.py', 'IPython/external/pyparsing/__init__.py', 'IPython/external/qt.py', 'IPython/external/qt_for_kernel.py', 'IPython/external/simplegeneric/__init__.py', 'IPython/external/simplegeneric/_simplegeneric.py', 'IPython/frontend/html/notebook/__init__.py', 'IPython/frontend/html/notebook/tests/test_kernelsession.py', 'IPython/frontend/qt/base_frontend_mixin.py', 'IPython/frontend/qt/console/ansi_code_processor.py', 'IPython/frontend/qt/console/bracket_matcher.py', 'IPython/frontend/qt/console/call_tip_widget.py', 'IPython/frontend/qt/console/completion_lexer.py', 'IPython/frontend/qt/console/completion_widget.py', 'IPython/frontend/qt/console/console_widget.py', 'IPython/frontend/qt/console/history_console_widget.py', 'IPython/frontend/qt/console/ipython_widget.py', 'IPython/frontend/qt/console/kill_ring.py', 'IPython/frontend/qt/console/mainwindow.py', 'IPython/frontend/qt/console/pygments_highlighter.py', 'IPython/frontend/qt/console/qtconsoleapp.py', 'IPython/frontend/qt/console/rich_ipython_widget.py', 'IPython/frontend/qt/console/styles.py', 'IPython/frontend/qt/console/tests/test_ansi_code_processor.py', 'IPython/frontend/qt/console/tests/test_completion_lexer.py', 'IPython/frontend/qt/console/tests/test_kill_ring.py', 'IPython/frontend/qt/kernelmanager.py', 'IPython/frontend/qt/rich_text.py', 'IPython/frontend/qt/svg.py', 'IPython/frontend/qt/util.py', 'IPython/kernel/__init__.py', 'IPython/lib/clipboard.py', 'IPython/lib/display.py', 'IPython/lib/irunner.py', 'IPython/lib/security.py', 'IPython/lib/tests/test_imports.py', 'IPython/lib/tests/test_irunner.py', 'IPython/lib/tests/test_irunner_pylab_magic.py', 'IPython/lib/tests/test_security.py', 'IPython/nbformat/v1/tests/nbexamples.py', 'IPython/nbformat/v1/tests/test_json.py', 'IPython/nbformat/v1/tests/test_nbbase.py', 'IPython/nbformat/v2/tests/nbexamples.py', 'IPython/nbformat/v2/tests/test_json.py', 'IPython/nbformat/v2/tests/test_nbbase.py', 'IPython/nbformat/v2/tests/test_nbpy.py', 'IPython/quarantine/clearcmd.py', 'IPython/quarantine/envpersist.py', 'IPython/quarantine/ext_rescapture.py', 'IPython/quarantine/ipy_app_completers.py', 'IPython/quarantine/ipy_completers.py', 'IPython/quarantine/ipy_editors.py', 'IPython/quarantine/ipy_exportdb.py', 'IPython/quarantine/ipy_extutil.py', 'IPython/quarantine/ipy_fsops.py', 'IPython/quarantine/ipy_gnuglobal.py', 'IPython/quarantine/ipy_jot.py', 'IPython/quarantine/ipy_lookfor.py', 'IPython/quarantine/ipy_profile_doctest.py', 'IPython/quarantine/ipy_pydb.py', 'IPython/quarantine/ipy_rehashdir.py', 'IPython/quarantine/ipy_render.py', 'IPython/quarantine/ipy_server.py', 'IPython/quarantine/ipy_signals.py', 'IPython/quarantine/ipy_synchronize_with.py', 'IPython/quarantine/ipy_system_conf.py', 'IPython/quarantine/ipy_which.py', 'IPython/quarantine/ipy_winpdb.py', 'IPython/quarantine/ipy_workdir.py', 'IPython/quarantine/jobctrl.py', 'IPython/quarantine/ledit.py', 'IPython/quarantine/win32clip.py', 'IPython/testing/mkdoctests.py', 'IPython/testing/plugin/dtexample.py', 'IPython/testing/plugin/ipdoctest.py', 'IPython/testing/plugin/iptest.py', 'IPython/testing/plugin/setup.py', 'IPython/testing/plugin/show_refs.py', 'IPython/testing/plugin/simple.py', 'IPython/testing/plugin/simplevars.py', 'IPython/testing/plugin/test_ipdoctest.py', 'IPython/testing/plugin/test_refs.py', 'IPython/testing/skipdoctest.py', 'IPython/testing/tests/test_decorators.py', 'IPython/utils/autoattr.py', 'IPython/utils/nested_context.py', 'IPython/utils/pickleshare.py', 'IPython/utils/py3compat.py', 'IPython/utils/PyColorize.py', 'IPython/utils/rlineimpl.py', 'IPython/utils/strdispatch.py', 'IPython/utils/tempdir.py', 'IPython/utils/tests/test_imports.py', 'IPython/utils/tests/test_wildcard.py', 'IPython/utils/upgradedir.py', 'IPython/zmq/completer.py', 'IPython/zmq/displayhook.py', 'IPython/zmq/entry_point.py', 'IPython/zmq/frontend.py', 'IPython/zmq/iostream.py', 'IPython/zmq/ipkernel.py', 'IPython/zmq/log.py', 'IPython/zmq/parentpoller.py', 'IPython/zmq/pykernel.py', 'IPython/zmq/pylab/backend_inline.py', 'IPython/zmq/zmqshell.py' ]

File last commit:

r5390:c82649ea
r5390:c82649ea
Show More
test_configurable.py
183 lines | 5.7 KiB | text/x-python | PythonLexer
# encoding: utf-8
"""
Tests for IPython.config.configurable
Authors:
* Brian Granger
* Fernando Perez (design help)
"""
#-----------------------------------------------------------------------------
# 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,
SingletonConfigurable
)
from IPython.utils.traitlets import (
Integer, Float, Unicode
)
from IPython.config.loader import Config
from IPython.utils.py3compat import PY3
#-----------------------------------------------------------------------------
# Test cases
#-----------------------------------------------------------------------------
class MyConfigurable(Configurable):
a = Integer(1, config=True, help="The integer a.")
b = Float(1.0, config=True, help="The integer b.")
c = Unicode('no config')
mc_help=u"""MyConfigurable options
----------------------
--MyConfigurable.a=<Integer>
Default: 1
The integer a.
--MyConfigurable.b=<Float>
Default: 1.0
The integer b."""
mc_help_inst=u"""MyConfigurable options
----------------------
--MyConfigurable.a=<Integer>
Current: 5
The integer a.
--MyConfigurable.b=<Float>
Current: 4.0
The integer b."""
# 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>")
class Foo(Configurable):
a = Integer(0, config=True, help="The integer a.")
b = Unicode('nope', config=True)
class Bar(Foo):
b = Unicode('gotit', config=False, help="The string b.")
c = Float(config=True, help="The string c.")
class TestConfigurable(TestCase):
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)
c2 = Configurable(config=c1.config)
c3 = Configurable(config=c2.config)
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)
c2 = MyConfigurable(config=c1.config)
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)
b = Bar(config=f.config)
self.assertEquals(f.a, 10)
self.assertEquals(f.b, 'wow')
self.assertEquals(b.b, 'gotit')
self.assertEquals(b.c, 100.0)
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)
def test_help(self):
self.assertEquals(MyConfigurable.class_get_help(), mc_help)
def test_help_inst(self):
inst = MyConfigurable(a=5, b=4)
self.assertEquals(MyConfigurable.class_get_help(inst), mc_help_inst)
class TestSingletonConfigurable(TestCase):
def test_instance(self):
from IPython.config.configurable import SingletonConfigurable
class Foo(SingletonConfigurable): pass
self.assertEquals(Foo.initialized(), False)
foo = Foo.instance()
self.assertEquals(Foo.initialized(), True)
self.assertEquals(foo, Foo.instance())
self.assertEquals(SingletonConfigurable._instance, None)
def test_inheritance(self):
class Bar(SingletonConfigurable): pass
class Bam(Bar): pass
self.assertEquals(Bar.initialized(), False)
self.assertEquals(Bam.initialized(), False)
bam = Bam.instance()
bam == Bar.instance()
self.assertEquals(Bar.initialized(), True)
self.assertEquals(Bam.initialized(), True)
self.assertEquals(bam, Bam._instance)
self.assertEquals(bam, Bar._instance)
self.assertEquals(SingletonConfigurable._instance, None)