##// END OF EJS Templates
Added test_dir2 for the dir2 (bonus) tests...
Tim Couper -
Show More
@@ -0,0 +1,51 b''
1 import nose.tools as nt
2 from IPython.utils.dir2 import dir2
3
4
5 class Base(object):
6 x = 1
7 z = 23
8
9
10 def test_base():
11 res = dir2(Base())
12 assert ('x' in res)
13 assert ('z' in res)
14 assert ('y' not in res)
15 assert ('__class__' in res)
16 nt.assert_equal(res.count('x'), 2) # duplicates
17 nt.assert_equal(res.count('__class__'), 4) # duplicates
18
19 def test_SubClass():
20
21 class SubClass(Base):
22 y = 2
23
24 res = dir2(SubClass())
25 assert ('y' in res)
26 nt.assert_equal(res.count('y'), 2) # duplicates,
27 nt.assert_equal(res.count('x'), 3) # duplicates, but fewer than above!
28
29
30 def test_SubClass_with_trait_names_method():
31
32 class SubClass(Base):
33 y = 2
34 def trait_names(self):
35 return ['t', 'umbrella']
36
37 res = dir2(SubClass())
38 assert('trait_names' in res)
39 assert('umbrella' in res)
40 nt.assert_equal(res.count('t'), 1)
41
42
43 def test_SubClass_with_trait_names_attr():
44 # usecase: trait_names is used in a class describing psychological classification
45
46 class SubClass(Base):
47 y = 2
48 trait_names = 44
49
50 res = dir2(SubClass())
51 assert('trait_names' in res)
@@ -336,6 +336,7 b' class Completer(Configurable):'
336 #io.rprint('Completer->attr_matches, txt=%r' % text) # dbg
336 #io.rprint('Completer->attr_matches, txt=%r' % text) # dbg
337 # Another option, seems to work great. Catches things like ''.<tab>
337 # Another option, seems to work great. Catches things like ''.<tab>
338 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
338 m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)
339
339 if m:
340 if m:
340 expr, attr = m.group(1, 3)
341 expr, attr = m.group(1, 3)
341 elif self.greedy:
342 elif self.greedy:
@@ -345,7 +346,7 b' class Completer(Configurable):'
345 expr, attr = m2.group(1,2)
346 expr, attr = m2.group(1,2)
346 else:
347 else:
347 return []
348 return []
348
349
349 try:
350 try:
350 obj = eval(expr, self.namespace)
351 obj = eval(expr, self.namespace)
351 except:
352 except:
@@ -18,7 +18,6 b' from IPython.core import completer'
18 from IPython.external.decorators import knownfailureif
18 from IPython.external.decorators import knownfailureif
19 from IPython.utils.tempdir import TemporaryDirectory
19 from IPython.utils.tempdir import TemporaryDirectory
20 from IPython.utils.generics import complete_object
20 from IPython.utils.generics import complete_object
21 from IPython.testing.globalipapp import get_ipython
22
21
23 #-----------------------------------------------------------------------------
22 #-----------------------------------------------------------------------------
24 # Test functions
23 # Test functions
@@ -241,4 +240,4 b' def test_get__all__entries_no__all__ok():'
241 class A(object):
240 class A(object):
242 pass
241 pass
243 words = completer.get__all__entries(A())
242 words = completer.get__all__entries(A())
244 nt.assert_equal(words, []) No newline at end of file
243 nt.assert_equal(words, [])
General Comments 0
You need to be logged in to leave comments. Login now