diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-03 02:29:01 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-01-03 02:29:01 -0500 |
commit | d0a3a68d5192935730eeab840790f35af971086a (patch) | |
tree | 8d0d7da2d4f1818bfa6d8e7f5187ceb697c361f6 /tests | |
parent | 26a1521e870855ef89e6481f94293cded8237571 (diff) | |
download | external_python_setuptools-d0a3a68d5192935730eeab840790f35af971086a.tar.gz external_python_setuptools-d0a3a68d5192935730eeab840790f35af971086a.tar.bz2 external_python_setuptools-d0a3a68d5192935730eeab840790f35af971086a.zip |
Moved test_resources and test_pkg_resources to pkg_resources package.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pkg_resources.py | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/tests/test_pkg_resources.py b/tests/test_pkg_resources.py deleted file mode 100644 index 564d7cec..00000000 --- a/tests/test_pkg_resources.py +++ /dev/null @@ -1,111 +0,0 @@ -import sys -import tempfile -import os -import zipfile -import datetime -import time -import subprocess - -import pkg_resources - -try: - unicode -except NameError: - unicode = str - -def timestamp(dt): - """ - Return a timestamp for a local, naive datetime instance. - """ - try: - return dt.timestamp() - except AttributeError: - # Python 3.2 and earlier - return time.mktime(dt.timetuple()) - -class EggRemover(unicode): - def __call__(self): - if self in sys.path: - sys.path.remove(self) - if os.path.exists(self): - os.remove(self) - -class TestZipProvider(object): - finalizers = [] - - ref_time = datetime.datetime(2013, 5, 12, 13, 25, 0) - "A reference time for a file modification" - - @classmethod - def setup_class(cls): - "create a zip egg and add it to sys.path" - egg = tempfile.NamedTemporaryFile(suffix='.egg', delete=False) - zip_egg = zipfile.ZipFile(egg, 'w') - zip_info = zipfile.ZipInfo() - zip_info.filename = 'mod.py' - zip_info.date_time = cls.ref_time.timetuple() - zip_egg.writestr(zip_info, 'x = 3\n') - zip_info = zipfile.ZipInfo() - zip_info.filename = 'data.dat' - zip_info.date_time = cls.ref_time.timetuple() - zip_egg.writestr(zip_info, 'hello, world!') - zip_egg.close() - egg.close() - - sys.path.append(egg.name) - cls.finalizers.append(EggRemover(egg.name)) - - @classmethod - def teardown_class(cls): - for finalizer in cls.finalizers: - finalizer() - - def test_resource_filename_rewrites_on_change(self): - """ - If a previous call to get_resource_filename has saved the file, but - the file has been subsequently mutated with different file of the - same size and modification time, it should not be overwritten on a - subsequent call to get_resource_filename. - """ - import mod - manager = pkg_resources.ResourceManager() - zp = pkg_resources.ZipProvider(mod) - filename = zp.get_resource_filename(manager, 'data.dat') - actual = datetime.datetime.fromtimestamp(os.stat(filename).st_mtime) - assert actual == self.ref_time - f = open(filename, 'w') - f.write('hello, world?') - f.close() - ts = timestamp(self.ref_time) - os.utime(filename, (ts, ts)) - filename = zp.get_resource_filename(manager, 'data.dat') - f = open(filename) - assert f.read() == 'hello, world!' - manager.cleanup_resources() - -class TestResourceManager(object): - def test_get_cache_path(self): - mgr = pkg_resources.ResourceManager() - path = mgr.get_cache_path('foo') - type_ = str(type(path)) - message = "Unexpected type from get_cache_path: " + type_ - assert isinstance(path, (unicode, str)), message - - -class TestIndependence: - """ - Tests to ensure that pkg_resources runs independently from setuptools. - """ - def test_setuptools_not_imported(self): - """ - In a separate Python environment, import pkg_resources and assert - that action doesn't cause setuptools to be imported. - """ - lines = ( - 'import pkg_resources', - 'import sys', - 'assert "setuptools" not in sys.modules, ' - '"setuptools was imported"', - ) - cmd = [sys.executable, '-c', '; '.join(lines)] - subprocess.check_call(cmd) |