mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Stop trying to write into the stdlib during packaging tests (#12331).
This prevents tests from failing when run from a Python installed in a read-only directory. The code is a bit uglier; shutil.copytree calls copystat on directories behind our back, so I had to add an os.walk with os.chmod (*and* os.path.join!) calls. shutil, I am disappoint. This changeset is dedicated to the hundreds of neurons that were lost while I was debugging this on an otherwise fine afternoon.
This commit is contained in:
parent
56ec5fe950
commit
b85b966de6
2 changed files with 34 additions and 23 deletions
|
@ -39,20 +39,40 @@ def record_pieces(file):
|
||||||
return [path, digest, size]
|
return [path, digest, size]
|
||||||
|
|
||||||
|
|
||||||
class CommonDistributionTests:
|
class FakeDistsMixin:
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(FakeDistsMixin, self).setUp()
|
||||||
|
self.addCleanup(enable_cache)
|
||||||
|
disable_cache()
|
||||||
|
|
||||||
|
# make a copy that we can write into for our fake installed
|
||||||
|
# distributions
|
||||||
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, tmpdir)
|
||||||
|
self.fake_dists_path = os.path.join(tmpdir, 'fake_dists')
|
||||||
|
fake_dists_src = os.path.abspath(
|
||||||
|
os.path.join(os.path.dirname(__file__), 'fake_dists'))
|
||||||
|
shutil.copytree(fake_dists_src, self.fake_dists_path)
|
||||||
|
# XXX ugly workaround: revert copystat calls done by shutil behind our
|
||||||
|
# back (to avoid getting a read-only copy of a read-only file). we
|
||||||
|
# could pass a custom copy_function to change the mode of files, but
|
||||||
|
# shutil gives no control over the mode of directories :(
|
||||||
|
for root, dirs, files in os.walk(self.fake_dists_path):
|
||||||
|
os.chmod(root, 0o755)
|
||||||
|
for f in files:
|
||||||
|
os.chmod(os.path.join(root, f), 0o644)
|
||||||
|
for d in dirs:
|
||||||
|
os.chmod(os.path.join(root, d), 0o755)
|
||||||
|
|
||||||
|
|
||||||
|
class CommonDistributionTests(FakeDistsMixin):
|
||||||
"""Mixin used to test the interface common to both Distribution classes.
|
"""Mixin used to test the interface common to both Distribution classes.
|
||||||
|
|
||||||
Derived classes define cls, sample_dist, dirs and records. These
|
Derived classes define cls, sample_dist, dirs and records. These
|
||||||
attributes are used in test methods. See source code for details.
|
attributes are used in test methods. See source code for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(CommonDistributionTests, self).setUp()
|
|
||||||
self.addCleanup(enable_cache)
|
|
||||||
disable_cache()
|
|
||||||
self.fake_dists_path = os.path.abspath(
|
|
||||||
os.path.join(os.path.dirname(__file__), 'fake_dists'))
|
|
||||||
|
|
||||||
def test_instantiation(self):
|
def test_instantiation(self):
|
||||||
# check that useful attributes are here
|
# check that useful attributes are here
|
||||||
name, version, distdir = self.sample_dist
|
name, version, distdir = self.sample_dist
|
||||||
|
@ -110,6 +130,7 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase):
|
||||||
|
|
||||||
self.records = {}
|
self.records = {}
|
||||||
for distinfo_dir in self.dirs:
|
for distinfo_dir in self.dirs:
|
||||||
|
|
||||||
record_file = os.path.join(distinfo_dir, 'RECORD')
|
record_file = os.path.join(distinfo_dir, 'RECORD')
|
||||||
with open(record_file, 'w') as file:
|
with open(record_file, 'w') as file:
|
||||||
record_writer = csv.writer(
|
record_writer = csv.writer(
|
||||||
|
@ -138,12 +159,6 @@ class TestDistribution(CommonDistributionTests, unittest.TestCase):
|
||||||
record_data[path] = md5_, size
|
record_data[path] = md5_, size
|
||||||
self.records[distinfo_dir] = record_data
|
self.records[distinfo_dir] = record_data
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
for distinfo_dir in self.dirs:
|
|
||||||
record_file = os.path.join(distinfo_dir, 'RECORD')
|
|
||||||
open(record_file, 'wb').close()
|
|
||||||
super(TestDistribution, self).tearDown()
|
|
||||||
|
|
||||||
def test_instantiation(self):
|
def test_instantiation(self):
|
||||||
super(TestDistribution, self).test_instantiation()
|
super(TestDistribution, self).test_instantiation()
|
||||||
self.assertIsInstance(self.dist.requested, bool)
|
self.assertIsInstance(self.dist.requested, bool)
|
||||||
|
@ -252,20 +267,13 @@ class TestEggInfoDistribution(CommonDistributionTests,
|
||||||
|
|
||||||
|
|
||||||
class TestDatabase(support.LoggingCatcher,
|
class TestDatabase(support.LoggingCatcher,
|
||||||
|
FakeDistsMixin,
|
||||||
unittest.TestCase):
|
unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestDatabase, self).setUp()
|
super(TestDatabase, self).setUp()
|
||||||
disable_cache()
|
|
||||||
# Setup the path environment with our fake distributions
|
|
||||||
current_path = os.path.abspath(os.path.dirname(__file__))
|
|
||||||
self.fake_dists_path = os.path.join(current_path, 'fake_dists')
|
|
||||||
sys.path.insert(0, self.fake_dists_path)
|
sys.path.insert(0, self.fake_dists_path)
|
||||||
|
self.addCleanup(sys.path.remove, self.fake_dists_path)
|
||||||
def tearDown(self):
|
|
||||||
sys.path.remove(self.fake_dists_path)
|
|
||||||
enable_cache()
|
|
||||||
super(TestDatabase, self).tearDown()
|
|
||||||
|
|
||||||
def test_distinfo_dirname(self):
|
def test_distinfo_dirname(self):
|
||||||
# Given a name and a version, we expect the distinfo_dirname function
|
# Given a name and a version, we expect the distinfo_dirname function
|
||||||
|
|
|
@ -1147,6 +1147,9 @@ Extension Modules
|
||||||
Tests
|
Tests
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
- Issue #12331: The test suite for the packaging module can now run from an
|
||||||
|
installed Python.
|
||||||
|
|
||||||
- Issue #12331: The test suite for lib2to3 can now run from an installed
|
- Issue #12331: The test suite for lib2to3 can now run from an installed
|
||||||
Python.
|
Python.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue