예제 #1
0
파일: image.py 프로젝트: r00ta/conu
    def get_volume_options(volumes):
        """
        Generates volume options to run methods.

        :param volumes: tuple or list of tuples in form target x source,target x source,target,mode.
        :return: list of the form ["-v", "/source:/target", "-v", "/other/source:/destination:z", ...]
        """
        if not isinstance(volumes, list):
            volumes = [volumes]
        volumes = [Volume.create_from_tuple(v) for v in volumes]
        result = []
        for v in volumes:
            result += ["-v", str(v)]
        return result
예제 #2
0
def test_volume_create_from_tuple(input_parameter, result):
    assert str(Volume.create_from_tuple(input_parameter)) == result
예제 #3
0
def test_volume_init(source, target, mode, result):
    assert str(Volume(source=source, target=target, mode=mode)) == result
예제 #4
0
])
def test_volume_create_from_tuple(input_parameter, result):
    assert str(Volume.create_from_tuple(input_parameter)) == result


@pytest.mark.parametrize("source,target,mode,result", [
    (None, "/target/path", None, "/target/path"),
    ("/source/path", "/target/path", None, "/source/path:/target/path"),
    ("/source/path", "/target/path", "mode", "/source/path:/target/path:mode"),
    (Directory("/source/path"), "/target/path", None,
     "/source/path:/target/path"),
    (Directory("/source/path"), "/target/path", "mode",
     "/source/path:/target/path:mode"),
])
def test_volume_init(source, target, mode, result):
    assert str(Volume(source=source, target=target, mode=mode)) == result


@pytest.mark.parametrize("instance,result", [
    (Volume("/target/path"), "/target/path"),
    (Volume("/target/path", "/source/path"), "/source/path:/target/path"),
    (Volume("/target/path", "/source/path",
            "mode"), "/source/path:/target/path:mode"),
    (Volume("/target/path",
            Directory("/source/path")), "/source/path:/target/path"),
    (Volume("/target/path", Directory("/source/path"),
            "mode"), "/source/path:/target/path:mode"),
])
def test_volume_init_raw(instance, result):
    assert str(instance) == result