22
33import os
44
5+ from bpython ._py3compat import py3
56from bpython import inspection
67from bpython .test import unittest
78from bpython .test .fodder import encoding_ascii
2021'''
2122
2223
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
2827
29- class Callable (object ):
30- def __call__ (self ):
31- pass
3228
33- class OldNoncallable :
34- pass
29+ class Callable (object ):
30+ def __call__ (self ):
31+ pass
3532
36- class Noncallable (object ):
37- pass
3833
39- def spam ():
40- pass
34+ class OldNoncallable :
35+ pass
36+
37+
38+ class Noncallable (object ):
39+ pass
4140
42- class CallableMethod (object ):
43- def method (self ):
44- pass
4541
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 ):
4653 self .assertTrue (inspection .is_callable (spam ))
4754 self .assertTrue (inspection .is_callable (Callable ))
4855 self .assertTrue (inspection .is_callable (Callable ()))
@@ -53,6 +60,25 @@ def method(self):
5360 self .assertFalse (inspection .is_callable (None ))
5461 self .assertTrue (inspection .is_callable (CallableMethod ().method ))
5562
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+
5682 def test_parsekeywordpairs (self ):
5783 # See issue #109
5884 def fails (spam = ['-a' , '-b' ]):
0 commit comments