diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-12 13:46:50 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-05-12 13:46:50 -0400 |
commit | e73268755f8d4889f5491907a9b366f8c2b0770d (patch) | |
tree | 86a5157a4834e65cb861c8b28f10961e4f2e4d90 /tests/test_pkg_resources.py | |
parent | b9661afd506c7c5f43d01c092ce313f33e730892 (diff) | |
download | external_python_setuptools-e73268755f8d4889f5491907a9b366f8c2b0770d.tar.gz external_python_setuptools-e73268755f8d4889f5491907a9b366f8c2b0770d.tar.bz2 external_python_setuptools-e73268755f8d4889f5491907a9b366f8c2b0770d.zip |
Adding test that captures the new requirement.
--HG--
branch : distribute
extra : rebase_source : fcf8db4d0becf51a1e192ec438c13f81d391e342
Diffstat (limited to 'tests/test_pkg_resources.py')
-rw-r--r-- | tests/test_pkg_resources.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/test_pkg_resources.py b/tests/test_pkg_resources.py new file mode 100644 index 00000000..7009b4ab --- /dev/null +++ b/tests/test_pkg_resources.py @@ -0,0 +1,61 @@ +import sys +import tempfile +import os +import zipfile + +import pkg_resources + +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 = [] + + @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 = 2013, 5, 12, 13, 25, 0 + zip_egg.writestr(zip_info, 'x = 3\n') + zip_info = zipfile.ZipInfo() + zip_info.filename = 'data.dat' + zip_info.date_time = 2013, 5, 12, 13, 25, 0 + 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') + assert os.stat(filename).st_mtime == 1368379500 + f = open(filename, 'wb') + f.write('hello, world?') + f.close() + os.utime(filename, (1368379500, 1368379500)) + filename = zp.get_resource_filename(manager, 'data.dat') + f = open(filename) + assert f.read() == 'hello, world!' + manager.cleanup_resources() |