##// END OF EJS Templates
Merge pull request #6183 from takluyver/pr-whatsnew-6...
Merge pull request #6183 from takluyver/pr-whatsnew-6 Update whatsnew and set rst default role

File last commit:

r16961:cb8a00e5
r17316:b03e27b3 merge
Show More
test_traitlets.py
1153 lines | 30.7 KiB | text/x-python | PythonLexer
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 # encoding: utf-8
Min RK
Make HasTraits pickleable...
r16216 """Tests for IPython.utils.traitlets."""
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Min RK
Make HasTraits pickleable...
r16216 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
#
# Adapted from enthought.traits, Copyright (c) Enthought, Inc.,
# also under the terms of the Modified BSD License.
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Min RK
Make HasTraits pickleable...
r16216 import pickle
Bradley M. Froehle
Add tests for CRegExp.
r6750 import re
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 import sys
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 from unittest import TestCase
MinRK
test Dict trait assignment
r8232 import nose.tools as nt
MinRK
small changes in response to pyflakes pass...
r6270 from nose import SkipTest
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 from IPython.utils.traitlets import (
zah
Implementation in TraitType directly.
r16453 HasTraits, MetaHasTraits, TraitType, Any, CBytes, Dict,
MinRK
add Integer traitlet...
r5344 Int, Long, Integer, Float, Complex, Bytes, Unicode, TraitError,
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 Undefined, Type, This, Instance, TCPAddress, List, Tuple,
Jason Grout
Change 'bind' to 'link'
r15163 ObjectName, DottedObjectName, CRegExp, link
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 )
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 from IPython.utils import py3compat
MinRK
add Integer traitlet...
r5344 from IPython.testing.decorators import skipif
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
#-----------------------------------------------------------------------------
# Helper classes for testing
#-----------------------------------------------------------------------------
Dav Clark
Final changes traitlet -> trait for review
r2385 class HasTraitsStub(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 def _notify_trait(self, name, old, new):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 self._notify_name = name
self._notify_old = old
self._notify_new = new
#-----------------------------------------------------------------------------
# Test classes
#-----------------------------------------------------------------------------
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestTraitType(TestCase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 def test_get_undefined(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Dav Clark
Final changes traitlet -> trait for review
r2385 a = TraitType
Brian Granger
Important changes to simplify traitlets....
r2182 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.a, Undefined)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_set(self):
Dav Clark
Final changes traitlet -> trait for review
r2385 class A(HasTraitsStub):
a = TraitType
Brian Granger
Important changes to simplify traitlets....
r2182
a = A()
a.a = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.a, 10)
self.assertEqual(a._notify_name, 'a')
self.assertEqual(a._notify_old, Undefined)
self.assertEqual(a._notify_new, 10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_validate(self):
Dav Clark
Final changes traitlet -> trait for review
r2385 class MyTT(TraitType):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 def validate(self, inst, value):
return -1
Dav Clark
Final changes traitlet -> trait for review
r2385 class A(HasTraitsStub):
Brian Granger
Important changes to simplify traitlets....
r2182 tt = MyTT
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Important changes to simplify traitlets....
r2182 a = A()
a.tt = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.tt, -1)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 def test_default_validate(self):
zah
Implementation in TraitType directly.
r16453 class MyIntTT(TraitType):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 def validate(self, obj, value):
if isinstance(value, int):
return value
self.error(obj, value)
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 tt = MyIntTT(10)
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.tt, 10)
Brian Granger
Important changes to simplify traitlets....
r2182
Dav Clark
Iniital stab at renames for traitlets
r2384 # Defaults are validated when the HasTraits is instantiated
class B(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 tt = MyIntTT('bad default')
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, B)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 def test_is_valid_for(self):
Dav Clark
Final changes traitlet -> trait for review
r2385 class MyTT(TraitType):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 def is_valid_for(self, value):
return True
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 tt = MyTT
a = A()
a.tt = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.tt, 10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_value_for(self):
Dav Clark
Final changes traitlet -> trait for review
r2385 class MyTT(TraitType):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 def value_for(self, value):
return 20
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 tt = MyTT
a = A()
a.tt = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.tt, 20)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_info(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Dav Clark
Final changes traitlet -> trait for review
r2385 tt = TraitType
Brian Granger
Important changes to simplify traitlets....
r2182 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(A.tt.info(), 'any value')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_error(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Dav Clark
Final changes traitlet -> trait for review
r2385 tt = TraitType
Brian Granger
Important changes to simplify traitlets....
r2182 a = A()
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, A.tt.error, a, 10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Robert Kern
ENH: Add dynamic initializers (_x_default methods) to traitlets.
r3207 def test_dynamic_initializer(self):
class A(HasTraits):
x = Int(10)
def _x_default(self):
return 11
class B(A):
x = Int(20)
class C(A):
def _x_default(self):
return 21
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a._trait_values, {})
Thomas Kluyver
Fix tests in utils
r13373 self.assertEqual(list(a._trait_dyn_inits.keys()), ['x'])
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.x, 11)
self.assertEqual(a._trait_values, {'x': 11})
Robert Kern
ENH: Add dynamic initializers (_x_default methods) to traitlets.
r3207 b = B()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b._trait_values, {'x': 20})
Thomas Kluyver
Fix tests in utils
r13373 self.assertEqual(list(a._trait_dyn_inits.keys()), ['x'])
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.x, 20)
Robert Kern
ENH: Add dynamic initializers (_x_default methods) to traitlets.
r3207 c = C()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(c._trait_values, {})
Thomas Kluyver
Fix tests in utils
r13373 self.assertEqual(list(a._trait_dyn_inits.keys()), ['x'])
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(c.x, 21)
self.assertEqual(c._trait_values, {'x': 21})
Robert Kern
BUG: Do not store class-specific state on TraitTypes since they may be shared through subclassing.
r3336 # Ensure that the base class remains unmolested when the _default
# initializer gets overridden in a subclass.
a = A()
c = C()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a._trait_values, {})
Thomas Kluyver
Fix tests in utils
r13373 self.assertEqual(list(a._trait_dyn_inits.keys()), ['x'])
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.x, 11)
self.assertEqual(a._trait_values, {'x': 11})
Robert Kern
BUG: Do not store class-specific state on TraitTypes since they may be shared through subclassing.
r3336
Robert Kern
ENH: Add dynamic initializers (_x_default methods) to traitlets.
r3207
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class TestHasTraitsMeta(TestCase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_metaclass(self):
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(type(HasTraits), MetaHasTraits)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(type(a.__class__), MetaHasTraits)
self.assertEqual(a.a,0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.a,10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class B(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 b = Int()
b = B()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.b,0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 b.b = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.b,10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class C(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 c = Int(30)
c = C()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(c.c,30)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 c.c = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(c.c,10)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183 def test_this_class(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183 t = This()
tt = This()
class B(A):
tt = This()
ttt = This()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(A.t.this_class, A)
self.assertEqual(B.t.this_class, A)
self.assertEqual(B.tt.this_class, B)
self.assertEqual(B.ttt.this_class, B)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class TestHasTraitsNotify(TestCase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def setUp(self):
self._notify1 = []
self._notify2 = []
def notify1(self, name, old, new):
self._notify1.append((name, old, new))
def notify2(self, name, old, new):
self._notify2.append((name, old, new))
def test_notify_all(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
b = Float
a = A()
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(self.notify1)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(self._notify1),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.b = 0.0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(self._notify1),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('a',0,10) in self._notify1)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.b = 10.0
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('b',0.0,10.0) in self._notify1)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError,setattr,a,'a','bad string')
self.assertRaises(TraitError,setattr,a,'b','bad string')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 self._notify1 = []
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(self.notify1,remove=True)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 20
a.b = 20.0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(self._notify1),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_notify_one(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
b = Float
a = A()
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(self.notify1, 'a')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(self._notify1),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('a',0,10) in self._notify1)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError,setattr,a,'a','bad string')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_subclass(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
class B(A):
b = Float
b = B()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.a,0)
self.assertEqual(b.b,0.0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 b.a = 100
b.b = 100.0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.a,100)
self.assertEqual(b.b,100.0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_notify_subclass(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
class B(A):
b = Float
b = B()
Dav Clark
Iniital stab at renames for traitlets
r2384 b.on_trait_change(self.notify1, 'a')
b.on_trait_change(self.notify2, 'b')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 b.a = 0
b.b = 0.0
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(self._notify1),0)
self.assertEqual(len(self._notify2),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 b.a = 10
b.b = 10.0
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('a',0,10) in self._notify1)
self.assertTrue(('b',0.0,10.0) in self._notify2)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_static_notify(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
_notify1 = []
def _a_changed(self, name, old, new):
self._notify1.append((name, old, new))
a = A()
a.a = 0
Brian Granger
Important changes to simplify traitlets....
r2182 # This is broken!!!
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(a._notify1),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('a',0,10) in a._notify1)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
class B(A):
b = Float
_notify2 = []
def _b_changed(self, name, old, new):
self._notify2.append((name, old, new))
b = B()
b.a = 10
b.b = 10.0
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(('a',0,10) in b._notify1)
self.assertTrue(('b',0.0,10.0) in b._notify2)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_notify_args(self):
def callback0():
self.cb = ()
def callback1(name):
self.cb = (name,)
def callback2(name, new):
self.cb = (name, new)
def callback3(name, old, new):
self.cb = (name, old, new)
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a = Int
a = A()
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback0, 'a')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self.cb,())
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback0, 'a', remove=True)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback1, 'a')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 100
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self.cb,('a',))
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback1, 'a', remove=True)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback2, 'a')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 1000
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self.cb,('a',1000))
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback2, 'a', remove=True)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback3, 'a')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 a.a = 10000
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self.cb,('a',1000,10000))
Dav Clark
Iniital stab at renames for traitlets
r2384 a.on_trait_change(callback3, 'a', remove=True)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(len(a._trait_notifiers['a']),0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def test_notify_only_once(self):
class A(HasTraits):
listen_to = ['a']
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 a = Int(0)
b = 0
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def __init__(self, **kwargs):
super(A, self).__init__(**kwargs)
self.on_trait_change(self.listener1, ['a'])
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def listener1(self, name, old, new):
self.b += 1
class B(A):
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 c = 0
d = 0
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def __init__(self, **kwargs):
super(B, self).__init__(**kwargs)
self.on_trait_change(self.listener2)
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def listener2(self, name, old, new):
self.c += 1
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Added test for traitlet notify by-ref fix
r13149 def _a_changed(self, name, old, new):
self.d += 1
b = B()
b.a += 1
self.assertEqual(b.b, b.c)
self.assertEqual(b.b, b.d)
b.a += 1
self.assertEqual(b.b, b.c)
self.assertEqual(b.b, b.d)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Iniital stab at renames for traitlets
r2384 class TestHasTraits(TestCase):
Brian Granger
A few more small traitlets features.
r2179
Dav Clark
Iniital stab at renames for traitlets
r2384 def test_trait_names(self):
class A(HasTraits):
Brian Granger
Improvement to how config is handled in Components....
r2184 i = Int
f = Float
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(sorted(a.trait_names()),['f','i'])
self.assertEqual(sorted(A.class_trait_names()),['f','i'])
Brian Granger
Improvement to how config is handled in Components....
r2184
Dav Clark
Iniital stab at renames for traitlets
r2384 def test_trait_metadata(self):
class A(HasTraits):
Brian Granger
Improvement to how config is handled in Components....
r2184 i = Int(config_key='MY_VALUE')
Brian Granger
A few more small traitlets features.
r2179 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.trait_metadata('i','config_key'), 'MY_VALUE')
Brian Granger
A few more small traitlets features.
r2179
Dav Clark
Iniital stab at renames for traitlets
r2384 def test_traits(self):
class A(HasTraits):
Brian Granger
Improvement to how config is handled in Components....
r2184 i = Int
f = Float
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.traits(), dict(i=A.i, f=A.f))
self.assertEqual(A.class_traits(), dict(i=A.i, f=A.f))
Brian Granger
Improvement to how config is handled in Components....
r2184
Dav Clark
Iniital stab at renames for traitlets
r2384 def test_traits_metadata(self):
class A(HasTraits):
Brian Granger
Improvement to how config is handled in Components....
r2184 i = Int(config_key='VALUE1', other_thing='VALUE2')
f = Float(config_key='VALUE3', other_thing='VALUE2')
Brian Granger
Massive refactoring of of the core....
r2245 j = Int(0)
Brian Granger
Improvement to how config is handled in Components....
r2184 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.traits(), dict(i=A.i, f=A.f, j=A.j))
Dav Clark
Final changes traitlet -> trait for review
r2385 traits = a.traits(config_key='VALUE1', other_thing='VALUE2')
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(traits, dict(i=A.i))
Brian Granger
Massive refactoring of of the core....
r2245
Bernardo B. Marques
remove all trailling spaces
r4872 # This passes, but it shouldn't because I am replicating a bug in
Brian Granger
Massive refactoring of of the core....
r2245 # traits.
Dav Clark
Final changes traitlet -> trait for review
r2385 traits = a.traits(config_key=lambda v: True)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(traits, dict(i=A.i, f=A.f, j=A.j))
Brian Granger
Massive refactoring of of the core....
r2245
Brian Granger
Adding support for HasTraits to take keyword arguments.
r2740 def test_init(self):
class A(HasTraits):
i = Int()
x = Float()
a = A(i=1, x=10.0)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.i, 1)
self.assertEqual(a.x, 10.0)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
MinRK
test positional args in HasTraits
r10369 def test_positional_args(self):
class A(HasTraits):
i = Int(0)
def __init__(self, i):
super(A, self).__init__()
self.i = i
zah
Implementation in TraitType directly.
r16453
MinRK
test positional args in HasTraits
r10369 a = A(5)
self.assertEqual(a.i, 5)
# should raise TypeError if no positional arg given
self.assertRaises(TypeError, A)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 #-----------------------------------------------------------------------------
Dav Clark
Final changes traitlet -> trait for review
r2385 # Tests for specific trait types
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 #-----------------------------------------------------------------------------
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
class TestType(TestCase):
def test_default(self):
class B(object): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 klass = Type
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, None)
Brian Granger
A number of changes to how traitlets and components work....
r2229
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a.klass = B
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, B)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, a, 'klass', 10)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
def test_value(self):
class B(object): pass
class C(object): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 klass = Type(B)
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, B)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, a, 'klass', C)
self.assertRaises(TraitError, setattr, a, 'klass', object)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a.klass = B
def test_allow_none(self):
class B(object): pass
class C(B): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 klass = Type(B, allow_none=False)
a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, B)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, a, 'klass', None)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a.klass = C
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, C)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Brian Granger
Important changes to simplify traitlets....
r2182 def test_validate_klass(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
A number of changes to how traitlets and components work....
r2229 klass = Type('no strings allowed')
self.assertRaises(ImportError, A)
Brian Granger
Important changes to simplify traitlets....
r2182
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
A number of changes to how traitlets and components work....
r2229 klass = Type('rub.adub.Duck')
self.assertRaises(ImportError, A)
Brian Granger
Important changes to simplify traitlets....
r2182
def test_validate_default(self):
class B(object): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 klass = Type('bad default', B)
Brian Granger
A number of changes to how traitlets and components work....
r2229 self.assertRaises(ImportError, A)
Brian Granger
Important changes to simplify traitlets....
r2182
Dav Clark
Iniital stab at renames for traitlets
r2384 class C(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 klass = Type(None, B, allow_none=False)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, C)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Brian Granger
A number of changes to how traitlets and components work....
r2229 def test_str_klass(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
A number of changes to how traitlets and components work....
r2229 klass = Type('IPython.utils.ipstruct.Struct')
from IPython.utils.ipstruct import Struct
a = A()
a.klass = Struct
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.klass, Struct)
Bernardo B. Marques
remove all trailling spaces
r4872
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, a, 'klass', 10)
Brian Granger
A number of changes to how traitlets and components work....
r2229
Thomas Kluyver
Allow Type trait to be set with an importable string
r16961 def test_set_str_klass(self):
class A(HasTraits):
klass = Type()
a = A(klass='IPython.utils.ipstruct.Struct')
from IPython.utils.ipstruct import Struct
self.assertEqual(a.klass, Struct)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 class TestInstance(TestCase):
def test_basic(self):
class Foo(object): pass
class Bar(Foo): pass
class Bah(object): pass
Bernardo B. Marques
remove all trailling spaces
r4872
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 inst = Instance(Foo)
a = A()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(a.inst is None)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a.inst = Foo()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(isinstance(a.inst, Foo))
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a.inst = Bar()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(isinstance(a.inst, Foo))
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, a, 'inst', Foo)
self.assertRaises(TraitError, setattr, a, 'inst', Bar)
self.assertRaises(TraitError, setattr, a, 'inst', Bah())
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
def test_unique_default_value(self):
Brian Granger
A number of changes to how traitlets and components work....
r2229 class Foo(object): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Foo,(),{})
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
a = A()
b = A()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(a.inst is not b.inst)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
def test_args_kw(self):
class Foo(object):
def __init__(self, c): self.c = c
Brian Granger
Important changes to simplify traitlets....
r2182 class Bar(object): pass
class Bah(object):
def __init__(self, c, d):
self.c = c; self.d = d
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Foo, (10,))
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 a = A()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(a.inst.c, 10)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Dav Clark
Iniital stab at renames for traitlets
r2384 class B(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Bah, args=(10,), kw=dict(d=20))
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 b = B()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(b.inst.c, 10)
self.assertEqual(b.inst.d, 20)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Dav Clark
Iniital stab at renames for traitlets
r2384 class C(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Foo)
c = C()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(c.inst is None)
Brian Granger
Important changes to simplify traitlets....
r2182
def test_bad_default(self):
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177 class Foo(object): pass
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Foo, allow_none=False)
Bernardo B. Marques
remove all trailling spaces
r4872
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, A)
Brian Granger
Important changes to simplify traitlets....
r2182
def test_instance(self):
class Foo(object): pass
def inner():
Dav Clark
Iniital stab at renames for traitlets
r2384 class A(HasTraits):
Brian Granger
Important changes to simplify traitlets....
r2182 inst = Instance(Foo())
Bernardo B. Marques
remove all trailling spaces
r4872
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, inner)
Brian Granger
Added support for Type and Instance traitlets with testing.
r2177
Brian Granger
Improvements to component.py....
r2180
class TestThis(TestCase):
def test_this_class(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class Foo(HasTraits):
Brian Granger
Improvements to component.py....
r2180 this = This
f = Foo()
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(f.this, None)
Brian Granger
Improvements to component.py....
r2180 g = Foo()
f.this = g
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(f.this, g)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, f, 'this', 10)
Brian Granger
Improvements to component.py....
r2180
def test_this_inst(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class Foo(HasTraits):
Brian Granger
Improvements to component.py....
r2180 this = This()
Bernardo B. Marques
remove all trailling spaces
r4872
Brian Granger
Improvements to component.py....
r2180 f = Foo()
f.this = Foo()
Bradley M. Froehle
s/assert_/assertTrue/
r7876 self.assertTrue(isinstance(f.this, Foo))
Brian Granger
Improvements to component.py....
r2180
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183 def test_subclass(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class Foo(HasTraits):
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183 t = This()
class Bar(Foo):
pass
f = Foo()
b = Bar()
f.t = b
b.t = f
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(f.t, b)
self.assertEqual(b.t, f)
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183
def test_subclass_override(self):
Dav Clark
Iniital stab at renames for traitlets
r2384 class Foo(HasTraits):
Brian Granger
Fixing subtle bug in the traitlets with This....
r2183 t = This()
class Bar(Foo):
t = This()
f = Foo()
b = Bar()
f.t = b
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(f.t, b)
Dav Clark
Final changes traitlet -> trait for review
r2385 self.assertRaises(TraitError, setattr, b, 't', f)
Brian Granger
Improvements to component.py....
r2180
Dav Clark
Final changes traitlet -> trait for review
r2385 class TraitTestBase(TestCase):
"""A best testing class for basic trait types."""
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def assign(self, value):
self.obj.value = value
def coerce(self, value):
return value
def test_good_values(self):
if hasattr(self, '_good_values'):
for value in self._good_values:
self.assign(value)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self.obj.value, self.coerce(value))
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_bad_values(self):
if hasattr(self, '_bad_values'):
for value in self._bad_values:
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 try:
self.assertRaises(TraitError, self.assign, value)
except AssertionError:
assert False, value
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
def test_default_value(self):
if hasattr(self, '_default_value'):
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(self._default_value, self.obj.value)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
zah
Added tests
r16411 def test_allow_none(self):
if (hasattr(self, '_bad_values') and hasattr(self, '_good_values') and
None in self._bad_values):
trait=self.obj.traits()['value']
zah
Implementation in TraitType directly.
r16453 try:
trait.allow_none = True
self._bad_values.remove(None)
#skip coerce. Allow None casts None to None.
self.assign(None)
self.assertEqual(self.obj.value,None)
self.test_good_values()
self.test_bad_values()
finally:
#tear down
trait.allow_none = False
self._bad_values.append(None)
zah
Added tests
r16411
MinRK
add Integer traitlet...
r5344 def tearDown(self):
# restore default value after tests, if set
if hasattr(self, '_default_value'):
self.obj.value = self._default_value
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class AnyTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
value = Any
Dav Clark
Final changes traitlet -> trait for review
r2385 class AnyTraitTest(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = AnyTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
_default_value = None
_good_values = [10.0, 'ten', u'ten', [10], {'ten': 10},(10,), None, 1j]
_bad_values = []
Dav Clark
Final changes traitlet -> trait for review
r2385 class IntTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
value = Int(99)
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestInt(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = IntTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 _default_value = 99
_good_values = [10, -10]
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None, 1j,
10.1, -10.1, '10L', '-10L', '10.1', '-10.1', u'10L',
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 u'-10L', u'10.1', u'-10.1', '10', '-10', u'10', u'-10']
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 if not py3compat.PY3:
Thomas Kluyver
Fix long integer literals....
r13352 _bad_values.extend([long(10), long(-10), 10*sys.maxint, -10*sys.maxint])
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class LongTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Fix long integer literals....
r13352 value = Long(99 if py3compat.PY3 else long(99))
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestLong(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = LongTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Fix long integer literals....
r13352 _default_value = 99 if py3compat.PY3 else long(99)
_good_values = [10, -10]
_bad_values = ['ten', u'ten', [10], {'ten': 10},(10,),
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 None, 1j, 10.1, -10.1, '10', '-10', '10L', '-10L', '10.1',
'-10.1', u'10', u'-10', u'10L', u'-10L', u'10.1',
u'-10.1']
MinRK
add Integer traitlet...
r5344 if not py3compat.PY3:
# maxint undefined on py3, because int == long
Thomas Kluyver
Fix long integer literals....
r13352 _good_values.extend([long(10), long(-10), 10*sys.maxint, -10*sys.maxint])
_bad_values.extend([[long(10)], (long(10),)])
MinRK
add Integer traitlet...
r5344
@skipif(py3compat.PY3, "not relevant on py3")
def test_cast_small(self):
"""Long casts ints to long"""
self.obj.value = 10
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(type(self.obj.value), long)
MinRK
add Integer traitlet...
r5344
class IntegerTrait(HasTraits):
value = Integer(1)
class TestInteger(TestLong):
obj = IntegerTrait()
_default_value = 1
def coerce(self, n):
return int(n)
@skipif(py3compat.PY3, "not relevant on py3")
def test_cast_small(self):
"""Integer casts small longs to int"""
if py3compat.PY3:
raise SkipTest("not relevant on py3")
Thomas Kluyver
Fix long integer literals....
r13352 self.obj.value = long(100)
Bradley M. Froehle
s/assertEquals/assertEqual/
r7874 self.assertEqual(type(self.obj.value), int)
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class FloatTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
value = Float(99.0)
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestFloat(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = FloatTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
_default_value = 99.0
_good_values = [10, -10, 10.1, -10.1]
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 _bad_values = ['ten', u'ten', [10], {'ten': 10},(10,), None,
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 1j, '10', '-10', '10L', '-10L', '10.1', '-10.1', u'10',
u'-10', u'10L', u'-10L', u'10.1', u'-10.1']
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 if not py3compat.PY3:
Thomas Kluyver
Fix long integer literals....
r13352 _bad_values.extend([long(10), long(-10)])
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class ComplexTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
value = Complex(99.0-99.0j)
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestComplex(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = ComplexTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
_default_value = 99.0-99.0j
Bernardo B. Marques
remove all trailling spaces
r4872 _good_values = [10, -10, 10.1, -10.1, 10j, 10+10j, 10-10j,
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 10.1j, 10.1+10.1j, 10.1-10.1j]
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 _bad_values = [u'10L', u'-10L', 'ten', [10], {'ten': 10},(10,), None]
if not py3compat.PY3:
Thomas Kluyver
Fix long integer literals....
r13352 _bad_values.extend([long(10), long(-10)])
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 class BytesTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Tweaks to improve automated conversion to Python 3 code.
r4110 value = Bytes(b'string')
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 class TestBytes(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 obj = BytesTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Thomas Kluyver
Tweaks to improve automated conversion to Python 3 code.
r4110 _default_value = b'string'
_good_values = [b'10', b'-10', b'10L',
b'-10L', b'10.1', b'-10.1', b'string']
Thomas Kluyver
Fix long integer literals....
r13352 _bad_values = [10, -10, 10.1, -10.1, 1j, [10],
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 ['ten'],{'ten': 10},(10,), None, u'string']
Thomas Kluyver
Fix long integer literals....
r13352 if not py3compat.PY3:
_bad_values.extend([long(10), long(-10)])
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 class UnicodeTrait(HasTraits):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
value = Unicode(u'unicode')
Dav Clark
Final changes traitlet -> trait for review
r2385 class TestUnicode(TraitTestBase):
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
Dav Clark
Final changes traitlet -> trait for review
r2385 obj = UnicodeTrait()
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175
_default_value = u'unicode'
Bernardo B. Marques
remove all trailling spaces
r4872 _good_values = ['10', '-10', '10L', '-10L', '10.1',
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 '-10.1', '', u'', 'string', u'string', u"€"]
Thomas Kluyver
Fix long integer literals....
r13352 _bad_values = [10, -10, 10.1, -10.1, 1j,
Brian Granger
More work on traitlets.py. I have added tests for existing traitlets.
r2175 [10], ['ten'], [u'ten'], {'ten': 10},(10,), None]
Thomas Kluyver
Fix long integer literals....
r13352 if not py3compat.PY3:
_bad_values.extend([long(10), long(-10)])
Brian Granger
Minor work on kernelmanager....
r2742
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 class ObjectNameTrait(HasTraits):
value = ObjectName("abc")
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 class TestObjectName(TraitTestBase):
obj = ObjectNameTrait()
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 _default_value = "abc"
_good_values = ["a", "gh", "g9", "g_", "_G", u"a345_"]
_bad_values = [1, "", u"€", "9g", "!", "#abc", "aj@", "a.b", "a()", "a[0]",
zah
Added tests
r16411 None, object(), object]
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 if sys.version_info[0] < 3:
_bad_values.append(u"þ")
else:
_good_values.append(u"þ") # þ=1 is valid in Python 3 (PEP 3131).
class DottedObjectNameTrait(HasTraits):
value = DottedObjectName("a.b")
class TestDottedObjectName(TraitTestBase):
obj = DottedObjectNameTrait()
Bernardo B. Marques
remove all trailling spaces
r4872
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 _default_value = "a.b"
_good_values = ["A", "y.t", "y765.__repr__", "os.path.join", u"os.path.join"]
zah
Added tests
r16411 _bad_values = [1, u"abc.€", "_.@", ".", ".abc", "abc.", ".abc.", None]
Thomas Kluyver
Add ObjectName and DottedObjectName trait types for referring to Python identifiers.
r4047 if sys.version_info[0] < 3:
_bad_values.append(u"t.þ")
else:
_good_values.append(u"t.þ")
Brian Granger
Minor work on kernelmanager....
r2742 class TCPAddressTrait(HasTraits):
value = TCPAddress()
class TestTCPAddress(TraitTestBase):
obj = TCPAddressTrait()
_default_value = ('127.0.0.1',0)
_good_values = [('localhost',0),('192.168.0.1',1000),('www.google.com',80)]
zah
Added tests
r16411 _bad_values = [(0,0),('localhost',10.0),('localhost',-1), None]
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class ListTrait(HasTraits):
value = List(Int)
class TestList(TraitTestBase):
obj = ListTrait()
_default_value = []
MinRK
allow setting Tuple traitlet with list...
r15472 _good_values = [[], [1], list(range(10)), (1,2)]
_bad_values = [10, [1,'a'], 'a']
zah
Implementation in TraitType directly.
r16453
MinRK
allow setting Tuple traitlet with list...
r15472 def coerce(self, value):
if value is not None:
value = list(value)
return value
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
Thomas Kluyver
Merge pull request #5502 from Zaharid/iniinstance...
r16545 class Foo(object):
pass
class InstanceListTrait(HasTraits):
value = List(Instance(__name__+'.Foo'))
class TestInstanceList(TraitTestBase):
obj = InstanceListTrait()
def test_klass(self):
"""Test that the instance klass is properly assigned."""
self.assertIs(self.obj.traits()['value']._trait.klass, Foo)
_default_value = []
_good_values = [[Foo(), Foo(), None], None]
_bad_values = [['1', 2,], '1', [Foo]]
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870 class LenListTrait(HasTraits):
value = List(Int, [0], minlen=1, maxlen=2)
class TestLenList(TraitTestBase):
obj = LenListTrait()
_default_value = [0]
MinRK
allow setting Tuple traitlet with list...
r15472 _good_values = [[1], [1,2], (1,2)]
_bad_values = [10, [1,'a'], 'a', [], list(range(3))]
def coerce(self, value):
if value is not None:
value = list(value)
return value
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class TupleTrait(HasTraits):
zah
Fixed tuple
r16547 value = Tuple(Int(allow_none=True))
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class TestTupleTrait(TraitTestBase):
obj = TupleTrait()
_default_value = None
zah
Fixed tuple
r16547 _good_values = [(1,), None, (0,), [1], (None,)]
MinRK
allow setting Tuple traitlet with list...
r15472 _bad_values = [10, (1,2), ('a'), ()]
def coerce(self, value):
if value is not None:
value = tuple(value)
return value
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
def test_invalid_args(self):
self.assertRaises(TypeError, Tuple, 5)
self.assertRaises(TypeError, Tuple, default_value='hello')
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 t = Tuple(Int, CBytes, default_value=(1,5))
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class LooseTupleTrait(HasTraits):
value = Tuple((1,2,3))
class TestLooseTupleTrait(TraitTestBase):
obj = LooseTupleTrait()
_default_value = (1,2,3)
MinRK
allow setting Tuple traitlet with list...
r15472 _good_values = [(1,), None, [1], (0,), tuple(range(5)), tuple('hello'), ('a',5), ()]
_bad_values = [10, 'hello', {}]
def coerce(self, value):
if value is not None:
value = tuple(value)
return value
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
def test_invalid_args(self):
self.assertRaises(TypeError, Tuple, 5)
self.assertRaises(TypeError, Tuple, default_value='hello')
Thomas Kluyver
Eliminate Str and CStr trait types except in IPython.parallel
r4046 t = Tuple(Int, CBytes, default_value=(1,5))
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class MultiTupleTrait(HasTraits):
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 value = Tuple(Int, Bytes, default_value=[99,b'bottles'])
MinRK
Allow type checking on elements of List,Tuple,Set...
r3870
class TestMultiTuple(TraitTestBase):
obj = MultiTupleTrait()
Thomas Kluyver
Various fixes to tests in IPython.utils.
r4891 _default_value = (99,b'bottles')
_good_values = [(1,b'a'), (2,b'b')]
_bad_values = ((),10, b'a', (1,b'a',3), (b'a',1), (1, u'a'))
Bradley M. Froehle
Add tests for CRegExp.
r6750
class CRegExpTrait(HasTraits):
value = CRegExp(r'')
class TestCRegExp(TraitTestBase):
def coerce(self, value):
return re.compile(value)
obj = CRegExpTrait()
_default_value = re.compile(r'')
_good_values = [r'\d+', re.compile(r'\d+')]
_bad_values = [r'(', None, ()]
MinRK
test Dict trait assignment
r8232
class DictTrait(HasTraits):
value = Dict()
def test_dict_assignment():
d = dict()
c = DictTrait()
c.value = d
d['a'] = 5
nt.assert_equal(d, c.value)
nt.assert_true(c.value is d)
Jonathan Frederic
Added Connect tests
r15012
Jason Grout
Change 'bind' to 'link'
r15163 class TestLink(TestCase):
Jonathan Frederic
fixes to make Connect pass tests
r15013 def test_connect_same(self):
Jason Grout
Change 'bind' to 'link'
r15163 """Verify two traitlets of the same type can be linked together using link."""
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Create two simple classes with Int traitlets.
class A(HasTraits):
value = Int()
a = A(value=9)
b = A(value=8)
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Conenct the two classes.
Jason Grout
Change 'bind' to 'link'
r15163 c = link((a, 'value'), (b, 'value'))
Jonathan Frederic
Added Connect tests
r15012
Jason Grout
Change 'bind' to 'link'
r15163 # Make sure the values are the same at the point of linking.
Jonathan Frederic
fixes to make Connect pass tests
r15013 self.assertEqual(a.value, b.value)
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Change one of the values to make sure they stay in sync.
a.value = 5
self.assertEqual(a.value, b.value)
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018 b.value = 6
self.assertEqual(a.value, b.value)
Jonathan Frederic
Added Connect tests
r15012
Jason Grout
Change 'bind' to 'link'
r15163 def test_link_different(self):
"""Verify two traitlets of different types can be linked together using link."""
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Create two simple classes with Int traitlets.
class A(HasTraits):
value = Int()
class B(HasTraits):
count = Int()
a = A(value=9)
b = B(count=8)
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Conenct the two classes.
Jason Grout
Change 'bind' to 'link'
r15163 c = link((a, 'value'), (b, 'count'))
Jonathan Frederic
Added Connect tests
r15012
Jason Grout
Change 'bind' to 'link'
r15163 # Make sure the values are the same at the point of linking.
Jonathan Frederic
fixes to make Connect pass tests
r15013 self.assertEqual(a.value, b.count)
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Change one of the values to make sure they stay in sync.
a.value = 5
self.assertEqual(a.value, b.count)
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018 b.count = 4
self.assertEqual(a.value, b.count)
Jonathan Frederic
Added Connect tests
r15012
Jason Grout
Change 'bind' to 'link'
r15163 def test_unlink(self):
"""Verify two linked traitlets can be unlinked."""
Jonathan Frederic
Added Connect tests
r15012
Jonathan Frederic
fixes to make Connect pass tests
r15013 # Create two simple classes with Int traitlets.
class A(HasTraits):
value = Int()
a = A(value=9)
b = A(value=8)
Jason Grout
Change 'bind' to 'link'
r15163 # Connect the two classes.
c = link((a, 'value'), (b, 'value'))
Jonathan Frederic
fixes to make Connect pass tests
r15013 a.value = 4
Jason Grout
Change 'bind' to 'link'
r15163 c.unlink()
Jonathan Frederic
fixes to make Connect pass tests
r15013
Jason Grout
Change 'bind' to 'link'
r15163 # Change one of the values to make sure they don't stay in sync.
Jonathan Frederic
fixes to make Connect pass tests
r15013 a.value = 5
self.assertNotEqual(a.value, b.value)
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018
def test_callbacks(self):
Jason Grout
Change 'bind' to 'link'
r15163 """Verify two linked traitlets have their callbacks called once."""
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018
# Create two simple classes with Int traitlets.
class A(HasTraits):
value = Int()
class B(HasTraits):
count = Int()
a = A(value=9)
b = B(count=8)
zah
Implementation in TraitType directly.
r16453
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018 # Register callbacks that count.
callback_count = []
def a_callback(name, old, new):
callback_count.append('a')
a.on_trait_change(a_callback, 'value')
def b_callback(name, old, new):
callback_count.append('b')
b.on_trait_change(b_callback, 'count')
Jason Grout
Change 'bind' to 'link'
r15163 # Connect the two classes.
c = link((a, 'value'), (b, 'count'))
Jonathan Frederic
Use closure to prevent traitlet callbacks from firing twice.
r15018
# Make sure b's count was set to a's value once.
self.assertEqual(''.join(callback_count), 'b')
del callback_count[:]
# Make sure a's value was set to b's count once.
b.count = 5
self.assertEqual(''.join(callback_count), 'ba')
del callback_count[:]
# Make sure b's count was set to a's value once.
a.value = 4
self.assertEqual(''.join(callback_count), 'ab')
del callback_count[:]
Min RK
Make HasTraits pickleable...
r16216
class Pickleable(HasTraits):
i = Int()
j = Int()
def _i_default(self):
return 1
def _i_changed(self, name, old, new):
self.j = new
def test_pickle_hastraits():
c = Pickleable()
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(c, protocol)
c2 = pickle.loads(p)
nt.assert_equal(c2.i, c.i)
nt.assert_equal(c2.j, c.j)
c.i = 5
for protocol in range(pickle.HIGHEST_PROTOCOL + 1):
p = pickle.dumps(c, protocol)
c2 = pickle.loads(p)
nt.assert_equal(c2.i, c.i)
nt.assert_equal(c2.j, c.j)
Thomas Kluyver
Merge pull request #5502 from Zaharid/iniinstance...
r16545