Ben Finney wrote:
Scott David Daniels <[EMAIL PROTECTED]> writes:>
I would rather something more like:
def assert_compare_true(op, first, second, msg=None):
if op(first, second):
return
raise self.failure_exception(msg)
if msg is None:
self.failure_exception("%(first)r %(op)r %(second)"
% vars())
self.failure_exception("%(first)r %(op)r %(second): %(msg)"
% vars())
I'm confused. It appears to me that your version never gets past the
first 'raise' statement, which is unconditional; and the rest seems to
do nothing but instantiate exceptions without using them.
Sorry, I was too hasty last time (had to jet out of the house) and sent
out the unfinished version. This is what I meant:
def assert_compare_true(op, first, second, msg=None):
if op(first, second):
return
if msg is None:
raise self.failure_exception(
"%(first)r %(op)r %(second)" % vars())
raise self.failure_exception(
"%(first)r %(op)r %(second): %(msg)" % vars())
(1) Displaying args is the whole point, otherwise just use assert_.
This form fosters tests that say what is wrong, and not simply
_that_ something has gone wrong.
The point is a readable test, reducing boilerplate at the
call location. Something like:
...
self.assert_le(sum(source) // len(source), 5, "Mean OK")
(2) No point to doing string conversion except on failure; slow
__repr__ methods are fine to use if the result is not discarded.
--Scott David Daniels
[EMAIL PROTECTED]
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com