Best Python code snippet using localstack_python
test_docker.py
Source:test_docker.py
...326 assert tmpdir.join("foo.log").isfile(), "foo.log was not created in mounted dir"327 @pytest.mark.skipif(328 condition=in_docker(), reason="cannot test volume mounts from host when in docker"329 )330 def test_inspect_container_volumes(331 self, tmpdir, docker_client: ContainerClient, create_container332 ):333 mount_volumes = [334 (tmpdir.realpath() / "foo", "/tmp/mypath/foo"),335 ("some_named_volume", "/tmp/mypath/volume"),336 ]337 c = create_container(338 "alpine",339 command=["sh", "-c", "while true; do sleep 1; done"],340 mount_volumes=mount_volumes,341 )342 docker_client.start_container(c.container_id)343 vols = docker_client.inspect_container_volumes(c.container_id)344 # FIXME cmd docker client creates different default permission mode flags345 if isinstance(docker_client, CmdDockerClient):346 vol1 = VolumeInfo(347 type="bind",348 source=f"{tmpdir}/foo",349 destination="/tmp/mypath/foo",350 mode="",351 rw=True,352 propagation="rprivate",353 name=None,354 driver=None,355 )356 vol2 = VolumeInfo(357 type="volume",358 source="/var/lib/docker/volumes/some_named_volume/_data",359 destination="/tmp/mypath/volume",360 mode="z",361 rw=True,362 propagation="",363 name="some_named_volume",364 driver="local",365 )366 else:367 vol1 = VolumeInfo(368 type="bind",369 source=f"{tmpdir}/foo",370 destination="/tmp/mypath/foo",371 mode="rw",372 rw=True,373 propagation="rprivate",374 name=None,375 driver=None,376 )377 vol2 = VolumeInfo(378 type="volume",379 source="/var/lib/docker/volumes/some_named_volume/_data",380 destination="/tmp/mypath/volume",381 mode="rw",382 rw=True,383 propagation="",384 name="some_named_volume",385 driver="local",386 )387 assert vol1 in vols388 assert vol2 in vols389 def test_inspect_container_volumes_with_no_volumes(390 self, docker_client: ContainerClient, dummy_container391 ):392 docker_client.start_container(dummy_container.container_id)393 assert len(docker_client.inspect_container_volumes(dummy_container.container_id)) == 0394 def test_copy_into_container(self, tmpdir, docker_client: ContainerClient, create_container):395 local_path = tmpdir.join("myfile.txt")396 container_path = "/tmp/myfile_differentpath.txt"397 self._test_copy_into_container(398 docker_client,399 create_container,400 ["cat", container_path],401 local_path,402 local_path,403 container_path,404 )405 def test_copy_into_non_existent_container(self, tmpdir, docker_client: ContainerClient):406 local_path = tmpdir.mkdir("test_dir")407 file_path = local_path.join("test_file")...
docker_utils.py
Source:docker_utils.py
...42 if not container_id:43 raise OSError("no hostname returned to use as container id")44 return container_id45def inspect_current_container_mounts() -> List[VolumeInfo]:46 return DOCKER_CLIENT.inspect_container_volumes(get_current_container_id())47@functools.lru_cache()48def get_default_volume_dir_mount() -> Optional[VolumeInfo]:49 """50 Returns the volume information of LocalStack's DEFAULT_VOLUME_DIR (/var/lib/localstack), if mounted,51 else it returns None. If we're not currently in docker a VauleError is raised. in a container, a ValueError is52 raised.53 :return: the volume info of the default volume dir or None54 """55 for volume in inspect_current_container_mounts():56 if volume.destination.rstrip("/") == DEFAULT_VOLUME_DIR:57 return volume58 return None...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!