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 gdr@garethrees.org
Recipients gdr@garethrees.org
Date 2014-02-04.16:09:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1391530146.21.0.549410928914.issue20510@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-02-04 16:09:06gdr@garethrees.orgsetrecipients: + gdr@garethrees.org
2014-02-04 16:09:06gdr@garethrees.orgsetmessageid: <1391530146.21.0.549410928914.issue20510@psf.upfronthosting.co.za>
2014-02-04 16:09:06gdr@garethrees.orglinkissue20510 messages
2014-02-04 16:09:05gdr@garethrees.orgcreate