diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-07-30 22:49:11 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-07-30 22:49:11 (GMT) |
commit | b7a7731e018283a4ee3dcb65c25175b62691fd34 (patch) | |
tree | e9dfd2a2610b030af384826e3745e054b3ad973c /Lib/test | |
parent | 302b54acd91f999c039f9a3618f734dbdfb74467 (diff) | |
download | cpython-b7a7731e018283a4ee3dcb65c25175b62691fd34.zip cpython-b7a7731e018283a4ee3dcb65c25175b62691fd34.tar.gz cpython-b7a7731e018283a4ee3dcb65c25175b62691fd34.tar.bz2 |
Add tests for getattr() and hasattr() with non-string args
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_b1.py | 18 | ||||
-rw-r--r-- | Lib/test/test_b2.py | 6 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index bddd157..1103a03 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -256,10 +256,28 @@ if float(u" \u0663.\u0661\u0664 ") != 3.14: print 'getattr' import sys if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr' +try: + getattr(sys, 1) +except TypeError: + pass +else: + raise TestFailed, "getattr(sys, 1) should raise an exception" +try: + getattr(sys, 1, "foo") +except TypeError: + pass +else: + raise TestFailed, 'getattr(sys, 1, "foo") should raise an exception' print 'hasattr' import sys if not hasattr(sys, 'stdout'): raise TestFailed, 'hasattr' +try: + hasattr(sys, 1) +except TypeError: + pass +else: + raise TestFailed, "hasattr(sys, 1) should raise an exception" print 'hash' hash(None) diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py index cfc461c..ae07f5b 100644 --- a/Lib/test/test_b2.py +++ b/Lib/test/test_b2.py @@ -205,6 +205,12 @@ print 'setattr' import sys setattr(sys, 'spam', 1) if sys.spam != 1: raise TestFailed, 'setattr(sys, \'spam\', 1)' +try: + setattr(sys, 1, 'spam') +except TypeError: + pass +else: + raise TestFailed, "setattr(sys, 1, 'spam') should raise exception" print 'str' if str('') != '': raise TestFailed, 'str(\'\')' |