def test_package_has_no_reader_fallback(self): # Test odd ball packages which: # 1. Do not have a ResourceReader as a loader # 2. Are not on the file system # 3. Are not in a zip file module = util.create_package(file=data01, path=data01.__file__, contents=['A', 'B', 'C']) # Give the module a dummy loader. module.__loader__ = object() # Give the module a dummy origin. module.__file__ = '/path/which/shall/not/be/named' module.__spec__.loader = module.__loader__ module.__spec__.origin = module.__file__ self.assertFalse(resources.is_resource(module, 'A'))
def test_resource_missing_is_not_resource(self): package = util.create_package(file=data01, path=data01.__file__, contents=['A', 'B', 'C', 'D/E', 'D/F']) self.assertFalse(resources.is_resource(package, 'Z'))
def test_is_submodule_resource(self): self.assertTrue( resources.is_resource(import_module('namespacedata01'), 'binary.file'))
def test_read_submodule_resource_by_name(self): self.assertTrue(resources.is_resource('namespacedata01', 'binary.file'))
def test_is_resource_missing(self): self.assertFalse(resources.is_resource(self.data, 'not-a-file'))
def test_is_resource_subresource_directory(self): # Directories are not resources. self.assertFalse(resources.is_resource(self.data, 'subdirectory'))
def test_is_resource_failure_does_not_keep_open(self): c = resources.is_resource('ziptestdata', 'not-present') self.zip_path.unlink() del c
def test_is_resource_does_not_keep_open(self): c = resources.is_resource('ziptestdata', 'binary.file') self.zip_path.unlink() del c
def test_is_resource_good_path(self): self.assertTrue(resources.is_resource(self.data, 'binary.file'))
def test_read_submodule_resource_by_name(self): self.assertTrue( resources.is_resource('ziptestdata.subdirectory', 'binary.file'))
def test_is_submodule_resource(self): submodule = import_module('ziptestdata.subdirectory') self.assertTrue(resources.is_resource(submodule, 'binary.file'))