]> granicus.if.org Git - python/commitdiff
Add tests for getattr() and hasattr() with non-string args
authorJeremy Hylton <jeremy@alum.mit.edu>
Mon, 30 Jul 2001 22:49:11 +0000 (22:49 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Mon, 30 Jul 2001 22:49:11 +0000 (22:49 +0000)
Lib/test/test_b1.py
Lib/test/test_b2.py

index bddd157ad5477189caa37f2d175de98af12bb5fe..1103a0397338d8191aef6fb9950bc9618a08ca64 100644 (file)
@@ -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)
index cfc461c054dc97f69312825479c813f51455e800..ae07f5b8def62bdb8494e9ae7abe3e645fa336ff 100644 (file)
@@ -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(\'\')'