[tor-commits] [stem/master] Accounting for __builtin__ renaming
atagar at torproject.org
atagar at torproject.org
Sat Feb 2 18:20:49 UTC 2013
commit 62086346044c9eab1ce68d830669559773ef22b9
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Jan 21 08:57:02 2013 -0800
Accounting for __builtin__ renaming
Python 3.x renames __builtin__ to builtins...
======================================================================
ERROR: test_parse_circ_path
----------------------------------------------------------------------
Traceback:
File "/home/atagar/Desktop/stem/test/data/python3/test/unit/control/controller.py", line 24, in setUp
mocking.revert_mocking()
File "/home/atagar/Desktop/stem/test/data/python3/test/mocking.py", line 404, in revert_mocking
if module == __builtin__:
NameError: global name '__builtin__' is not defined
---
test/mocking.py | 12 +++++++++++-
test/settings.cfg | 1 +
2 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/test/mocking.py b/test/mocking.py
index 82b9790..192d59c 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -58,6 +58,7 @@ import stem.descriptor.extrainfo_descriptor
import stem.descriptor.networkstatus
import stem.descriptor.router_status_entry
import stem.descriptor.server_descriptor
+import stem.prereq
import stem.response
import stem.socket
@@ -401,7 +402,16 @@ def revert_mocking():
for mock_id in mock_ids:
module, function, impl = MOCK_STATE[mock_id]
- if module == __builtin__:
+ # Python 3.x renamed __builtin__ to builtins. Ideally we'd account for
+ # this with a simple 'import __builtin__ as builtins' but that somehow
+ # makes the following check fail. Haven't a clue why.
+
+ if stem.prereq.is_python_3():
+ builtin_module = builtins
+ else:
+ builtin_module = __builtin__
+
+ if module == builtin_module:
setattr(__builtin__, function, impl)
else:
setattr(module, function, impl)
diff --git a/test/settings.cfg b/test/settings.cfg
index ebaf6c0..66475ee 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -157,5 +157,6 @@ pyflakes.ignore stem/prereq.py => 'RSA' imported but unused
pyflakes.ignore stem/prereq.py => 'asn1' imported but unused
pyflakes.ignore stem/prereq.py => 'long_to_bytes' imported but unused
pyflakes.ignore stem/descriptor/__init__.py => redefinition of unused 'OrderedDict' from line 32
+pyflakes.ignore test/mocking.py => undefined name 'builtins'
pyflakes.ignore test/unit/response/events.py => 'from stem import *' used; unable to detect undefined names
More information about the tor-commits
mailing list