summaryrefslogtreecommitdiffstats
path: root/Lib/packaging/tests/test_mixin2to3.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/packaging/tests/test_mixin2to3.py')
-rw-r--r--Lib/packaging/tests/test_mixin2to3.py77
1 files changed, 43 insertions, 34 deletions
diff --git a/Lib/packaging/tests/test_mixin2to3.py b/Lib/packaging/tests/test_mixin2to3.py
index d7c83c2..926f754 100644
--- a/Lib/packaging/tests/test_mixin2to3.py
+++ b/Lib/packaging/tests/test_mixin2to3.py
@@ -1,5 +1,5 @@
-"""Tests for packaging.command.build_py."""
import sys
+import textwrap
from packaging.tests import unittest, support
from packaging.compat import Mixin2to3
@@ -12,60 +12,69 @@ class Mixin2to3TestCase(support.TempdirManager,
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_convert_code_only(self):
# used to check if code gets converted properly.
- code_content = "print 'test'\n"
- code_handle = self.mktempfile()
- code_name = code_handle.name
+ code = "print 'test'"
- code_handle.write(code_content)
- code_handle.flush()
+ with self.mktempfile() as fp:
+ fp.write(code)
mixin2to3 = Mixin2to3()
- mixin2to3._run_2to3([code_name])
- converted_code_content = "print('test')\n"
- with open(code_name) as fp:
- new_code_content = "".join(fp.readlines())
+ mixin2to3._run_2to3([fp.name])
+ expected = "print('test')"
- self.assertEqual(new_code_content, converted_code_content)
+ with open(fp.name) as fp:
+ converted = fp.read()
+
+ self.assertEqual(expected, converted)
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_doctests_only(self):
# used to check if doctests gets converted properly.
- doctest_content = '"""\n>>> print test\ntest\n"""\nprint test\n\n'
- doctest_handle = self.mktempfile()
- doctest_name = doctest_handle.name
+ doctest = textwrap.dedent('''\
+ """Example docstring.
+
+ >>> print test
+ test
+
+ It works.
+ """''')
- doctest_handle.write(doctest_content)
- doctest_handle.flush()
+ with self.mktempfile() as fp:
+ fp.write(doctest)
mixin2to3 = Mixin2to3()
- mixin2to3._run_2to3([doctest_name])
+ mixin2to3._run_2to3([fp.name])
+ expected = textwrap.dedent('''\
+ """Example docstring.
+
+ >>> print(test)
+ test
+
+ It works.
+ """\n''')
- converted_doctest_content = ['"""', '>>> print(test)', 'test', '"""',
- 'print(test)', '', '', '']
- converted_doctest_content = '\n'.join(converted_doctest_content)
- with open(doctest_name) as fp:
- new_doctest_content = "".join(fp.readlines())
+ with open(fp.name) as fp:
+ converted = fp.read()
- self.assertEqual(new_doctest_content, converted_doctest_content)
+ self.assertEqual(expected, converted)
@unittest.skipIf(sys.version < '2.6', 'requires Python 2.6 or higher')
def test_additional_fixers(self):
# used to check if use_2to3_fixers works
- code_content = "type(x) is T"
- code_handle = self.mktempfile()
- code_name = code_handle.name
+ code = 'type(x) is not T'
- code_handle.write(code_content)
- code_handle.flush()
+ with self.mktempfile() as fp:
+ fp.write(code)
mixin2to3 = Mixin2to3()
-
- mixin2to3._run_2to3(files=[code_name], doctests=[code_name],
+ mixin2to3._run_2to3(files=[fp.name], doctests=[fp.name],
fixers=['packaging.tests.fixer'])
- converted_code_content = "isinstance(x, T)"
- with open(code_name) as fp:
- new_code_content = "".join(fp.readlines())
- self.assertEqual(new_code_content, converted_code_content)
+
+ expected = 'not isinstance(x, T)'
+
+ with open(fp.name) as fp:
+ converted = fp.read()
+
+ self.assertEqual(expected, converted)
def test_suite():