blob: 14a7487d0816db1793c05f796ff6cfbe12fe08d9 (
plain)
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
79
80
81
|
import sys
import textwrap
from packaging.tests import unittest, support
from packaging.compat import Mixin2to3
class Mixin2to3TestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
def test_convert_code_only(self):
# used to check if code gets converted properly.
code = "print 'test'"
with self.mktempfile() as fp:
fp.write(code)
mixin2to3 = Mixin2to3()
mixin2to3._run_2to3([fp.name])
expected = "print('test')"
with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
def test_doctests_only(self):
# used to check if doctests gets converted properly.
doctest = textwrap.dedent('''\
"""Example docstring.
>>> print test
test
It works.
"""''')
with self.mktempfile() as fp:
fp.write(doctest)
mixin2to3 = Mixin2to3()
mixin2to3._run_2to3([fp.name])
expected = textwrap.dedent('''\
"""Example docstring.
>>> print(test)
test
It works.
"""\n''')
with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
def test_additional_fixers(self):
# used to check if use_2to3_fixers works
code = 'type(x) is not T'
with self.mktempfile() as fp:
fp.write(code)
mixin2to3 = Mixin2to3()
mixin2to3._run_2to3(files=[fp.name], doctests=[fp.name],
fixers=['packaging.tests.fixer'])
expected = 'not isinstance(x, T)'
with open(fp.name) as fp:
converted = fp.read()
self.assertEqual(expected, converted)
def test_suite():
return unittest.makeSuite(Mixin2to3TestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
|