aboutsummaryrefslogtreecommitdiffstats
path: root/pkg_resources/tests/test_pkg_resources.py
diff options
context:
space:
mode:
Diffstat (limited to 'pkg_resources/tests/test_pkg_resources.py')
-rw-r--r--pkg_resources/tests/test_pkg_resources.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/pkg_resources/tests/test_pkg_resources.py b/pkg_resources/tests/test_pkg_resources.py
index 4e2cac94..62a39b8f 100644
--- a/pkg_resources/tests/test_pkg_resources.py
+++ b/pkg_resources/tests/test_pkg_resources.py
@@ -12,6 +12,11 @@ import stat
import distutils.dist
import distutils.command.install_egg_info
+try:
+ from unittest import mock
+except ImportError:
+ import mock
+
from pkg_resources.extern.six.moves import map
from pkg_resources.extern.six import text_type, string_types
@@ -138,8 +143,34 @@ class TestResourceManager:
message = "Unexpected type from get_cache_path: " + type_
assert isinstance(path, string_types), message
+ def test_get_cache_path_race(self, tmpdir):
+ # Patch to os.path.isdir to create a race condition
+ def patched_isdir(dirname, unpatched_isdir=pkg_resources.isdir):
+ patched_isdir.dirnames.append(dirname)
+
+ was_dir = unpatched_isdir(dirname)
+ if not was_dir:
+ os.makedirs(dirname)
+ return was_dir
+
+ patched_isdir.dirnames = []
+
+ # Get a cache path with a "race condition"
+ mgr = pkg_resources.ResourceManager()
+ mgr.set_extraction_path(str(tmpdir))
+
+ archive_name = os.sep.join(('foo', 'bar', 'baz'))
+ with mock.patch.object(pkg_resources, 'isdir', new=patched_isdir):
+ mgr.get_cache_path(archive_name)
+
+ # Because this test relies on the implementation details of this
+ # function, these assertions are a sentinel to ensure that the
+ # test suite will not fail silently if the implementation changes.
+ called_dirnames = patched_isdir.dirnames
+ assert len(called_dirnames) == 2
+ assert called_dirnames[0].split(os.sep)[-2:] == ['foo', 'bar']
+ assert called_dirnames[1].split(os.sep)[-1:] == ['foo']
-class TestIndependence:
"""
Tests to ensure that pkg_resources runs independently from setuptools.
"""