2
2
3
3
import os
4
4
5
+ from bpython ._py3compat import py3
5
6
from bpython import inspection
6
7
from bpython .test import unittest
7
8
from bpython .test .fodder import encoding_ascii
20
21
'''
21
22
22
23
23
- class TestInspection (unittest .TestCase ):
24
- def test_is_callable (self ):
25
- class OldCallable :
26
- def __call__ (self ):
27
- pass
24
+ class OldCallable :
25
+ def __call__ (self ):
26
+ pass
28
27
29
- class Callable (object ):
30
- def __call__ (self ):
31
- pass
32
28
33
- class OldNoncallable :
34
- pass
29
+ class Callable (object ):
30
+ def __call__ (self ):
31
+ pass
35
32
36
- class Noncallable (object ):
37
- pass
38
33
39
- def spam ():
40
- pass
34
+ class OldNoncallable :
35
+ pass
36
+
37
+
38
+ class Noncallable (object ):
39
+ pass
41
40
42
- class CallableMethod (object ):
43
- def method (self ):
44
- pass
45
41
42
+ def spam ():
43
+ pass
44
+
45
+
46
+ class CallableMethod (object ):
47
+ def method (self ):
48
+ pass
49
+
50
+
51
+ class TestInspection (unittest .TestCase ):
52
+ def test_is_callable (self ):
46
53
self .assertTrue (inspection .is_callable (spam ))
47
54
self .assertTrue (inspection .is_callable (Callable ))
48
55
self .assertTrue (inspection .is_callable (Callable ()))
@@ -53,6 +60,25 @@ def method(self):
53
60
self .assertFalse (inspection .is_callable (None ))
54
61
self .assertTrue (inspection .is_callable (CallableMethod ().method ))
55
62
63
+ @unittest .skipIf (py3 , 'old-style classes only exist in Python 2' )
64
+ def test_is_new_style_py2 (self ):
65
+ self .assertTrue (inspection .is_new_style (spam ))
66
+ self .assertTrue (inspection .is_new_style (Noncallable ))
67
+ self .assertFalse (inspection .is_new_style (OldNoncallable ))
68
+ self .assertTrue (inspection .is_new_style (Noncallable ()))
69
+ self .assertFalse (inspection .is_new_style (OldNoncallable ()))
70
+ self .assertTrue (inspection .is_new_style (None ))
71
+
72
+ @unittest .skipUnless (py3 , 'only in Python 3 are all classes new-style' )
73
+ def test_is_new_style_py3 (self ):
74
+ self .assertTrue (inspection .is_new_style (spam ))
75
+ self .assertTrue (inspection .is_new_style (Noncallable ))
76
+ self .assertTrue (inspection .is_new_style (OldNoncallable ))
77
+ self .assertTrue (inspection .is_new_style (Noncallable ()))
78
+ self .assertTrue (inspection .is_new_style (OldNoncallable ()))
79
+ self .assertTrue (inspection .is_new_style (None ))
80
+
81
+
56
82
def test_parsekeywordpairs (self ):
57
83
# See issue #109
58
84
def fails (spam = ['-a' , '-b' ]):
0 commit comments