Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'filing': 0.07; 'here?': 0.09; 'indeed,': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; '"""return': 0.16; '201': 0.16; 'b):': 0.16; 'charles': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'function?': 0.16; 'losing': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'portable': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'robust.': 0.16; 'sheer': 0.16; 'simpson': 0.16; 'stdlib.': 0.16; 'syntax,': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.18; 'module': 0.19; 'skip:f 30': 0.19; 'later': 0.20; 'cc:addr:python.org': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'this:': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; "doesn't": 0.30; 'convince': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'fri,': 0.33; "i'd": 0.34; 'something': 0.35; 'test': 0.35; 'received:com.au': 0.36; "i'll": 0.36; 'unit': 0.37; 'so,': 0.37; 'received:211': 0.38; 'rather': 0.38; 'aside': 0.39; 'users': 0.40; 'skip:u 10': 0.60; 'black': 0.61; 'simple': 0.61; 'content-disposition:inline': 0.62; 'become': 0.64; 'provide': 0.64; 'drm': 0.84; 'pirates': 0.84; 'not:': 0.91; 'whereas': 0.91; '2013': 0.98 Date: Fri, 11 Oct 2013 14:13:19 +1100 From: Cameron Simpson To: Steven D'Aprano Subject: Re: Skipping decorators in unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <525768a5$0$29984$c3e8da3$5496439d@news.astraweb.com> User-Agent: Mutt/1.5.21 (2010-09-15) References: <525768a5$0$29984$c3e8da3$5496439d@news.astraweb.com> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=bpB1Wiqi c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=LcaDllckn3IA:10 a=MIEZmskQDU0A:10 a=IkcTkHD0fZMA:10 a=vrnE16BAAAAA:8 a=AS59is4VRK8A:10 a=kZ7UWmmPAAAA:8 a=Zxz3DMRhNio38qFk4IQA:9 a=QEXdDO2ut3YA:10 a=pyH5b1fOeEsA:10 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1381461210 news.xs4all.nl 15957 [2001:888:2000:d::a6]:45567 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:56640 On 11Oct2013 02:55, Steven D'Aprano wrote: > On Fri, 11 Oct 2013 09:12:38 +1100, Cameron Simpson wrote: > > Speaking for myself, I would be include to recast this code: > > > > @absolutize > > def addition(a, b): > > return a + b > > > > into: > > > > def _addition(a, b): > > return a + b > > addition = absolutize(_addition) > > > > Then you can unit test both _addition() and addition(). > > *shudders* > Ew ew ew ew. Care to provide some technical discourse here? Aside from losing the neat and evocative @decorator syntax, the above is simple and overt. > I would much rather do something like this: > > def undecorate(f): > """Return the undecorated inner function from function f.""" > return f.func_closure[0].cell_contents Whereas this feels like black magic. Is this portable to any decorated function? If so, I'd have hoped it was in the stdlib. If not: black magic. > And in use: > > py> f(100) > 201 > py> undecorate(f)(100) > 200 All lovely, provided you can convince me that undecorate() is robust. (And if you can, I'll certainly be filing it away in my funcutils module for later use.) Cheers, -- Cameron Simpson DRM doesn't inconvenience pirates ¿ indeed, over time it trains law-abiding users to become pirates out of sheer frustration. - Charles Stross