Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'tests.': 0.07; 'from:addr:web.de': 0.09; 'url:peps': 0.09; '*type*': 0.16; 'devs': 0.16; 'finney': 0.16; 'ioerror:': 0.16; "one's": 0.16; 'received:80.91': 0.16; 'received:80.91.229': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:gmane.org': 0.16; 'received:list': 0.16; 'received:t-dialin.net': 0.16; 'returns,': 0.16; 'subject:instance': 0.16; 'subject:type': 0.16; 'subject:unittest': 0.16; 'fix': 0.20; 'wrote:': 0.21; 'exception': 0.22; 'url:dev': 0.22; 'header:User-Agent:1': 0.23; 'permission': 0.23; 'test': 0.24; 'error': 0.25; 'equivalent': 0.27; "python's": 0.27; 'seems': 0.28; 'subject:with': 0.28; '(by': 0.29; 'code': 0.29; 'file': 0.29; 'question': 0.30; 'normally': 0.33; 'operating': 0.34; 'url:python': 0.34; "skip:' 10": 0.35; '(most': 0.35; 'ben': 0.35; 'writes:': 0.35; 'header:X -Complaints-To:1': 0.36; 'url:org': 0.36; 'unit': 0.38; 'received:org': 0.38; 'core': 0.39; 'to:addr:python-list': 0.39; 'to:addr:python.org': 0.40; 'such': 0.61; 'call': 0.62; 'built- in': 0.67; 'codes.': 0.84; 'directory:': 0.84; 'last):': 0.91; 'acts': 0.95 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: unittest: assertRaises() with an instance instead of a type Date: Thu, 29 Mar 2012 08:55:53 +0200 Organization: None References: <4f735345$0$29981$c3e8da3$5496439d@news.astraweb.com> <87mx70f9xa.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p50849205.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1333004116 news.xs4all.nl 6938 [2001:888:2000:d::a6]:46872 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:22329 Ben Finney wrote: > Steven D'Aprano writes: > >> (By the way, I have to question the design of an exception with error >> codes. That seems pretty poor design to me. Normally the exception *type* >> acts as equivalent to an error code.) > > Have a look at Python's built-in OSError. The various errors from the > operating system can only be distinguished by the numeric code the OS > returns, so that's what to test on in one's unit tests. The core devs are working to fix that: $ python3.2 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.3 -c'open("does-not-exist")' Traceback (most recent call last): File "", line 1, in FileNotFoundError: [Errno 2] No such file or directory: 'does-not-exist' $ python3.2 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in IOError: [Errno 13] Permission denied: 'unwritable' $ python3.3 -c'open("unwritable", "w")' Traceback (most recent call last): File "", line 1, in PermissionError: [Errno 13] Permission denied: 'unwritable' http://www.python.org/dev/peps/pep-3151/