Re: Skipping decorators in unit tests

2013-10-11 Thread Cameron Simpson
On 11Oct2013 02:37, Gilles Lenfant wrote: > * Adding an "__original__" attribute to the wrapper func in the decorators of > my own Just one remark: Call this __original or _original (or even original). The __x__ names are reserved for python operations (like __add__, supporting "+"). Cheers, -

Re: Skipping decorators in unit tests

2013-10-11 Thread Ned Batchelder
On 10/10/13 10:22 PM, Cameron Simpson wrote: On 10Oct2013 19:44, Ned Batchelder wrote: On 10/10/13 6:12 PM, 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): retu

Re: Skipping decorators in unit tests

2013-10-11 Thread Ethan Furman
On 10/10/2013 08:13 PM, Cameron Simpson wrote: 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

Re: Skipping decorators in unit tests

2013-10-11 Thread Ethan Furman
On 10/10/2013 08:01 PM, Roy Smith wrote: On 10Oct2013 19:44, Ned Batchelder wrote: I have to admit I'm having a hard time understanding why you'd need to test the undecorated functions. After all, the undecorated functions aren't available to anyone. All that matters is how they behave with t

Re: Skipping decorators in unit tests

2013-10-11 Thread Gilles Lenfant
Cameron, Steven, Ben, Ned, Terry, Roy. Many thanks for this interesting discussion. I ended up... mixing some solutions provided by your hints : * Adding an "__original__" attribute to the wrapper func in the decorators of my own * Playing with "func_closure" to test functions/methods provided

Re: Skipping decorators in unit tests

2013-10-11 Thread Terry Reedy
On 10/11/2013 4:17 AM, Terry Reedy wrote: On 10/10/2013 11:13 PM, Cameron Simpson wrote: On 11Oct2013 02:55, Steven D'Aprano wrote: def undecorate(f): """Return the undecorated inner function from function f.""" return f.func_closure[0].cell_contents Whereas this feels like black

Re: Skipping decorators in unit tests

2013-10-11 Thread Terry Reedy
On 10/11/2013 4:17 AM, Terry Reedy wrote: On 10/10/2013 11:13 PM, Cameron Simpson wrote: On 11Oct2013 02:55, Steven D'Aprano wrote: def undecorate(f): """Return the undecorated inner function from function f.""" return f.func_closure[0].cell_contents Whereas this feels like black

Re: Skipping decorators in unit tests

2013-10-11 Thread Terry Reedy
On 10/11/2013 12:36 AM, Steven D'Aprano wrote: I also like Terry Reedy's suggestion of having the decorator automatically add the unwrapped function to the wrapped function as an attribute: def decorate(func): @functools.wraps(func) def inner(arg): blah blah inner._unwra

Re: Skipping decorators in unit tests

2013-10-11 Thread Terry Reedy
On 10/10/2013 11:13 PM, Cameron Simpson wrote: On 11Oct2013 02:55, Steven D'Aprano wrote: 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

Re: Skipping decorators in unit tests

2013-10-10 Thread Cameron Simpson
On 11Oct2013 05:51, Steven D'Aprano wrote: > On Fri, 11 Oct 2013 15:36:29 +1100, Cameron Simpson wrote: > > But is it reliable? Will it work on any decorated function? > > *Any* decorated function? No, of course not, since decorators can do > anything they like: [... examples ...] That was wha

Re: Skipping decorators in unit tests

2013-10-10 Thread Steven D'Aprano
On Fri, 11 Oct 2013 15:36:29 +1100, Cameron Simpson wrote: > But is it reliable? Will it work on any decorated function? *Any* decorated function? No, of course not, since decorators can do anything they like: def decorate(func): return lambda *args: "Surprise!" @decorate def something_use

Re: Skipping decorators in unit tests

2013-10-10 Thread Steven D'Aprano
On Fri, 11 Oct 2013 14:13:19 +1100, Cameron Simpson wrote: > 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): >> >

Re: Skipping decorators in unit tests

2013-10-10 Thread Cameron Simpson
On 11Oct2013 14:42, Ben Finney wrote: > Cameron Simpson writes: > > On 11Oct2013 02:55, Steven D'Aprano > > wrote: > > > def undecorate(f): > > > """Return the undecorated inner function from function f.""" > > > return f.func_closure[0].cell_contents > > > > Whereas this feels like bla

Re: Skipping decorators in unit tests

2013-10-10 Thread Ben Finney
Cameron Simpson writes: > On 11Oct2013 02:55, Steven D'Aprano > wrote: > > 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

Re: Skipping decorators in unit tests

2013-10-10 Thread Cameron Simpson
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): > >

Re: Skipping decorators in unit tests

2013-10-10 Thread Roy Smith
On 10Oct2013 19:44, Ned Batchelder wrote: > > I have to admit I'm having a hard time understanding why you'd need > > to test the undecorated functions. After all, the undecorated > > functions aren't available to anyone. All that matters is how they > > behave with the decorators. In article ,

Re: Skipping decorators in unit tests

2013-10-10 Thread Steven D'Aprano
On Fri, 11 Oct 2013 09:12:38 +1100, Cameron Simpson wrote: > On 10Oct2013 07:00, Gilles Lenfant wrote: >> (explaining the title) : my app has functions and methods (and maybe >> classes in the future) that are decorated by decorators provided by the >> standard library or 3rd party packages. >>

Re: Skipping decorators in unit tests

2013-10-10 Thread Cameron Simpson
On 10Oct2013 19:44, Ned Batchelder wrote: > On 10/10/13 6:12 PM, 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 > > > >

Re: Skipping decorators in unit tests

2013-10-10 Thread Terry Reedy
On 10/10/2013 10:00 AM, Gilles Lenfant wrote: To add to the other two responses so far... (explaining the title) : my app has functions and methods (and maybe classes in the future) that are decorated by decorators provided by the standard library or 3rd party packages. But I need to test "u

Re: Skipping decorators in unit tests

2013-10-10 Thread Ned Batchelder
On 10/10/13 6:12 PM, Cameron Simpson wrote: On 10Oct2013 07:00, Gilles Lenfant wrote: (explaining the title) : my app has functions and methods (and maybe classes in the future) that are decorated by decorators provided by the standard library or 3rd party packages. But I need to test "undecor

Re: Skipping decorators in unit tests

2013-10-10 Thread Cameron Simpson
On 10Oct2013 07:00, Gilles Lenfant wrote: > (explaining the title) : my app has functions and methods (and > maybe classes in the future) that are decorated by decorators > provided by the standard library or 3rd party packages. > > But I need to test "undecorated" functions and methods in my uni

Skipping decorators in unit tests

2013-10-10 Thread Gilles Lenfant
Hi, (explaining the title) : my app has functions and methods (and maybe classes in the future) that are decorated by decorators provided by the standard library or 3rd party packages. But I need to test "undecorated" functions and methods in my unit tests, preferably without adding "special s