[Python-checkins] (2.7): Use simpler assert in basic example.

Nick Coghlan ncoghlan at gmail.com
Fri Mar 11 03:45:50 CET 2011


On Thu, Mar 10, 2011 at 4:36 PM, ezio.melotti
<python-checkins at python.org> wrote:
> http://hg.python.org/cpython/rev/9adc4792db9a
> changeset:   68356:9adc4792db9a
> branch:      2.7
> user:        Ezio Melotti <ezio.melotti at gmail.com>
> date:        Thu Mar 10 23:35:39 2011 +0200
> summary:
>  Use simpler assert in basic example.

Please don't. Now the new methods are available, using assertTrue() on
supported expressions is actively throwing away data, and the docs
shouldn't recommend it *anywhere*.

If using assertIn() at this point in the docs is a genuine problem,
find an alternative test example that isn't better written using one
of the more specific methods.

Cheers,
Nick.

>
> files:
>  Doc/library/unittest.rst
>
> diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
> --- a/Doc/library/unittest.rst
> +++ b/Doc/library/unittest.rst
> @@ -130,13 +130,13 @@
>
>        def test_choice(self):
>            element = random.choice(self.seq)
> -           self.assertIn(element, self.seq)
> +           self.assertTrue(element in self.seq)
>
>        def test_sample(self):
>            with self.assertRaises(ValueError):
>                random.sample(self.seq, 20)
>            for element in random.sample(self.seq, 5):
> -               self.assertIn(element, self.seq)
> +               self.assertTrue(element in self.seq)
>
>    if __name__ == '__main__':
>        unittest.main()
>
> --
> Repository URL: http://hg.python.org/cpython
>
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> http://mail.python.org/mailman/listinfo/python-checkins
>
>



-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-checkins mailing list