Open GoogleCodeExporter opened 9 years ago
Nice. Thanks for this.
Original comment by fuzzyman
on 4 Apr 2012 at 10:13
Original comment by fuzzyman
on 4 Apr 2012 at 1:45
I'd like to include this in the examples.txt page (which is already meant to be
more advanced examples). It would also be great if it was possible to rewrite
the example as a doctest (so the example can be tested). Hopefully I'll have a
chance to get to this before the 1.0 release if you don't have time.
Original comment by fuzzyman
on 13 Apr 2012 at 4:03
Ok, let me try do that (I guess I have time for that).
Original comment by k...@k-bx.com
on 14 Apr 2012 at 9:08
Original comment by fuzzyman
on 14 Apr 2012 at 9:58
Ok, so I actually stopped at point when I start to find things ugly. I mean,
the point of prefixed_patch() is to show people how to save time from importing
long names multiple times. But to import long module name -- you actually need
to have that module (to doctest @ppatch). So I ended up at ugly code that looks
something like this: http://paste.ubuntu.com/931756/
I think it's not the right way how to do things (insert that piece of code into
hidden doctest-strings just to make test look something like "with
imaginary_module('foo.bar.baz'): ... (actual test with
prefixed_patch('foo.bar') ...".
Original comment by k...@k-bx.com
on 15 Apr 2012 at 10:02
Several of the existing doctests already have code setup (and some have
teardown) at the start of the document. And faking modules is easy with
sys.path:
>>> from mock import Mock
>>> import sys
>>> foo = Mock()
>>> sys.modules['foo'] = foo
>>> sys.modules['foo.bar'] = foo.bar
>>> sys.modules['foo.bar.baz'] = foo.bar.baz
>>> from foo.bar import baz
>>> baz
<Mock name='mock.bar.baz' id='4299821328'>
>>> baz is foo.bar.baz
True
Original comment by fuzzyman
on 15 Apr 2012 at 11:00
I ended up with piece like this http://paste.ubuntu.com/931862/
I don't see why there's need in doctest :) maybe example could be different to
show by doctest that ppatch really works, but then that example will show
correctness of ppatch instead of example of real-world unit-test with ppatch.
Original comment by k...@k-bx.com
on 15 Apr 2012 at 11:44
(btw, thanks for mocking modules idea, also shame on me, it was actually at
examples.txt :-D
Original comment by k...@k-bx.com
on 15 Apr 2012 at 11:46
Original issue reported on code.google.com by
k...@k-bx.com
on 4 Apr 2012 at 10:10