Repository navigation
Expand file tree
/
Copy pathtest_import_star.py
More file actions
78 lines (60 loc) · 2.37 KB
/
Copy pathtest_import_star.py
File metadata and controls
78 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
This tests whether
from future.builtins import *
works as expected:
- This should NOT introduce namespace pollution on Py3.
- On Python 2, this should not introduce any symbols that aren't in
__builtin__.
"""
from __future__ import absolute_import, print_function, unicode_literals
import copy
from future import utils
from future.tests.base import unittest, skip26
original_locals = set(copy.copy(locals()))
original_globals = set(copy.copy(globals()))
new_names = set(['original_locals', 'original_globals', 'new_names'])
from future.builtins import *
new_locals = set(copy.copy(locals())) - new_names - original_locals
new_globals = set(copy.copy(globals())) - new_names - original_globals - \
set(['new_locals'])
class TestImportStar(unittest.TestCase):
def test_namespace_pollution_locals(self):
if utils.PY3:
self.assertEqual(len(new_locals), 0,
'namespace pollution: {0}'.format(new_locals))
else:
pass # maybe check that no new symbols are introduced
def test_namespace_pollution_globals(self):
if utils.PY3:
self.assertEqual(len(new_globals), 0,
'namespace pollution: {0}'.format(new_globals))
else:
pass # maybe check that no new symbols are introduced
def test_iterators(self):
self.assertNotEqual(type(range(10)), list)
def test_super(self):
pass
@skip26
def test_python3_stdlib_imports(self):
"""
The import hooks should be tightened up so that this test never fails
"""
# These should fail on Py2
try:
import queue
import socketserver
except ImportError:
if utils.PY3:
self.fail('Py3 modules failed to load')
else:
if utils.PY2:
self.fail('Py3 standard library modules should not import on Py2 without explicitly enabling them')
self.assertTrue(True)
def test_str(self):
self.assertIsNot(str, bytes) # Py2: assertIsNot only in 2.7
self.assertEqual(str('blah'), u'blah') # Py3.3 and Py2 only
def test_python_2_unicode_compatible_decorator(self):
# This should not be in the namespace
assert 'python_2_unicode_compatible' not in locals()
if __name__ == '__main__':
unittest.main()