ยปCore Development>Code coverage>Lib/packaging/tests/test_mixin2to3.py

Python code coverage for Lib/packaging/tests/test_mixin2to3.py

#countcontent
1n/aimport textwrap
2n/a
3n/afrom packaging.tests import unittest, support
4n/afrom packaging.compat import Mixin2to3
5n/a
6n/a
7n/aclass Mixin2to3TestCase(support.TempdirManager,
8n/a support.LoggingCatcher,
9n/a unittest.TestCase):
10n/a
11n/a def setUp(self):
12n/a super(Mixin2to3TestCase, self).setUp()
13n/a self.filename = self.mktempfile().name
14n/a
15n/a def check(self, source, wanted, **kwargs):
16n/a source = textwrap.dedent(source)
17n/a with open(self.filename, 'w') as fp:
18n/a fp.write(source)
19n/a
20n/a Mixin2to3()._run_2to3(**kwargs)
21n/a
22n/a wanted = textwrap.dedent(wanted)
23n/a with open(self.filename) as fp:
24n/a converted = fp.read()
25n/a self.assertMultiLineEqual(converted, wanted)
26n/a
27n/a def test_conversion(self):
28n/a # check that code and doctests get converted
29n/a self.check('''\
30n/a """Example docstring.
31n/a
32n/a >>> print test
33n/a test
34n/a
35n/a It works.
36n/a """
37n/a print 'test'
38n/a ''',
39n/a '''\
40n/a """Example docstring.
41n/a
42n/a >>> print(test)
43n/a test
44n/a
45n/a It works.
46n/a """
47n/a print('test')
48n/a
49n/a ''', # 2to3 adds a newline here
50n/a files=[self.filename])
51n/a
52n/a def test_doctests_conversion(self):
53n/a # check that doctest files are converted
54n/a self.check('''\
55n/a Welcome to the doc.
56n/a
57n/a >>> print test
58n/a test
59n/a ''',
60n/a '''\
61n/a Welcome to the doc.
62n/a
63n/a >>> print(test)
64n/a test
65n/a
66n/a ''',
67n/a doctests=[self.filename])
68n/a
69n/a def test_additional_fixers(self):
70n/a # make sure the fixers argument works
71n/a self.check("""\
72n/a echo('42')
73n/a echo2('oh no')
74n/a """,
75n/a """\
76n/a print('42')
77n/a print('oh no')
78n/a """,
79n/a files=[self.filename],
80n/a fixers=['packaging.tests.fixer'])
81n/a
82n/a
83n/adef test_suite():
84n/a return unittest.makeSuite(Mixin2to3TestCase)
85n/a
86n/aif __name__ == "__main__":
87n/a unittest.main(defaultTest="test_suite")