assertEquals( exp, got[, message] ) Two objects test as "equal" if: * they are the same object as tested by the 'is' operator. * either object is a float or complex number and the absolute value of the difference between the two is less than 1e-8.
( exp, got, msg = None )
| 243 | from types import FloatType, ComplexType |
| 244 | |
| 245 | def assertEquals( exp, got, msg = None ): |
| 246 | """assertEquals( exp, got[, message] ) |
| 247 | |
| 248 | Two objects test as "equal" if: |
| 249 | |
| 250 | * they are the same object as tested by the 'is' operator. |
| 251 | * either object is a float or complex number and the absolute |
| 252 | value of the difference between the two is less than 1e-8. |
| 253 | * applying the equals operator ('==') returns True. |
| 254 | """ |
| 255 | if exp is got: |
| 256 | r = True |
| 257 | elif ( type( exp ) in ( FloatType, ComplexType ) or |
| 258 | type( got ) in ( FloatType, ComplexType ) ): |
| 259 | r = abs( exp - got ) < 1e-8 |
| 260 | else: |
| 261 | r = ( exp == got ) |
| 262 | if not r: |
| 263 | print >>sys.stderr, "Error: expected <%s> but got <%s>%s" % ( repr( exp ), repr( got ), colon( msg ) ) |
| 264 | traceback.print_stack() |
| 265 | |
| 266 | def assertException( exceptionType, f, msg = None ): |
| 267 | """Assert that an exception of type \var{exceptionType} |