summaryrefslogtreecommitdiff
path: root/Lib/packaging/tests/test_mixin2to3.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2012-03-17 16:58:12 +0100
committerGeorg Brandl <georg@python.org>2012-03-17 16:58:12 +0100
commitffd4830f6ab0942a463772a01a91f051bfa2d376 (patch)
tree14d5f982ed3d51197f0dd69370d3f6002aec8e1e /Lib/packaging/tests/test_mixin2to3.py
parent206a0cc1b0f2545eef212be6210b4bf7008815ba (diff)
parent5d6d9423be73e8c6f3f18fa3e006573fc5836236 (diff)
downloadcpython-ffd4830f6ab0942a463772a01a91f051bfa2d376.tar.gz
merge with 3.2
Diffstat (limited to 'Lib/packaging/tests/test_mixin2to3.py')
-rw-r--r--Lib/packaging/tests/test_mixin2to3.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/Lib/packaging/tests/test_mixin2to3.py b/Lib/packaging/tests/test_mixin2to3.py
new file mode 100644
index 0000000000..08a102b5f6
--- /dev/null
+++ b/Lib/packaging/tests/test_mixin2to3.py
@@ -0,0 +1,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")