|
[Webware-checkins] CVS: Webware/MiscUtils/Testing TestFuncs.py,1.9,1.10
From: Chuck Esterbrook <echuck@us...> - 2003-10-29 08:53
|
Update of /cvsroot/webware/Webware/MiscUtils/Testing
In directory sc8-pr-cvs1:/tmp/cvs-serv23017/Testing
Modified Files:
TestFuncs.py
Log Message:
- added safeDescription()
Index: TestFuncs.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiscUtils/Testing/TestFuncs.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** TestFuncs.py 29 Dec 2002 01:47:58 -0000 1.9
--- TestFuncs.py 29 Oct 2003 08:53:14 -0000 1.10
***************
*** 58,61 ****
--- 58,94 ----
+ def TestSafeDescription():
+ # @@ I think these tests could fail in earlier versions of Python
+ # because types displayed slightly different names.
+ sd = safeDescription
+
+ # basics:
+ assert sd(1)=="what=1 class=<type 'int'>", sd(1)
+ assert sd(1, 'x')=="x=1 class=<type 'int'>", sd(1, 'x')
+ assert sd('x')=="what='x' class=<type 'str'>", sd('x')
+ class Foo: pass
+ f = Foo()
+ assert sd(f).find('__main__.Foo')!=-1, sd(f)
+
+ # new object type:
+ try:
+ object # more recent versions of Python have a builtin object type
+ except NameError:
+ pass # must be old Python
+ else:
+ class Bar(object): pass
+ b = Bar()
+ assert sd(b).find('__main__.Bar')!=-1, sd(b)
+
+ # okay now test that safeDescription eats exceptions from repr():
+ class Baz:
+ def __repr__(self):
+ raise KeyError, 'bogus'
+ b = Baz()
+ try:
+ assert sd(b).find("(exception from repr(x): exceptions.KeyError: 'bogus')")!=-1, sd(b)
+ except:
+ assert 0, 'failure: should not get exception'
+
def TestUniqueId():
lastResult = None
***************
*** 88,92 ****
"""1234"""
'''
!
stringCases = '''
kjasdfkasdf
--- 121,125 ----
"""1234"""
'''
!
stringCases = '''
kjasdfkasdf
***************
*** 126,129 ****
--- 159,163 ----
TestHostName()
TestLocalIP()
+ TestSafeDescription()
TestUniqueId()
TestValueForString()
|
| Thread | Author | Date |
|---|---|---|
| [Webware-checkins] CVS: Webware/MiscUtils/Testing TestFuncs.py,1.9,1.10 | Chuck Esterbrook <echuck@us...> |