classification
Title: test_any and test_all should validate short-circuiting behaviour
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.4, Python 3.3, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ezio.melotti Nosy List: ezio.melotti, python-dev, wim.glenn
Priority: normal Keywords: patch

Created on 2013-02-20 12:32 by wim.glenn, last changed 2013-02-21 21:18 by ezio.melotti. This issue is now closed.

Files
File name Uploaded Description Edit
mywork.patch wim.glenn, 2013-02-20 12:32 patch for short-circuiting test cases review
Messages (3)
msg182496 - (view) Author: wim glenn (wim.glenn) * Date: 2013-02-20 12:32
The docs http://docs.python.org/2/library/functions.html#all provide some equivalent code for all builtin (and similarly for any):

def all(iterable):
    for element in iterable:
        if not element:
            return False
    return True

The behaviour is clearly documented as short-circuiting, but the cases contained in test_builtin.py are lacking any test coverage for the short-circuiting behaviour.  You could implement any/all in a broken way that still passes the current tests (consuming more of a generator than you want to for example), so it is important to guarantee the short-circuiting.

My patch adds two simple test cases to make this behaviour explicit.
msg182609 - (view) Author: Roundup Robot (python-dev) Date: 2013-02-21 21:17
New changeset 124237eb5de9 by Ezio Melotti in branch '2.7':
#17255: test short-circuiting behavior of any()/all().  Patch by Wim Glenn.
http://hg.python.org/cpython/rev/124237eb5de9

New changeset 34b7240d678b by Ezio Melotti in branch '3.2':
#17255: test short-circuiting behavior of any()/all().  Patch by Wim Glenn.
http://hg.python.org/cpython/rev/34b7240d678b

New changeset 576d2c885eb6 by Ezio Melotti in branch '3.3':
#17255: merge with 3.2.
http://hg.python.org/cpython/rev/576d2c885eb6

New changeset c65fcedc511c by Ezio Melotti in branch 'default':
#17255: merge with 3.3.
http://hg.python.org/cpython/rev/c65fcedc511c
msg182610 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2013-02-21 21:18
Fixed, thanks for the report and the patch!
History
Date User Action Args
2013-02-21 21:18:28ezio.melottisetstatus: open -> closed

assignee: ezio.melotti
versions: - Python 2.6, Python 3.1, Python 3.5
nosy: + ezio.melotti

messages: + msg182610
resolution: fixed
stage: resolved
2013-02-21 21:17:48python-devsetnosy: + python-dev
messages: + msg182609
2013-02-20 12:32:03wim.glenncreate