##// END OF EJS Templates
[utils][tests][dir2] Remove nose
Samuel Gaist -
Show More
@@ -1,58 +1,58 b''
1 import nose.tools as nt
2 from IPython.utils.dir2 import dir2
1 from IPython.utils.dir2 import dir2
3
2
4
3
5 class Base(object):
4 class Base(object):
6 x = 1
5 x = 1
7 z = 23
6 z = 23
8
7
9
8
10 def test_base():
9 def test_base():
11 res = dir2(Base())
10 res = dir2(Base())
12 assert ('x' in res)
11 assert "x" in res
13 assert ('z' in res)
12 assert "z" in res
14 assert ('y' not in res)
13 assert "y" not in res
15 assert ('__class__' in res)
14 assert "__class__" in res
16 nt.assert_equal(res.count('x'), 1)
15 assert res.count("x") == 1
17 nt.assert_equal(res.count('__class__'), 1)
16 assert res.count("__class__") == 1
17
18
18
19 def test_SubClass():
19 def test_SubClass():
20
20
21 class SubClass(Base):
21 class SubClass(Base):
22 y = 2
22 y = 2
23
23
24 res = dir2(SubClass())
24 res = dir2(SubClass())
25 assert ('y' in res)
25 assert "y" in res
26 nt.assert_equal(res.count('y'), 1)
26 assert res.count("y") == 1
27 nt.assert_equal(res.count('x'), 1)
27 assert res.count("x") == 1
28
28
29
29
30 def test_SubClass_with_trait_names_attr():
30 def test_SubClass_with_trait_names_attr():
31 # usecase: trait_names is used in a class describing psychological classification
31 # usecase: trait_names is used in a class describing psychological classification
32
32
33 class SubClass(Base):
33 class SubClass(Base):
34 y = 2
34 y = 2
35 trait_names = 44
35 trait_names = 44
36
36
37 res = dir2(SubClass())
37 res = dir2(SubClass())
38 assert('trait_names' in res)
38 assert('trait_names' in res)
39
39
40
40
41 def test_misbehaving_object_without_trait_names():
41 def test_misbehaving_object_without_trait_names():
42 # dir2 shouldn't raise even when objects are dumb and raise
42 # dir2 shouldn't raise even when objects are dumb and raise
43 # something other than AttribteErrors on bad getattr.
43 # something other than AttribteErrors on bad getattr.
44
44
45 class MisbehavingGetattr(object):
45 class MisbehavingGetattr(object):
46 def __getattr__(self):
46 def __getattr__(self):
47 raise KeyError("I should be caught")
47 raise KeyError("I should be caught")
48
48
49 def some_method(self):
49 def some_method(self):
50 pass
50 pass
51
51
52 class SillierWithDir(MisbehavingGetattr):
52 class SillierWithDir(MisbehavingGetattr):
53 def __dir__(self):
53 def __dir__(self):
54 return ['some_method']
54 return ['some_method']
55
55
56 for bad_klass in (MisbehavingGetattr, SillierWithDir):
56 for bad_klass in (MisbehavingGetattr, SillierWithDir):
57 res = dir2(bad_klass())
57 res = dir2(bad_klass())
58 assert('some_method' in res)
58 assert('some_method' in res)
General Comments 0
You need to be logged in to leave comments. Login now