Questions tagged [mox]

Mox is a mock object framework for Python.

Mox is based on EasyMock, a Java mock object framework.

Mox will make mock objects for you, so you don't have to create your own! It mocks the public/protected interfaces of Python objects. You set up your mock objects expected behavior using a domain specific language (DSL), which makes it easy to use, understand, and refactor!

38 questions
0
votes
0 answers

Python mox urllib2's Request and urllopen function

I was trying to mox req = urllib2.Request( rest_url, json.dumps(data), {'Content-Type': 'application/json'}) req = urllib2.urlopen(req) chunk_size = 1024 * 1024 while True: chunk = req.read(chunk_size) if not chunk: break …
sarveshgupta
  • 31
  • 1
  • 3
0
votes
1 answer

python mox assert that a module function raises an exception

How do I make sure that a certain function raises an exception on certain inputs using mox? I could do it with try catch but it doesn't seem like too moxxy Lets say the function is the following: def merge_paths(a, b): if a == "": raise…
iggy
  • 1,613
  • 1
  • 18
  • 35
0
votes
1 answer

Python Mox: How to fake os.path.exists() for certain paths only?

How can I mock exists() for certain paths only while making it do the real thing for any other path? For example the class under test will call exists() and would fail on the paths that were supplied to it, because they do not exist on the system…
try-catch-finally
  • 7,436
  • 6
  • 46
  • 67
0
votes
1 answer

When using python mox mock objects is there any way to avoid all of them being equal (as in __eq__)?

I'm experiencing some problems derived from the fact than several all mox Mock object of a given class seem to be equal in the ==,__eq__ sense although they are different objects (at least mock1 is mock2 returns False). is there any way to prevent…
RubenLaguna
  • 21,435
  • 13
  • 113
  • 151
0
votes
0 answers

Is there a way to mock "import .." in python unittest?

I know in python by using mox, we can emulate the behaviour of a class propery or method. But when we new a instance or a target class, it does many things in its "import ..." class. My question is how to simulate the "import .." class behavour in…
JerryCai
  • 1,663
  • 4
  • 21
  • 36
0
votes
1 answer

mocking a variable using mox

I want to test this method, however I would need to mock the variable dirContent def imageFilePaths(paths): imagesWithPath = [] for _path in paths: try: dirContent = os.listdir(_path) except OSError: …
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
0
votes
0 answers

Why do I get ValueError("There must be at least one expected method") from mox, when I know that the function I've mocked out is getting called?

I'm using mox to stub out an email-sending function in my code. I want to verify that the function is called N times, with a certain set of params each time. Mox is raising ValueError("There must be at least one expected method") as if the function…
AndrewS
  • 1,395
  • 11
  • 23
0
votes
2 answers

Why does a failing test with mox fail other tests as well?

My issue is quite simple: I'm having a bunch of unit tests using pymox. When I add a new test that fails, most of the time a whole lot of others fail as well. How can I prevent that from happening? For example, I have a simple script for which I…
Radu Gheorghe
  • 564
  • 4
  • 8
1 2
3