[tor-dev] stem mock_method usage

Sean Robinson seankrobinson at gmail.com
Fri Dec 7 17:01:40 UTC 2012


Damian,

I am attempting to write a test using test.mocking.mock_method, but I do
not understand how to use it correctly.  Could you give me pointers on the
following smallest (non-)working test case.

import stem
from stem.control import Controller
import test.mocking as mocking

socket = stem.socket.ControlSocket()
controller = Controller(socket)

mocking.mock_method(Controller, 'get_version',
mocking.return_value(stem.version.Version('0.1.0.14')))

controller.get_version()

The above code fails with:

Traceback (most recent call last):
  File "mock_method-test.py", line 8, in <module>
    mocking.mock_method(Controller, 'get_version',
mocking.return_value(stem.version.Version('0.1.0.14')))
  File "stem.dev/test/mocking.py", line 317, in mock_method
    target_class.__dict__[method_name] = mock_wrapper
TypeError: 'dictproxy' object does not support item assignment


-- 
Sean Robinson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-dev/attachments/20121207/399a8deb/attachment.html>


More information about the tor-dev mailing list