diff options
| author | Damian Johnson <atagar@torproject.org> | 2018-08-14 12:54:55 -0700 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2018-08-14 12:54:55 -0700 |
| commit | e75cf259a8385b19c2b9b7df6aaf3f3e005e5478 (patch) | |
| tree | 769b3699727378a39ddafed20661cef31f479a73 | |
| parent | c9cc0f558cfe086d8e72e4fd9bf31c98ad535041 (diff) | |
Python3 mock doesn't have assert_called_once
Oops. With python 2.x we use pypi's mock module but with python 3.x it's built
in (under unittest.mock). I thought Python bundled an exact copy of the
upstream module but seems it doesn't include the assert_called_once method...
======================================================================
ERROR: test_event_listing_with_malformed_event
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3.5/unittest/mock.py", line 1157, in patched
return func(*args, **keywargs)
File "/home/atagar/Desktop/stem/test/unit/control/controller.py", line 688, in test_event_listing_with_malformed_event
self.malformed_listener.assert_called_once()
File "/usr/lib/python3.5/unittest/mock.py", line 583, in __getattr__
raise AttributeError(name)
AttributeError: assert_called_once
| -rw-r--r-- | test/unit/control/controller.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py index eba612fd..c7fd0f96 100644 --- a/test/unit/control/controller.py +++ b/test/unit/control/controller.py @@ -10,6 +10,7 @@ import unittest import stem.descriptor.router_status_entry import stem.response +import stem.response.events import stem.socket import stem.util.system import stem.version @@ -681,11 +682,18 @@ class TestControl(unittest.TestCase): is_alive_mock.return_value = True self.controller._launch_threads() + # When stem.response.convert() encounters malformed content we still recast + # the message. + + expected_bad_event = ControlMessage.from_str(BAD_EVENT.raw_content()) + setattr(expected_bad_event, 'arrived_at', TEST_TIMESTAMP) + expected_bad_event.__class__ = stem.response.events.BandwidthEvent + try: self._emit_event(BAD_EVENT) self.circ_listener.assert_not_called() self.bw_listener.assert_not_called() - self.malformed_listener.assert_called_once() + self.malformed_listener.assert_called_once_with(casted_bad_event) self._emit_event(BW_EVENT) self.bw_listener.assert_called_once_with(BW_EVENT) |
