我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用pkg_resources.ResourceManager()。
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()
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') with open(filename) as f: assert f.read() == 'hello, world!' manager.cleanup_resources()
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