Exemplo n.º 1
0
def test_parse_batch_call(assets: LocalPath) -> None:
    workspace = assets
    config_file = workspace / "batch-action-call.yml"
    flow = parse_batch(workspace, config_file)
    assert flow == ast.BatchFlow(
        Pos(0, 0, config_file),
        Pos(6, 0, config_file),
        params=None,
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.BATCH,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                   Pos(0, 0, config_file), None),
        images=None,
        volumes=None,
        defaults=None,
        mixins=None,
        tasks=[
            ast.TaskActionCall(
                Pos(2, 2, config_file),
                Pos(6, 0, config_file),
                id=OptIdExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "test"),
                needs=None,
                strategy=None,
                cache=None,
                enable=EnableExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ success() }}",
                ),
                action=SimpleStrExpr(Pos(0, 0, config_file),
                                     Pos(0, 0, config_file),
                                     "ws:batch-action"),
                args={
                    "arg1":
                    PrimitiveExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), "val 1")
                },
            )
        ],
    )
Exemplo n.º 2
0
def test_parse_live_module_call(assets: LocalPath) -> None:
    workspace = assets
    config_file = workspace / "live-module-call.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(16, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        images=None,
        volumes=None,
        defaults=ANY,
        mixins=None,
        jobs={
            "test":
            ast.JobModuleCall(
                Pos(13, 4, config_file),
                Pos(16, 0, config_file),
                module=SimpleStrExpr(
                    Pos(13, 4, config_file),
                    Pos(15, 0, config_file),
                    "workspace:live-module",
                ),
                args={
                    "arg1":
                    PrimitiveExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), "val 1")
                },
                params=None,
            )
        },
    )
Exemplo n.º 3
0
def test_parse_stateful_action(assets: LocalPath) -> None:
    config_file = assets / "stateful_actions/parser-test.yml"
    action = parse_action(config_file)
    assert action == ast.StatefulAction(
        Pos(0, 0, config_file),
        Pos(19, 0, config_file),
        kind=ast.ActionKind.STATEFUL,
        name=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Test stateful Action",
        ),
        author=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Andrew Svetlov",
        ),
        descr=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "description of test action",
        ),
        inputs={
            "arg1":
            ast.Input(
                Pos(6, 4, config_file),
                Pos(7, 2, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 1"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file), None),
            ),
            "arg2":
            ast.Input(
                Pos(8, 4, config_file),
                Pos(10, 0, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 2"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file),
                                               "value 2"),
            ),
        },
        outputs={
            "res":
            ast.Output(
                Pos(12, 4, config_file),
                Pos(13, 0, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file),
                                       "action result"),
                value=OptStrExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
            )
        },
        main=ast.ExecUnit(
            Pos(14, 2, config_file),
            Pos(16, 0, config_file),
            title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             None),
            name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            None),
            image=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "ubuntu"),
            preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                              None),
            schedule_timeout=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                              Pos(0, 0, config_file), None),
            entrypoint=OptStrExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            cmd=OptBashExpr(
                Pos(0, 0, config_file),
                Pos(0, 0, config_file),
                "echo ::save-state name=state::State",
            ),
            workdir=OptRemotePathExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
            env=None,
            volumes=None,
            tags=None,
            life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), None),
            http_port=OptIntExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
            http_auth=OptBoolExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            pass_config=OptBoolExpr(Pos(0, 0, config_file),
                                    Pos(0, 0, config_file), None),
        ),
        post=ast.ExecUnit(
            Pos(17, 2, config_file),
            Pos(19, 0, config_file),
            title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             None),
            name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            None),
            image=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "ubuntu"),
            preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                              None),
            schedule_timeout=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                              Pos(0, 0, config_file), None),
            entrypoint=OptStrExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            cmd=OptBashExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            "echo End"),
            workdir=OptRemotePathExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
            env=None,
            volumes=None,
            tags=None,
            life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), None),
            http_port=OptIntExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
            http_auth=OptBoolExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            pass_config=OptBoolExpr(Pos(0, 0, config_file),
                                    Pos(0, 0, config_file), None),
        ),
        post_if=EnableExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                           "${{ always() }}"),
    )
Exemplo n.º 4
0
def test_parse_batch_action(assets: LocalPath) -> None:
    config_file = assets / "batch-action-with-image.yml"
    action = parse_action(config_file)
    assert action == ast.BatchAction(
        Pos(0, 0, config_file),
        Pos(43, 0, config_file),
        kind=ast.ActionKind.BATCH,
        name=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Test batch Action",
        ),
        author=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Andrew Svetlov",
        ),
        descr=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "description of test action",
        ),
        inputs={
            "arg1":
            ast.Input(
                Pos(6, 4, config_file),
                Pos(7, 2, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 1"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file), None),
            ),
            "arg2":
            ast.Input(
                Pos(8, 4, config_file),
                Pos(10, 0, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 2"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file),
                                               "value 2"),
            ),
        },
        outputs=BatchActionOutputs(
            Pos(ANY, ANY, config_file),
            Pos(ANY, ANY, config_file),
            values={
                "res1":
                ast.Output(
                    Pos(ANY, ANY, config_file),
                    Pos(ANY, ANY, config_file),
                    descr=SimpleOptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "action result 1",
                    ),
                    value=OptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "${{ needs.task_1.outputs.task1 }}",
                    ),
                ),
                "res2":
                ast.Output(
                    Pos(ANY, ANY, config_file),
                    Pos(ANY, ANY, config_file),
                    descr=SimpleOptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "action result 2",
                    ),
                    value=OptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "${{ needs.task_2.outputs.task2 }}",
                    ),
                ),
            },
        ),
        cache=ast.Cache(
            Pos(19, 2, config_file),
            Pos(21, 0, config_file),
            strategy=ast.CacheStrategy.INHERIT,
            life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "30m"),
        ),
        images={
            "image_a":
            ast.Image(
                _start=Pos(23, 4, config_file),
                _end=Pos(35, 0, config_file),
                ref=StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            "image:banana"),
                context=OptStrExpr(Pos(0, 0, config_file),
                                   Pos(0, 0, config_file), "dir"),
                dockerfile=OptStrExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file),
                                      "dir/Dockerfile"),
                build_args=SequenceItemsExpr([
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            "--arg1"),
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            "val1"),
                    StrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "--arg2=val2",
                    ),
                ]),
                env=MappingItemsExpr({
                    "SECRET_ENV":
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                            "secret:key"),
                }),
                volumes=SequenceItemsExpr([
                    OptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "secret:key:/var/secret/key.txt",
                    ),
                ]),
                build_preset=OptStrExpr(Pos(0, 0, config_file),
                                        Pos(0, 0, config_file), "gpu-small"),
                force_rebuild=OptBoolExpr(Pos(0, 0, config_file),
                                          Pos(0, 0, config_file), None),
            )
        },
        tasks=[
            ast.Task(
                Pos(36, 2, config_file),
                Pos(40, 0, config_file),
                _specified_fields={"needs", "image", "cmd", "id"},
                mixins=None,
                title=OptStrExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                                None),
                image=OptStrExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), "image:banana"),
                preset=OptStrExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                                  Pos(0, 0, config_file),
                                                  None),
                entrypoint=OptStrExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
                cmd=OptBashExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "echo ::set-output name=task1::Task 1 ${{ inputs.arg1 }}",
                ),
                workdir=OptRemotePathExpr(Pos(0, 0, config_file),
                                          Pos(0, 0, config_file), None),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                           Pos(0, 0, config_file), None),
                http_port=OptIntExpr(Pos(0, 0, config_file),
                                     Pos(0, 0, config_file), None),
                http_auth=OptBoolExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
                pass_config=OptBoolExpr(Pos(0, 0, config_file),
                                        Pos(0, 0, config_file), None),
                id=OptIdExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "task_1"),
                needs={},
                strategy=None,
                cache=None,
                enable=EnableExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ success() }}",
                ),
            ),
            ast.Task(
                Pos(40, 2, config_file),
                Pos(43, 0, config_file),
                _specified_fields={"image", "cmd", "id"},
                mixins=None,
                title=OptStrExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                                None),
                image=OptStrExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), "ubuntu"),
                preset=OptStrExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                                  Pos(0, 0, config_file),
                                                  None),
                entrypoint=OptStrExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
                cmd=OptBashExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "echo ::set-output name=task2::Task 2 ${{ inputs.arg2 }}",
                ),
                workdir=OptRemotePathExpr(Pos(0, 0, config_file),
                                          Pos(0, 0, config_file), None),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                           Pos(0, 0, config_file), None),
                http_port=OptIntExpr(Pos(0, 0, config_file),
                                     Pos(0, 0, config_file), None),
                http_auth=OptBoolExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
                pass_config=OptBoolExpr(Pos(0, 0, config_file),
                                        Pos(0, 0, config_file), None),
                id=OptIdExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "task_2"),
                needs=None,
                strategy=None,
                cache=None,
                enable=EnableExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ success() }}",
                ),
            ),
        ],
    )
Exemplo n.º 5
0
def test_parse_live_action(assets: LocalPath) -> None:
    config_file = assets / "live-action.yml"
    action = parse_action(config_file)
    assert action == ast.LiveAction(
        Pos(0, 0, config_file),
        Pos(14, 0, config_file),
        kind=ast.ActionKind.LIVE,
        name=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Test live Action",
        ),
        author=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Andrew Svetlov",
        ),
        descr=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "description of test action",
        ),
        inputs={
            "arg1":
            ast.Input(
                Pos(6, 4, config_file),
                Pos(7, 2, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 1"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file), None),
            ),
            "arg2":
            ast.Input(
                Pos(8, 4, config_file),
                Pos(11, 0, config_file),
                descr=SimpleOptStrExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), "param 2"),
                default=SimpleOptPrimitiveExpr(Pos(0, 0, config_file),
                                               Pos(0, 0, config_file), 2),
                type=ast.InputType.INT,
            ),
        },
        job=ast.Job(
            Pos(12, 2, config_file),
            Pos(14, 0, config_file),
            _specified_fields={"cmd", "image"},
            mixins=None,
            name=OptStrExpr(Pos(3, 4, config_file), Pos(5, 0, config_file),
                            None),
            image=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             "ubuntu"),
            preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                              None),
            schedule_timeout=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                              Pos(0, 0, config_file), None),
            entrypoint=OptStrExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            cmd=OptBashExpr(
                Pos(0, 0, config_file),
                Pos(0, 0, config_file),
                "echo A ${{ inputs.arg1 }} B ${{ inputs.arg2 }} C",
            ),
            workdir=OptRemotePathExpr(Pos(0, 0, config_file),
                                      Pos(0, 0, config_file), None),
            env=None,
            volumes=None,
            tags=None,
            life_span=OptTimeDeltaExpr(Pos(0, 0, config_file),
                                       Pos(0, 0, config_file), None),
            title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                             None),
            detach=OptBoolExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                               None),
            browse=OptBoolExpr(Pos(0, 0, config_file), Pos(0, 0, config_file),
                               None),
            http_port=OptIntExpr(Pos(0, 0, config_file),
                                 Pos(0, 0, config_file), None),
            http_auth=OptBoolExpr(Pos(0, 0, config_file),
                                  Pos(0, 0, config_file), None),
            pass_config=OptBoolExpr(Pos(0, 0, config_file),
                                    Pos(0, 0, config_file), None),
            port_forward=None,
            multi=SimpleOptBoolExpr(Pos(0, 0, config_file),
                                    Pos(0, 0, config_file), None),
            params=None,
        ),
    )
Exemplo n.º 6
0
def test_parse_bash(assets: pathlib.Path) -> None:
    workspace = assets
    config_file = workspace / "live-bash.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(9, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        images=None,
        volumes=None,
        defaults=None,
        mixins=None,
        jobs={
            "test": ast.Job(
                Pos(3, 4, config_file),
                Pos(9, 0, config_file),
                _specified_fields={"cmd", "image"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "ubuntu"
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptBashExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    'VAR=qwerty\nif [[ $VAR == "qwerty" ]]; then\n echo yup\nfi\n',
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                port_forward=None,
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params=None,
            )
        },
    )
Exemplo n.º 7
0
def test_parse_python(assets: pathlib.Path) -> None:
    workspace = assets
    config_file = workspace / "live-python.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(7, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        images=None,
        volumes=None,
        defaults=None,
        mixins=None,
        jobs={
            "test": ast.Job(
                Pos(3, 4, config_file),
                Pos(7, 0, config_file),
                _specified_fields={"cmd", "image"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "ubuntu"
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptPythonExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "import sys\nprint(sys.argv)\n",
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                port_forward=None,
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params=None,
            )
        },
    )
Exemplo n.º 8
0
def test_parse_full_exprs(assets: pathlib.Path) -> None:
    workspace = assets
    config_file = workspace / "live-full-exprs.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(48, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Global title",
        ),
        images={
            "image_a": ast.Image(
                Pos(4, 4, config_file),
                Pos(11, 0, config_file),
                ref=StrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "image:banana"
                ),
                context=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
                dockerfile=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir/Dockerfile"
                ),
                build_args=SequenceExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ ['--arg1', 'val1', '--arg2=val2'] }}",
                    type2str,
                ),
                env=MappingExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ {'SECRET_ENV': 'secret:key' } }}",
                    type2str,
                ),
                volumes=SequenceExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ ['secret:key:/var/secret/key.txt'] }}",
                    type2str,
                ),
                build_preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "gpu-small"
                ),
                force_rebuild=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            )
        },
        volumes={
            "volume_a": ast.Volume(
                Pos(13, 4, config_file),
                Pos(17, 2, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:dir"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/dir"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
            ),
            "volume_b": ast.Volume(
                Pos(18, 4, config_file),
                Pos(20, 0, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:other"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/other"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            ),
        },
        defaults=ast.FlowDefaults(
            Pos(21, 2, config_file),
            Pos(28, 0, config_file),
            _specified_fields={
                "env",
                "volumes",
                "life_span",
                "schedule_timeout",
                "preset",
                "workdir",
                "tags",
            },
            tags=SequenceExpr(
                Pos(0, 0, config_file),
                Pos(0, 0, config_file),
                "${{ ['tag-a', 'tag-b'] }}",
                type2str,
            ),
            env=MappingExpr(
                Pos(0, 0, config_file),
                Pos(0, 0, config_file),
                "${{ {'global_a': 'val-a', 'global_b': 'val-b'} }}",
                type2str,
            ),
            volumes=SequenceExpr(
                Pos(0, 0, config_file),
                Pos(0, 0, config_file),
                "${{ ['storage:common:/mnt/common:rw'] }}",
                type2str,
            ),
            workdir=OptRemotePathExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "/global/dir"
            ),
            life_span=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "1d4h"
            ),
            preset=OptStrExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "cpu-large"
            ),
            schedule_timeout=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "24d23h22m21s"
            ),
        ),
        mixins=None,
        jobs={
            "test_a": ast.Job(
                Pos(30, 4, config_file),
                Pos(48, 0, config_file),
                _specified_fields={
                    "pass_config",
                    "image",
                    "life_span",
                    "http_port",
                    "title",
                    "cmd",
                    "schedule_timeout",
                    "tags",
                    "preset",
                    "http_auth",
                    "env",
                    "browse",
                    "workdir",
                    "name",
                    "entrypoint",
                    "port_forward",
                    "volumes",
                    "detach",
                },
                mixins=None,
                name=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "job-name"
                ),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ images.image_a.ref }}",
                ),
                preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "cpu-micro"
                ),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "1d2h3m4s"
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "bash"
                ),
                cmd=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "echo abc"
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/local/dir"
                ),
                env=MappingExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ {'local_a': 'val-1', 'local_b': 'val-2'} }}",
                    type2str,
                ),
                volumes=SequenceExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ [volumes.volume_a.ref, 'storage:dir:/var/dir:ro'] }}",
                    type2str,
                ),
                tags=SequenceExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ ['tag-1', 'tag-2'] }}",
                    type2str,
                ),
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "2h55m"
                ),
                title=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "Job title"
                ),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), 8080
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), False
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                port_forward=SequenceExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    '${{ ["2211:22"] }}',
                    port_pair_item,
                ),
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params=None,
            )
        },
    )
Exemplo n.º 9
0
def test_parse_full(assets: pathlib.Path) -> None:
    workspace = assets
    config_file = workspace / "live-full.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(69, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "Global title",
        ),
        images={
            "image_a": ast.Image(
                Pos(4, 4, config_file),
                Pos(16, 0, config_file),
                ref=StrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "image:banana"
                ),
                context=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
                dockerfile=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir/Dockerfile"
                ),
                build_args=SequenceItemsExpr(
                    [
                        StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "--arg1"
                        ),
                        StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "val1"),
                        StrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "--arg2=val2",
                        ),
                    ]
                ),
                env=MappingItemsExpr(
                    {
                        "SECRET_ENV": StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "secret:key"
                        ),
                    }
                ),
                volumes=SequenceItemsExpr(
                    [
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "secret:key:/var/secret/key.txt",
                        ),
                    ]
                ),
                build_preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "gpu-small"
                ),
                force_rebuild=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            )
        },
        volumes={
            "volume_a": ast.Volume(
                Pos(18, 4, config_file),
                Pos(22, 2, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:dir"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/dir"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
            ),
            "volume_b": ast.Volume(
                Pos(23, 4, config_file),
                Pos(25, 0, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:other"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/other"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            ),
        },
        defaults=ast.FlowDefaults(
            Pos(26, 2, config_file),
            Pos(36, 0, config_file),
            _specified_fields={
                "env",
                "volumes",
                "life_span",
                "schedule_timeout",
                "preset",
                "workdir",
                "tags",
            },
            tags=SequenceItemsExpr(
                [
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-a"),
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-b"),
                ]
            ),
            env=MappingItemsExpr(
                {
                    "global_a": StrExpr(
                        Pos(0, 0, config_file), Pos(0, 0, config_file), "val-a"
                    ),
                    "global_b": StrExpr(
                        Pos(0, 0, config_file), Pos(0, 0, config_file), "val-b"
                    ),
                }
            ),
            volumes=SequenceItemsExpr(
                [
                    OptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "storage:common:/mnt/common:rw",
                    ),
                ]
            ),
            workdir=OptRemotePathExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "/global/dir"
            ),
            life_span=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "1d4h"
            ),
            preset=OptStrExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "cpu-large"
            ),
            schedule_timeout=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "24d23h22m21s"
            ),
        ),
        mixins={
            "envs": ast.JobMixin(
                Pos(38, 4, config_file),
                Pos(41, 0, config_file),
                _specified_fields={"env"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    None,
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=MappingItemsExpr(
                    {
                        "local_b": StrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "val-mixin-2",
                        ),
                        "local_c": StrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "val-mixin-3",
                        ),
                    }
                ),
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                port_forward=None,
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params=None,
            )
        },
        jobs={
            "test_a": ast.Job(
                Pos(43, 4, config_file),
                Pos(69, 0, config_file),
                _specified_fields={
                    "workdir",
                    "http_auth",
                    "preset",
                    "port_forward",
                    "life_span",
                    "title",
                    "http_port",
                    "cmd",
                    "schedule_timeout",
                    "env",
                    "pass_config",
                    "detach",
                    "name",
                    "tags",
                    "image",
                    "mixins",
                    "browse",
                    "volumes",
                    "entrypoint",
                },
                mixins=[
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "envs")
                ],
                name=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "job-name"
                ),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "${{ images.image_a.ref }}",
                ),
                preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "cpu-micro"
                ),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "1d2h3m4s"
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "bash"
                ),
                cmd=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "echo abc"
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/local/dir"
                ),
                env=MappingItemsExpr(
                    {
                        "local_a": StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "val-1"
                        ),
                        "local_b": StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "val-2"
                        ),
                    }
                ),
                volumes=SequenceItemsExpr(
                    [
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "${{ volumes.volume_a.ref }}",
                        ),
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "storage:dir:/var/dir:ro",
                        ),
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "",
                        ),
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            None,
                        ),
                    ]
                ),
                tags=SequenceItemsExpr(
                    [
                        StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-1"
                        ),
                        StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-2"
                        ),
                    ]
                ),
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "2h55m"
                ),
                title=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "Job title"
                ),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), 8080
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), False
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                port_forward=SequenceItemsExpr(
                    [
                        PortPairExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "2211:22"
                        )
                    ]
                ),
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params=None,
            )
        },
    )
Exemplo n.º 10
0
def test_parse_params(assets: pathlib.Path) -> None:
    workspace = assets
    config_file = workspace / "live-params.yml"
    flow = parse_live(workspace, config_file)
    assert flow == ast.LiveFlow(
        Pos(0, 0, config_file),
        Pos(11, 0, config_file),
        id=SimpleOptIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        kind=ast.FlowKind.LIVE,
        title=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            None,
        ),
        images=None,
        volumes=None,
        defaults=None,
        mixins=None,
        jobs={
            "test": ast.Job(
                Pos(3, 4, config_file),
                Pos(11, 0, config_file),
                _specified_fields={"cmd", "image", "params"},
                mixins=None,
                name=OptStrExpr(Pos(3, 4, config_file), Pos(5, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "ubuntu"
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptBashExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "echo ${{ params.arg1 }} ${{ params.arg2 }} ${{ params.arg3 }}",
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                detach=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                browse=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                port_forward=None,
                multi=SimpleOptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                params={
                    "arg1": ast.Param(
                        _start=Pos(4, 12, config_file),
                        _end=Pos(4, 16, config_file),
                        default=OptStrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "val1"
                        ),
                        descr=OptStrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), None
                        ),
                    ),
                    "arg2": ast.Param(
                        _start=Pos(6, 8, config_file),
                        _end=Pos(8, 6, config_file),
                        default=OptStrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "val2"
                        ),
                        descr=OptStrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "Second arg"
                        ),
                    ),
                    "arg3": ast.Param(
                        _start=Pos(8, 12, config_file),
                        _end=Pos(8, 31, config_file),
                        default=OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "${{ flow.flow_id }}",
                        ),
                        descr=OptStrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), None
                        ),
                    ),
                },
            )
        },
    )
Exemplo n.º 11
0
def test_parse_full(assets: pathlib.Path) -> None:
    config_file = assets / "with_project_yaml" / "project.yml"
    with config_file.open() as stream:
        project = parse_project_stream(stream)
    assert project == ast.Project(
        Pos(0, 0, config_file),
        Pos(58, 0, config_file),
        id=SimpleIdExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "test_project",
        ),
        owner=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "test-owner",
        ),
        role=SimpleOptStrExpr(
            Pos(0, 0, config_file),
            Pos(0, 0, config_file),
            "test-owner/roles/test-role",
        ),
        images={
            "image_a": ast.Image(
                Pos(5, 4, config_file),
                Pos(17, 0, config_file),
                ref=StrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "image:banana"
                ),
                context=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
                dockerfile=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir/Dockerfile"
                ),
                build_args=SequenceItemsExpr(
                    [
                        StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "--arg1"
                        ),
                        StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "val1"),
                        StrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "--arg2=val2",
                        ),
                    ]
                ),
                env=MappingItemsExpr(
                    {
                        "SECRET_ENV": StrExpr(
                            Pos(0, 0, config_file), Pos(0, 0, config_file), "secret:key"
                        ),
                    }
                ),
                volumes=SequenceItemsExpr(
                    [
                        OptStrExpr(
                            Pos(0, 0, config_file),
                            Pos(0, 0, config_file),
                            "secret:key:/var/secret/key.txt",
                        ),
                    ]
                ),
                build_preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "gpu-small"
                ),
                force_rebuild=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            )
        },
        volumes={
            "volume_a": ast.Volume(
                Pos(19, 4, config_file),
                Pos(23, 2, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:dir"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/dir"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), True
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "dir"
                ),
            ),
            "volume_b": ast.Volume(
                Pos(24, 4, config_file),
                Pos(26, 0, config_file),
                remote=URIExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "storage:other"
                ),
                mount=RemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "/var/other"
                ),
                read_only=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                local=OptLocalPathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            ),
        },
        defaults=ast.BatchFlowDefaults(
            Pos(27, 2, config_file),
            Pos(42, 0, config_file),
            _specified_fields={
                "fail_fast",
                "tags",
                "cache",
                "env",
                "volumes",
                "life_span",
                "schedule_timeout",
                "workdir",
                "max_parallel",
                "preset",
            },
            tags=SequenceItemsExpr(
                [
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-a"),
                    StrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), "tag-b"),
                ]
            ),
            env=MappingItemsExpr(
                {
                    "global_a": StrExpr(
                        Pos(0, 0, config_file), Pos(0, 0, config_file), "val-a"
                    ),
                    "global_b": StrExpr(
                        Pos(0, 0, config_file), Pos(0, 0, config_file), "val-b"
                    ),
                }
            ),
            volumes=SequenceItemsExpr(
                [
                    OptStrExpr(
                        Pos(0, 0, config_file),
                        Pos(0, 0, config_file),
                        "storage:common:/mnt/common:rw",
                    ),
                ]
            ),
            workdir=OptRemotePathExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "/global/dir"
            ),
            life_span=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "1d4h"
            ),
            preset=OptStrExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "cpu-large"
            ),
            schedule_timeout=OptTimeDeltaExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), "24d23h22m21s"
            ),
            cache=ast.Cache(
                Pos(40, 4, config_file),
                Pos(42, 0, config_file),
                strategy=ast.CacheStrategy.NONE,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "2h30m"
                ),
            ),
            fail_fast=OptBoolExpr(
                Pos(0, 0, config_file), Pos(0, 0, config_file), False
            ),
            max_parallel=OptIntExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), 20),
        ),
        mixins={
            "basic": ast.ExecUnitMixin(
                Pos(44, 4, config_file),
                Pos(46, 2, config_file),
                _specified_fields={"image", "preset"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "mixin-image",
                ),
                preset=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), "mixin-preset"
                ),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
            ),
            "with_cmd": ast.ExecUnitMixin(
                Pos(47, 4, config_file),
                Pos(49, 2, config_file),
                _specified_fields={"image", "cmd"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "mixin-image",
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "command -o --option arg1 arg2",
                ),
            ),
            "with_bash": ast.ExecUnitMixin(
                Pos(50, 4, config_file),
                Pos(54, 2, config_file),
                _specified_fields={"image", "cmd"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "mixin-image",
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptBashExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "command -o --option arg1 arg2\ncommand2 -o --option arg1 arg2\n",
                ),
            ),
            "with_python": ast.ExecUnitMixin(
                Pos(55, 4, config_file),
                Pos(58, 0, config_file),
                _specified_fields={"image", "cmd"},
                mixins=None,
                name=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                image=OptStrExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    "mixin-image",
                ),
                preset=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                schedule_timeout=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                entrypoint=OptStrExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                workdir=OptRemotePathExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                env=None,
                volumes=None,
                tags=None,
                life_span=OptTimeDeltaExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                title=OptStrExpr(Pos(0, 0, config_file), Pos(0, 0, config_file), None),
                http_port=OptIntExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                http_auth=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                pass_config=OptBoolExpr(
                    Pos(0, 0, config_file), Pos(0, 0, config_file), None
                ),
                cmd=OptPythonExpr(
                    Pos(0, 0, config_file),
                    Pos(0, 0, config_file),
                    'print("hello neuro-flow")\n',
                ),
            ),
        },
    )
Exemplo n.º 12
0
 def _make_opt_str_expr(res: Optional[str]) -> SimpleOptStrExpr:
     return SimpleOptStrExpr(Pos(0, 0, LocalPath("fake")),
                             Pos(0, 0, LocalPath("fake")), res)