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
82
83
84
85
86
87
|
import textwrap
from packaging.tests import unittest, support
from packaging.compat import Mixin2to3
class Mixin2to3TestCase(support.TempdirManager,
support.LoggingCatcher,
unittest.TestCase):
def setUp(self):
super(Mixin2to3TestCase, self).setUp()
self.filename = self.mktempfile().name
def check(self, source, wanted, **kwargs):
source = textwrap.dedent(source)
with open(self.filename, 'w') as fp:
fp.write(source)
Mixin2to3()._run_2to3(**kwargs)
wanted = textwrap.dedent(wanted)
with open(self.filename) as fp:
converted = fp.read()
self.assertMultiLineEqual(converted, wanted)
def test_conversion(self):
# check that code and doctests get converted
self.check('''\
"""Example docstring.
>>> print test
test
It works.
"""
print 'test'
''',
'''\
"""Example docstring.
>>> print(test)
test
It works.
"""
print('test')
''', # 2to3 adds a newline here
files=[self.filename])
def test_doctests_conversion(self):
# check that doctest files are converted
self.check('''\
Welcome to the doc.
>>> print test
test
''',
'''\
Welcome to the doc.
>>> print(test)
test
''',
doctests=[self.filename])
def test_additional_fixers(self):
# make sure the fixers argument works
self.check("""\
echo('42')
echo2('oh no')
""",
"""\
print('42')
print('oh no')
""",
files=[self.filename],
fixers=['packaging.tests.fixer'])
def test_suite():
return unittest.makeSuite(Mixin2to3TestCase)
if __name__ == "__main__":
unittest.main(defaultTest="test_suite")
|