mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
Stop trying to write into the stdlib during lib2to3 tests (#12331).
This prevents tests from failing when run from a Python installed in a read-only directory.
This commit is contained in:
parent
560bf855d3
commit
498da2c162
2 changed files with 14 additions and 7 deletions
|
|
@ -177,22 +177,26 @@ from __future__ import print_function"""
|
||||||
self.assertEqual(results, expected)
|
self.assertEqual(results, expected)
|
||||||
|
|
||||||
def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS):
|
def check_file_refactoring(self, test_file, fixers=_2TO3_FIXERS):
|
||||||
|
tmpdir = tempfile.mkdtemp(prefix="2to3-test_refactor")
|
||||||
|
self.addCleanup(shutil.rmtree, tmpdir)
|
||||||
|
# make a copy of the tested file that we can write to
|
||||||
|
shutil.copy(test_file, tmpdir)
|
||||||
|
test_file = os.path.join(tmpdir, os.path.basename(test_file))
|
||||||
|
os.chmod(test_file, 0o644)
|
||||||
|
|
||||||
def read_file():
|
def read_file():
|
||||||
with open(test_file, "rb") as fp:
|
with open(test_file, "rb") as fp:
|
||||||
return fp.read()
|
return fp.read()
|
||||||
|
|
||||||
old_contents = read_file()
|
old_contents = read_file()
|
||||||
rt = self.rt(fixers=fixers)
|
rt = self.rt(fixers=fixers)
|
||||||
|
|
||||||
rt.refactor_file(test_file)
|
rt.refactor_file(test_file)
|
||||||
self.assertEqual(old_contents, read_file())
|
self.assertEqual(old_contents, read_file())
|
||||||
|
|
||||||
try:
|
rt.refactor_file(test_file, True)
|
||||||
rt.refactor_file(test_file, True)
|
new_contents = read_file()
|
||||||
new_contents = read_file()
|
self.assertNotEqual(old_contents, new_contents)
|
||||||
self.assertNotEqual(old_contents, new_contents)
|
|
||||||
finally:
|
|
||||||
with open(test_file, "wb") as fp:
|
|
||||||
fp.write(old_contents)
|
|
||||||
return new_contents
|
return new_contents
|
||||||
|
|
||||||
def test_refactor_file(self):
|
def test_refactor_file(self):
|
||||||
|
|
|
||||||
|
|
@ -161,6 +161,9 @@ Tools/Demos
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #12331: The test suite for lib2to3 can now run from an installed
|
||||||
|
Python.
|
||||||
|
|
||||||
- Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64'
|
- Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64'
|
||||||
as the processor type on some Mac systems.
|
as the processor type on some Mac systems.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue