Ejemplo n.º 1
0
def test_imagename_str() -> None:
    """Test string representations of image names."""
    i1 = ImageName("CHEESE")
    i2 = ImageName("a/b", "C")

    assert str(i1) == "CHEESE"
    assert str(i2) == "a/b:C"
Ejemplo n.º 2
0
def test_imagename_repr() -> None:
    """Test evaluable string representations of ImageName."""
    i1 = ImageName("a")
    i2 = ImageName("one", "two")
    i3 = ImageName("%^£\"'__3", "&**((£)_!:£~!!!")

    assert eval(repr(i1)) == i1
    assert eval(repr(i2)) == i2
    assert eval(repr(i3)) == i3
Ejemplo n.º 3
0
def test_component_load_valid() -> None:
    """Test loading a component from a file."""
    with open(COMPONENT_VALID) as fp:
        assert Component.load_from_file(fp) == Component(
            recipe=BuildRecipe(commands=["RUN cd .."]),
            compatible=[ImageName("example"),
                        ImageName("test", "13.2")],
            description="A very exciting component.",
        )
Ejemplo n.º 4
0
def test_component_initialisation() -> None:
    """Test creating components."""
    Component(BuildRecipe(["RUN cd ."]))
    Component(
        RunRecipe(script=["a", "b"]),
        [ImageName.from_str("a/b:c"),
         ImageName("qwerty", "uiop")],
        None,
        "does absolutely nothing",
    )
Ejemplo n.º 5
0
def test_imagename_eq() -> None:
    """Test ImageName equality."""
    i1 = ImageName("abc", "def")
    i2 = ImageName("abc", "def")
    i3 = ImageName("abc")
    i4 = ImageName("asd", "def")
    i5 = ["humpty", "dumpty", "had", "a", "great", "fall"]

    assert i1 == i2 and i2 == i1
    assert i1 != i3 and i3 != i1
    assert i1 != i4 and i4 != i1
    assert i1 != i5 and i5 != i1
Ejemplo n.º 6
0
def test_component_should_run() -> None:
    """Test whether components should be executed."""
    c1 = Component(RunRecipe(),
                   [ImageName("ubuntu"),
                    ImageName("debian", "stretch")])
    c2 = Component(BuildRecipe(["FROM nixos"]))

    i1 = ImageName("ubuntu")
    i2 = ImageName("ubuntu", "18.04")
    i3 = ImageName("debian")
    i4 = ImageName("debian", "stretch")
    i5 = ImageName("debian", "jessie")
    i6 = ImageName("arch")

    assert c1.should_run(i1)
    assert c1.should_run(i2)
    assert not c1.should_run(i3)
    assert c1.should_run(i4)
    assert not c1.should_run(i5)
    assert not c1.should_run(i6)

    assert c2.should_run(i1)
    assert c2.should_run(i2)
    assert c2.should_run(i3)
    assert c2.should_run(i4)
    assert c2.should_run(i5)
    assert c2.should_run(i6)
Ejemplo n.º 7
0
def test_environmentdefinition_load_valid() -> None:
    """Test loading Environment Definition from file."""
    m1 = Module(
        name="ubuntu",
        components=[
            Component(
                recipe=BuildRecipe(commands=["FROM ubuntu"]),
                results=ImageName("ubuntu"),
            )
        ],
    )

    m2 = Module(
        name="zsh",
        components=[
            Component(
                recipe=BuildRecipe(
                    commands=["RUN apt update && apt install zsh"]),
                compatible=[ImageName("ubuntu"),
                            ImageName("debian")],
                description="Installs zsh using apt.",
            ),
            Component(
                recipe=BuildRecipe(commands=["RUN pacman -S zsh"]),
                compatible=[ImageName("arch"),
                            ImageName("manjaro")],
                description="Installs zsh using pacman.",
            ),
            Component(
                recipe=BuildRecipe(commands=["CMD zsh"]),
                description="Use zsh as the entry command.",
            ),
            Component(recipe=RunRecipe(ports=[(3000, 3000), (8080, 8080)]), )
        ],
    )

    env_valid = EnvironmentDefinition(
        name="example-environment",
        modules=[m1, m2],
    )

    with open(ENV_VALID) as fp:
        assert EnvironmentDefinition.load_from_file(fp) == env_valid
Ejemplo n.º 8
0
def test_module_load_valid() -> None:
    """Test loading a module from a file."""
    with open(MODULE_VALID) as fp:
        assert Module.load_from_file(fp) == Module(
            name="example module",
            description="A module which is also an example!",
            components=[
                Component(
                    BuildRecipe(
                        commands=["FROM example-image",
                                  "RUN some-setup-cmd"], )),
                Component(
                    RunRecipe(script=["./fix-bug.sh --version 19.07"]),
                    compatible=[ImageName("example-image", "19.07")],
                ),
            ],
        )
Ejemplo n.º 9
0
def test_imagename_from_str_no_tag() -> None:
    """Test creating an ImageName from an untagged string."""
    image = ImageName.from_str("banana")

    assert image == ImageName("banana")
Ejemplo n.º 10
0
def test_imagename_load_from_empty() -> None:
    """Test loading empty file as ImageName."""
    with pytest.raises(TypeError):
        with open(YAML_EMPTY) as fp:
            ImageName.load_from_file(fp)
Ejemplo n.º 11
0
def test_imagename_comparisons() -> None:
    """Test comparing image names."""
    fish1 = ImageName("fish")
    fish2 = ImageName("fish", "3.6")

    assert fish1.is_compatible(fish2)
    assert fish2.is_compatible(fish2)
    assert not fish2.is_compatible(fish1)

    frog1 = ImageName("Frog", "twenty-seven")
    frog2 = ImageName("frog", "twenty-seven")

    assert not frog1.is_compatible(frog2)
    assert not frog2.is_compatible(frog1)
Ejemplo n.º 12
0
def test_imagename_load_full() -> None:
    """Test loading a full ImageName."""
    with open(IMAGENAME_FULL) as fp:
        assert ImageName.load_from_file(fp) == ImageName("banana", "13.76")
Ejemplo n.º 13
0
def test_imagename_load_partial() -> None:
    """Test loading a partial ImageName."""
    with open(IMAGENAME_PARTIAL) as fp:
        assert ImageName.load_from_file(fp) == ImageName("eee")
Ejemplo n.º 14
0
def test_imagename_from_bad_str() -> None:
    """Test creating an ImageName from a multi-tagged string."""
    with pytest.raises(ValueError):
        ImageName.from_str("a/b:c:d")
Ejemplo n.º 15
0
def test_imagename_from_str_with_tag() -> None:
    """Test creating an ImageName from a tagged string."""
    image = ImageName.from_str("bakery/bread:worryingly_moist")

    assert image == ImageName("bakery/bread", "worryingly_moist")
Ejemplo n.º 16
0
def test_imagename_load_invalid() -> None:
    """Test loading an invalid ImageName."""
    with pytest.raises(ValidationError):
        with open(IMAGENAME_INVALID) as fp:
            ImageName.load_from_file(fp)
Ejemplo n.º 17
0
def test_imagename_instantiation() -> None:
    """Test creating an ImageName."""
    ImageName("ghoti")
    ImageName("bolognese", "sauce")