diff options
author | Barry Warsaw <barry@python.org> | 1997-08-22 21:27:03 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1997-08-22 21:27:03 (GMT) |
commit | d543077aa669fbaf531405a4eb13136170bfe432 (patch) | |
tree | 5f69cd600582e0cb24349f160577e5d016df322b | |
parent | 4249f54b28563eff28e3ba428e65905d8112100a (diff) | |
download | cpython-d543077aa669fbaf531405a4eb13136170bfe432.zip cpython-d543077aa669fbaf531405a4eb13136170bfe432.tar.gz cpython-d543077aa669fbaf531405a4eb13136170bfe432.tar.bz2 |
Added tests of the new builtin functions issubclass() and isinstance()
-rw-r--r-- | Lib/test/test_b1.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index 8d8a725..747fc9a 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -236,6 +236,42 @@ if int(-3.9) <> -3: raise TestFailed, 'int(-3.9)' if int(3.5) <> 3: raise TestFailed, 'int(3.5)' if int(-3.5) <> -3: raise TestFailed, 'int(-3.5)' +print 'isinstance' +class C: + pass +class D(C): + pass +class E: + pass +c = C() +d = D() +e = E() +if not isinstance(c, C): raise TestFailed, 'isinstance(c, C)' +if not isinstance(d, C): raise TestFailed, 'isinstance(d, C)' +if isinstance(e, C): raise TestFailed, 'isinstance(e, C)' +if isinstance(c, D): raise TestFailed, 'isinstance(c, D)' +if isinstance('foo', E): raise TestFailed, 'isinstance("Foo", E)' +try: + isinstance(E, 'foo') + raise TestFailed, 'isinstance(E, "foo")' +except TypeError: + pass + +print 'issubclass' +if not issubclass(D, C): raise TestFailed, 'issubclass(D, C)' +if not issubclass(C, C): raise TestFailed, 'issubclass(C, C)' +if issubclass(C, D): raise TestFailed, 'issubclass(C, D)' +try: + issubclass('foo', E) + raise TestFailed, 'issubclass("foo", E)' +except TypeError: + pass +try: + issubclass(E, 'foo') + raise TestFailed, 'issubclass(E, "foo")' +except TypeError: + pass + print 'len' if len('123') <> 3: raise TestFailed, 'len(\'123\')' if len(()) <> 0: raise TestFailed, 'len(())' |