commit c40ea0fb2f2188d540655cfc4c6975bffc9585b2 Author: Damian Johnson atagar@torproject.org Date: Mon Mar 18 16:19:39 2013 -0700
Fixing open() mock for python 3
Our unit tests were broken under python 3 due to needing a slightly different mock for the open() function.
====================================================================== ERROR: test_mirror_mirror_on_the_wall_2 ---------------------------------------------------------------------- Traceback: File "/home/atagar/Desktop/stem/test/data/python3/test/unit/tutorial.py", line 107, in test_mirror_mirror_on_the_wall_2 tutorial_example() File "/home/atagar/Desktop/stem/test/data/python3/test/unit/tutorial.py", line 95, in tutorial_example for desc in parse_file(open("/home/atagar/.tor/cached-consensus")): FileNotFoundError: [Errno 2] No such file or directory: '/home/atagar/.tor/cached-consensus' --- test/unit/tutorial.py | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py index 0aec3a3..d557fa0 100644 --- a/test/unit/tutorial.py +++ b/test/unit/tutorial.py @@ -11,6 +11,7 @@ import unittest from stem.control import Controller from stem.descriptor.reader import DescriptorReader from stem.descriptor.server_descriptor import RelayDescriptor +from stem.prereq import is_python_3 from test import mocking
MIRROR_MIRROR_OUTPUT = """\ @@ -102,7 +103,12 @@ class TestTutorial(unittest.TestCase):
mocking.support_with(test_file) test_file.name = "/home/atagar/.tor/cached-consensus" - mocking.mock(open, mocking.return_value(test_file)) + + if is_python_3(): + import builtins + mocking.mock(open, mocking.return_value(test_file), target_module = builtins) + else: + mocking.mock(open, mocking.return_value(test_file))
tutorial_example() self.assertEqual("found relay caerSidi (A7569A83B5706AB1B1A9CB52EFF7D2D32E4553EB)\n", self.stdout.getvalue())
tor-commits@lists.torproject.org