This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dmalcolm
Recipients dmalcolm
Date 2010-01-18.23:24:28
SpamBayes Score 3.3862594e-07
Marked as misclassified No
Message-id <1263857088.57.0.971642204628.issue7737@psf.upfronthosting.co.za>
In-reply-to
Content
In many places throughout the existing test suite, there are assertions of the form:
     self.assertTrue(chips in menu)
and of the form:
     self.assertTrue(cheese not in shop)

If these fail, the error message will merely tell you that the condition failed, without telling you the values.

Some of these tests have an additional handcoded "msg" argument.

The attached patch (to the py3k branch) changes all of these assertions to use the assertIn and assertNotIn methods: when these fail, the log will indicate the repr() of the left- and right- hand sides.

If a "msg" argument was provided which isn't the left or right-hand side, I supply that as a third argument (which these methods can also accept).

I generated this patch using this pair of shell commands:

# Fixup "not in":
find Lib/test -name test_\*.py \
    | xargs sed --in-place -r -e "s|self.assertTrue\((.*) not in (.*)\)|self.assertNotIn(\1, \2)|g"

# Fixup "in":
find Lib/test -name test_\*.py \
    | xargs sed --in-place -r -e "s|self.assertTrue\((.*) in (.*)\)|self.assertIn(\1, \2)|g"

and then manually fixing the tests until they worked (the above isn't perfect, but was close enough, if I had to do it again I'd write a python script).

I edited some of the basic tests for collections that verify in/not-in semantics, so that both forms of test are present (using the assertIn variant first, to provide better logs in the event of failure.  I'm not sure that doing so is meaningful though (assertIn does a "member not in container", and assertNotIn does a "member in container" test).

I've rerun the test on my local build, and verified the code visually (however the patch is rather large so I may have missed something):
  75 files changed, 471 insertions(+), 454 deletions(-)

(suggested by http://bugs.python.org/msg97856 )
History
Date User Action Args
2010-01-18 23:24:49dmalcolmsetrecipients: + dmalcolm
2010-01-18 23:24:48dmalcolmsetmessageid: <1263857088.57.0.971642204628.issue7737@psf.upfronthosting.co.za>
2010-01-18 23:24:47dmalcolmlinkissue7737 messages
2010-01-18 23:24:46dmalcolmcreate