[py-svn] r57263 - in py/branch/event/py/code: . testing

hpk at codespeak.net hpk at codespeak.net
Fri Aug 15 11:07:32 CEST 2008


Author: hpk
Date: Fri Aug 15 11:07:31 2008
New Revision: 57263

Modified:
   py/branch/event/py/code/code.py
   py/branch/event/py/code/testing/test_code.py
Log:
consistently return TypeError for non-code objects


Modified: py/branch/event/py/code/code.py
==============================================================================
--- py/branch/event/py/code/code.py	(original)
+++ py/branch/event/py/code/code.py	Fri Aug 15 11:07:31 2008
@@ -6,12 +6,12 @@
         rawcode = getattr(rawcode, 'im_func', rawcode)
         rawcode = getattr(rawcode, 'func_code', rawcode)
         self.raw = rawcode 
-        self.filename = rawcode.co_filename
         try:
+            self.filename = rawcode.co_filename
             self.firstlineno = rawcode.co_firstlineno - 1
+            self.name = rawcode.co_name
         except AttributeError: 
             raise TypeError("not a code object: %r" %(rawcode,))
-        self.name = rawcode.co_name
         
     def __eq__(self, other): 
         return self.raw == other.raw

Modified: py/branch/event/py/code/testing/test_code.py
==============================================================================
--- py/branch/event/py/code/testing/test_code.py	(original)
+++ py/branch/event/py/code/testing/test_code.py	Fri Aug 15 11:07:31 2008
@@ -78,4 +78,8 @@
     code = py.code.Code(co_code)
     assert str(code.path) == name 
     assert code.fullsource is None
-    
+   
+def test_code_with_class():
+    class A:
+        pass
+    py.test.raises(TypeError, "py.code.Code(A)")



More information about the pytest-commit mailing list