471,318 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,318 software developers and data experts.

EasyMock for python ?


Hi,

Does anybody know where to find a library like EasyMock for python ? I
searched quickly but could not find anything.

I found python-mocks on sourceforge but form quickly reading the docs,
it is not an EasyMock style mock. Actually, according to
http://martinfowler.com/articles/mocksArentStubs.html I don't think it
is even a mock library. More a stub.

Philippe

Oct 10 '07 #1
8 1519
On 10/10/07, BlueBird <ph**@freehackers.orgwrote:
Does anybody know where to find a library like EasyMock for python ? I
searched quickly but could not find anything.

I found python-mocks on sourceforge but form quickly reading the docs,
it is not an EasyMock style mock. Actually, according to
http://martinfowler.com/articles/mocksArentStubs.html I don't think it
is even a mock library. More a stub.
python-mock is more jMock than EasyMock in style, it's true, and the
fact that you define expectations *after* the test invocation rather
than before does feel a bit odd. But it does indeed check against the
defined expectations, so that makes it a mock library in my book.

A record-playback EasyMock style mock library would be nice, it's true...

--
Cheers,
Simon B.
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
Oct 11 '07 #2
I had to get the hang of jMock-style testing through the usage of the
pmock library. But it seems to work out pretty well.

See some of my test cases at
http://springpython.python-hosting.c...reTestCases.py.

That should provide a hearty sample of uses for this mock set. It
easily let me throw away the real database and conclude unit testing
much faster.

Oct 11 '07 #3
BlueBird <ph**@freehackers.orgwrites:
Does anybody know where to find a library like EasyMock for python ?
I've had good results with Ian Bicking's 'minimock.py'
<URL:http://blog.ianbicking.org/minimock.html>. It uses the existing
'doctest' functionality for its output, and a minimock.Mock will mock
*everything* (using further Mock instances for attributes and methods)
unless explicitly told otherwise.

This means that the Mock object automatically supports any number of
attributes and methods by any reasonable names; the only setup needed
beyond creating the instance is to seed it with anything you *don't*
want returned as a Mock.

--
\ "Laugh and the world laughs with you; snore and you sleep |
`\ alone." -- Anonymous |
_o__) |
Ben Finney
Oct 12 '07 #4
On 10/12/07, Ben Finney <bi****************@benfinney.id.auwrote:
BlueBird <ph**@freehackers.orgwrites:
This means that the Mock object automatically supports any number of
attributes and methods by any reasonable names; the only setup needed
beyond creating the instance is to seed it with anything you *don't*
want returned as a Mock.
Now *that* is what the OP was talking about - that's not a Mock,
that's a Stub. See <http://tinyurl.com/26hfjd>.
..

--
Cheers,
Simon B.
si***@brunningonline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
Oct 12 '07 #5
(Please don't send me personal copies of messages that are sent to the
forum; I read via the newsgroup, and it's annoying to also get replies
in email when I didn't send an email message.)

"Simon Brunning" <si***@brunningonline.netwrites:
On 10/12/07, Ben Finney <bi****************@benfinney.id.auwrote:
This means that the Mock object automatically supports any number
of attributes and methods by any reasonable names; the only setup
needed beyond creating the instance is to seed it with anything
you *don't* want returned as a Mock.

Now *that* is what the OP was talking about - that's not a Mock,
that's a Stub. See <http://tinyurl.com/26hfjd>.
Because the minimock.Mock instance is instrumented to emit a message
any time one of its attributes is called, that output becomes the
playback — which then, using doctest, can be compared against the
*expected* sequence of method calls.

That seems like it's a Mock to me: intended to assert that a specific
sequence of method calls with specific arguments was made on the mock
instance.

--
\ "I love to go down to the schoolyard and watch all the little |
`\ children jump up and down and run around yelling and screaming. |
_o__) They don't know I'm only using blanks." -- Emo Philips |
Ben Finney
Oct 12 '07 #6
On Oct 11, 4:26 pm, "Simon Brunning" <si...@brunningonline.netwrote:
On 10/10/07, BlueBird <p...@freehackers.orgwrote:
Does anybody know where to find a library like EasyMock for python ? I
searched quickly but could not find anything.
I found python-mocks on sourceforge but form quickly reading the docs,
it is not an EasyMock style mock. Actually, according to
http://martinfowler.com/articles/mocksArentStubs.htmlI don't think it
is even a mock library. More a stub.

python-mock is more jMock than EasyMock in style, it's true, and the
fact that you define expectations *after* the test invocation rather
than before does feel a bit odd. But it does indeed check against the
defined expectations, so that makes it a mock library in my book.

A record-playback EasyMock style mock library would be nice, it's true...
It should not be that hard to do, given that python-mocks already has
the notion of recording and expectation verifiation.

I may give it a stab.

Philippe
Oct 12 '07 #7
On 10/12/07, Ben Finney <bi****************@benfinney.id.auwrote:
>
I've had good results with Ian Bicking's 'minimock.py'
<URL:http://blog.ianbicking.org/minimock.html>. It uses the existing
'doctest' functionality for its output, and a minimock.Mock will mock
*everything* (using further Mock instances for attributes and methods)
unless explicitly told otherwise.
One problem I can see with the current implementation of using
minimock + doctest is that if you have more than one mock object
needed for a particular function call in a test, the output from each
mock will be interleaved; there should really be some way to use
minimock so that you can output a call log from each mock individually
after calling the function to test.

Of course, that might need to be a feature in
still_small_but_slightly_large_than_minimock.py ;-)

Andrew
Oct 15 '07 #8
Ben Finney <bi****************@benfinney.id.auwrites:
I've had good results with Ian Bicking's 'minimock.py'
<URL:http://blog.ianbicking.org/minimock.html>. It uses the existing
'doctest' functionality for its output [...]
That doesn't make much sense, and it's wrong; it uses 'print' for its
output. That should read "It uses the existing 'doctest' functionality
for checking output [...]"

--
\ "If you're not part of the solution, you're part of the |
`\ precipitate." -- Steven Wright |
_o__) |
Ben Finney
Oct 15 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Emile van Sebille | last post: by
reply views Thread by Emile van Sebille | last post: by
reply views Thread by Emile van Sebille | last post: by
reply views Thread by Emile van Sebille | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.