[tor-commits] [stem/master] Python3 mock doesn't have assert_called_once
atagar at torproject.org
atagar at torproject.org
Tue Aug 14 19:57:06 UTC 2018
commit e75cf259a8385b19c2b9b7df6aaf3f3e005e5478
Author: Damian Johnson <atagar at torproject.org>
Date: Tue Aug 14 12:54:55 2018 -0700
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
---
test/unit/control/controller.py | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
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)
More information about the tor-commits
mailing list