def test_resource_api(easter_fixture):
test_file = NamedTemporaryFile(mode='wb+')
dirname, file_name = os.path.split(test_file.name)
easter_fixture.stub_egg.location = dirname
easter_fixture.stub_egg.activate()
assert pkg_resources.resource_exists(easter_fixture.stub_egg.as_requirement(), file_name)
assert not pkg_resources.resource_exists(easter_fixture.stub_egg.as_requirement(), 'IDoNotExist')
contents = b'asdd '
test_file.write(contents)
test_file.flush()
as_string = pkg_resources.resource_string(easter_fixture.stub_egg.as_requirement(), file_name)
assert as_string == contents
as_file = pkg_resources.resource_stream(easter_fixture.stub_egg.as_requirement(), file_name)
assert as_file.read() == contents
评论列表
文章目录