async def test_open_async_with(): """Test that temporary files can be opened.""" content_expected = b"This is test content." async with aiotempfile() as file: path = await write_to_file(file, content_expected) assert await read_file(file) == content_expected await close_file(file, path)
async def test_open_context_manager__anext__(): """Test that temporary files can be opened.""" content_expected = b"This is test content." aiofiles_context_manager = aiotempfile() assert isinstance(aiofiles_context_manager, AiofilesContextManager) file = await aiofiles_context_manager.__anext__() path = await write_to_file(file, content_expected) assert await read_file(file) == content_expected await close_file(file, path) aiofiles_context_manager.close()
def test_open_context_manager__await__(): # pylint: disable=not-an-iterable """Test that temporary files can be opened.""" content_expected = b"This is test content." aiofiles_context_manager = aiotempfile() assert isinstance(aiofiles_context_manager, AiofilesContextManager) # https://stackoverflow.com/a/56114311/1201075 @coroutine def do_test() -> Path: file = yield from aiofiles_context_manager.__await__() path = yield from write_to_file(file, content_expected) content_acutal = yield from read_file(file) assert content_acutal == content_expected yield from close_file(file, path) yield from do_test() aiofiles_context_manager.close()
async def test_get_image_layer_to_disk( registry_v2_image_source: RegistryV2ImageSource, known_good_image_local: Dict, **kwargs, ): """Test layer retrieval to disk.""" if "protocol" in known_good_image_local: kwargs["protocol"] = known_good_image_local["protocol"] manifest = await registry_v2_image_source.get_manifest( known_good_image_local["image_name"], **kwargs) config_digest = manifest.get_config_digest() LOGGER.debug("Retrieving blob: %s/%s ...", config_digest, config_digest) async with aiotempfile(mode="w+b") as file: result = await registry_v2_image_source.get_image_layer_to_disk( known_good_image_local["image_name"], config_digest, file, **kwargs) LOGGER.debug("Verifying digest of written file ...") assert await hash_file(file.name) == config_digest assert result["digest"] == config_digest