Commit c8ddd6b0 authored by Denis Bilenko's avatar Denis Bilenko

Merge pull request #353 from fantix/fix_exec

Fixed exec, refs #38.
parents f250fa9f 735026d4
...@@ -261,12 +261,12 @@ class FileObjectThread(object): ...@@ -261,12 +261,12 @@ class FileObjectThread(object):
for method in ['read', 'readinto', 'readline', 'readlines', 'write', 'writelines', 'xreadlines']: for method in ['read', 'readinto', 'readline', 'readlines', 'write', 'writelines', 'xreadlines']:
exec '''def %s(self, *args, **kwargs): exec('''def %s(self, *args, **kwargs):
fobj = self._fobj fobj = self._fobj
if fobj is None: if fobj is None:
raise FileObjectClosed raise FileObjectClosed
return self._apply(fobj.%s, args, kwargs) return self._apply(fobj.%s, args, kwargs)
''' % (method, method) ''' % (method, method))
def __iter__(self): def __iter__(self):
return self return self
......
...@@ -30,4 +30,4 @@ test_name = os.path.splitext(test_filename)[0] ...@@ -30,4 +30,4 @@ test_name = os.path.splitext(test_filename)[0]
module_source = open(test_filename).read() module_source = open(test_filename).read()
module_source = disable_tests_in_source(module_source, test_name) module_source = disable_tests_in_source(module_source, test_name)
module_code = compile(module_source, test_filename, 'exec') module_code = compile(module_source, test_filename, 'exec')
exec module_code in globals() exec(module_code, globals())
"""Check __all__, __implements__, __extensions__, __imports__ of the modules""" """Check __all__, __implements__, __extensions__, __imports__ of the modules"""
from __future__ import print_function from __future__ import print_function
import six
import sys import sys
import unittest import unittest
import types import types
...@@ -43,7 +44,7 @@ class Test(unittest.TestCase): ...@@ -43,7 +44,7 @@ class Test(unittest.TestCase):
assert self.modname in NO_ALL assert self.modname in NO_ALL
return return
names = {} names = {}
exec("from %s import *" % self.modname) in names six.exec_("from %s import *" % self.modname, names)
names.pop('__builtins__', None) names.pop('__builtins__', None)
self.assertEqual(sorted(names), sorted(self.module.__all__)) self.assertEqual(sorted(names), sorted(self.module.__all__))
...@@ -140,7 +141,7 @@ are missing from %r: ...@@ -140,7 +141,7 @@ are missing from %r:
def _test(self, modname): def _test(self, modname):
self.modname = modname self.modname = modname
exec "import %s" % modname in {} six.exec_("import %s" % modname, {})
self.module = sys.modules[modname] self.module = sys.modules[modname]
self.check_all() self.check_all()
......
...@@ -24,7 +24,7 @@ if not hasattr(threading._Condition, 'notify_all'): ...@@ -24,7 +24,7 @@ if not hasattr(threading._Condition, 'notify_all'):
threading._Condition.notify_all = threading._Condition.notifyAll threading._Condition.notify_all = threading._Condition.notifyAll
''' '''
exec setup_ exec(setup_)
setup_3 = '\n'.join(' %s' % line for line in setup_.split('\n')) setup_3 = '\n'.join(' %s' % line for line in setup_.split('\n'))
setup_4 = '\n'.join(' %s' % line for line in setup_.split('\n')) setup_4 = '\n'.join(' %s' % line for line in setup_.split('\n'))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment