[New-bugs-announce] [issue20510] Test cases in test_sys don't match the comments

Gareth Rees report at bugs.python.org
Tue Feb 4 17:09:06 CET 2014


New submission from Gareth Rees:

Lib/test/test_sys.py contains test cases with incorrect comments -- or
comments with incorrect test cases, if you prefer:

    # call without argument
    try:
        sys.exit(0)
    except SystemExit as exc:
        self.assertEqual(exc.code, 0)
    ...

    # call with tuple argument with one entry
    # entry will be unpacked
    try:
        sys.exit(42)
    except SystemExit as exc:
        self.assertEqual(exc.code, 42)
    ...

    # call with integer argument
    try:
        sys.exit((42,))
    except SystemExit as exc:
        self.assertEqual(exc.code, 42)
    ...

(In the quote above I've edited out some inessential detail; see the
file if you really want to know.)

You can see that in the first test case sys.exit is called with an
argument (although the comment claims otherwise); in the second it is
called with an integer (not a tuple), and in the third it is called
with a tuple (not an integer).

These comments have been unchanged since the original commit by Walter
Dörwald <http://hg.python.org/cpython/rev/6a1394660270>. I've attached
a patch that corrects the first test case and swaps the comments for
the second and third test cases:

    # call without argument
    rc = subprocess.call([sys.executable, "-c",
                          "import sys; sys.exit()"])
    self.assertEqual(rc, 0)

    # call with integer argument
    try:
        sys.exit(42)
    except SystemExit as exc:
        self.assertEqual(exc.code, 42)
    ...

    # call with tuple argument with one entry
    # entry will be unpacked
    try:
        sys.exit((42,))
    except SystemExit as exc:
        self.assertEqual(exc.code, 42)
    ...

Note that in the first test case (without an argument) sys.exit() with
no argument actually raises SystemExit(None), so it's not sufficient
to catch the SystemExit and check exc.code; I need to check that it
actually gets translated to 0 on exit.

----------
components: Tests
files: exittest.patch
keywords: patch
messages: 210246
nosy: Gareth.Rees
priority: normal
severity: normal
status: open
title: Test cases in test_sys don't match the comments
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file33908/exittest.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20510>
_______________________________________


More information about the New-bugs-announce mailing list