473,244 Members | 1,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,244 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 1584
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Emile van Sebille | last post by:
QOTW: "If we get 2.3.3c1 out in early December, we could release 2.3.3 final before the end of the year, and start 2004 with a 100% bug-free codebase <wink>." -- Tim Peters "cjOr proWe vbCould...
0
by: Emile van Sebille | last post by:
QOTW: "Have you ever used the copy module? I am *not* a beginner, and have used it *once* (and I can't remember what for, either)." -- Michael Hudson "It will likely take a little practice...
0
by: Emile van Sebille | last post by:
QOTW (in the OS agnostic category): "There is a (very popular) Python package out there which exposes the win32 api. I'm not sure what it's called. (win32api? pythonwin? win32all?)" -- Francis...
0
by: Emile van Sebille | last post by:
QOTW (advanced interfaces track): "I'm firmly in favour of any language that can DWIMNWIS." -- Tim Delaney QOTW (MS roadkill track): "Underestimate MS at your own risk. It is one thing to not...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.