mox

How do I mock a class property with mox?

I have a class: class MyClass(object): @property def myproperty(self): return 'hello' Using mox and py.test, how do I mock out myproperty? I've tried: mock.StubOutWithMock(myclass, 'myproperty') myclass.myproperty = 'goodbye' and mock.StubOutWithMock(myclass, 'myproperty') myclass.myproperty.AndReturns('goodbye') ...

Mocking urllib2.urlopen and lxml.etree.parse using pymox

I'm trying to test some python code that uses urllib2 and lxml. I've seen several blog posts and stack overflow posts where people want to test exceptions being thrown, with urllib2. I haven't seen examples testing successful calls. Am I going down the correct path? Does anyone have a suggestion for getting this to work? Here is what...

How do I use Mox to mock a module function and allow it to be called in almost any way.

I have a function A that call another function B several times. I want to mock B in such a way that any number of calls that have the correct number of arguments, regardless of value, will return a fixed vale and be treated as correct. If or how many times the the function is called is not a part of the spec. ...

Testing call order across mock objects with Mox and Python

Hi, I'm testing a function that obtains a skeleton object from one helper object, modifies it using a second helper, and passes the modified object back to the first helper. Something along the lines of: class ReadModifyUpdate(object): def __init__(self, store, modifier): self._store = store self._modifier = modifie...