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 | 336 | #io.rprint('Completer->attr_matches, txt=%r' % text) # dbg |
|
337 | 337 | # Another option, seems to work great. Catches things like ''.<tab> |
|
338 | 338 | m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text) |
|
339 | ||
|
339 | 340 | if m: |
|
340 | 341 | expr, attr = m.group(1, 3) |
|
341 | 342 | elif self.greedy: |
@@ -18,7 +18,6 b' from IPython.core import completer' | |||
|
18 | 18 | from IPython.external.decorators import knownfailureif |
|
19 | 19 | from IPython.utils.tempdir import TemporaryDirectory |
|
20 | 20 | from IPython.utils.generics import complete_object |
|
21 | from IPython.testing.globalipapp import get_ipython | |
|
22 | 21 | |
|
23 | 22 | #----------------------------------------------------------------------------- |
|
24 | 23 | # Test functions |
General Comments 0
You need to be logged in to leave comments.
Login now