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
2
votes
2 answers

Expected methods never called when running python mox test

I'm trying to write a mox test that reads a spreadsheet (4 columns), gets the feed and writes specific columns (2 columns) to a CSV file. I'm trying to get past the first step which is get the list feed, my code is as follows: class…
jwesonga
  • 4,249
  • 16
  • 56
  • 83
1
vote
1 answer

Python unit test how to use Mox to mock the gzip with statement

In Python, how do I mock an object created in a with statement using mox unit test library Code class MyCode: def generate_gzip_file(self): with gzip.GzipFile('file_name.txt.gz','wb') as f: f.write('data') Unit Test class…
venky
  • 125
  • 1
  • 2
  • 9
1
vote
1 answer

Mocking consecutive function calls in Elixir with Mock or Mox

I'm trying to mock function multiple calls, so it returns every time specific different value. I am not that familiar with Elixir and functional concepts. defmodule Roller do def roll do 1..10 |>Enum.random() end end Roller returns…
Borys Zielonka
  • 287
  • 2
  • 6
  • 20
1
vote
1 answer

Elixir Mox library testing Phoenix code - with no Mox expectations in some test files

TL;DR Unrelated tests fail because "no expectation defined" when using Mox library, and stub_with/2 doesn't seem to be of any help Details: There is the Recaptcha library https://github.com/samueljseay/recaptcha which helps me in verifying recaptcha…
silverdr
  • 1,978
  • 2
  • 22
  • 27
1
vote
0 answers

python mocking open method using mox

When I try to mock open method, I am facing issue. Please find the sample code : import glob import re #from __builtin__ import open class DiskManager: def __init__(self): print("Called init method") def __get_xyz_from_serial(self, serial): for…
Jeet
  • 761
  • 3
  • 10
  • 27
1
vote
1 answer

How to mock HTTPoison with Mox?

Background I have library that uses HTTPoison for some functionality I need to test. To achieve this I am using Mox, which I believe is the universal mocking library for Elixir (even though there are others this one has the seal of approval of José…
Flame_Phoenix
  • 16,489
  • 37
  • 131
  • 266
1
vote
0 answers

mocking a function called multiple times using pymox

I have a function in the code that is being called twice. get_user_settings once it is getting called in the function I am testing and second time some different module has a function that calls it again. I have mocked it using pymox like this: mox…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
1
vote
0 answers

Mox error being caught by incode try..except

Consider the following: Class: class Something(object): def should_not_be_called(self): pass def should_be_called(self): pass def do_stuff(self): self.should_be_called() try: …
pseudoDust
  • 1,336
  • 1
  • 10
  • 18
1
vote
2 answers

Testing call order across mock objects with Mox and Python

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…
1
vote
1 answer

what is difference while doing monkeyPatch and StubOutwithMock?

I came across this while doing unittest, I am curious to know what is the difference between the below two ? self.monkeyPatch(module, 'myFunc', lambda n: someObject) and mox.StubOutWithMock(module,…
Ciasto piekarz
  • 7,853
  • 18
  • 101
  • 197
1
vote
2 answers

How do I use Python Mox to check if a method is called with the equivalent of a string?

I want to check if a function is being called with a string - however it seems that it makes a difference if that string is created using '%s' to insert a substring. The test is failing with this error: UnexpectedMethodCallError: Unexpected method…
1
vote
1 answer

how mock only one method called within the object you are testing

I want to test a method but mock out other methods that it calls. I created this simple example that should illustrate the concept: class myClass(): def one_method(self): print "hey" def two_deep(self): self.one_method() …
Pswiss87
  • 725
  • 1
  • 6
  • 16
1
vote
1 answer

How to unit test this code with pymox?

So I have installed pymox and I would like to test this method: class HttpStorage(): def download(self, input, output): try: file_to_download = urllib2.urlopen(input) except URLError: raise…
Richard Knop
  • 81,041
  • 149
  • 392
  • 552
0
votes
0 answers

Elixir mox - mocking service used by genserver

I'm using Mox to mock a service Pokemon.Api (mock is called Pokemon.ApiMock) and everythings works fine. I have also created a custome ExUnit.CaseTemplate(Pokemon.Case) and am stubbing the mock implementation with the real implementation. So if I…
WilliamG
  • 127
  • 2
  • 8
0
votes
2 answers

Mocking Django query using Mox

I'm trying to mock a django filter query using Mox. I am following the instructions on Mox website, however, since my django query is a chained method, it complains that the AndReturn() method doesn't exist. Here is my method: def…
mohi666
  • 6,842
  • 9
  • 45
  • 51