def test_docker_kwargs():
    code_dir = Path(__file__).parent
    container_first = DockerContainer("nginx:latest")
    container_first.with_volume_mapping(code_dir, '/code')

    container_second = DockerContainer("nginx:latest")

    with container_first:
        container_second.with_kwargs(volumes_from=[container_first._container.short_id])
        with container_second:
            files_first = container_first.exec('ls /code').output.decode('utf-8').strip()
            files_second = container_second.exec('ls /code').output.decode('utf-8').strip()
            assert files_first == files_second
def test_add_map_entry_override_non_mapping_value():
    code_dir = Path(__file__).parent
    container = DockerContainer("nginx:latest",
                                something='initial-value-is-not-a-map')
    container._with_map_entry('something', 'is', 'arbitrary')
    container._with_map_entry('something', 'also', 'arbitrary')
    container.with_bind_ports(8080, 80)
    container.with_exposed_ports(8000)
    container.with_env('test', 'value')
    container.with_volume_mapping(code_dir, '/code')

    assert container._kwargs['something'] == {
        'also': 'arbitrary',
        'is': 'arbitrary'
    }
    assert container._kwargs['ports'] == {8000: None, 8080: 80}
    assert container._kwargs['environment'] == {'test': 'value'}
    assert container._kwargs['volumes'] == {
        code_dir: {
            'bind': '/code',
            'mode': 'ro'
        }
    }