예제 #1
0
def test_goto_print(app_layout, capfd):
    _init_vmn_in_repo()
    _init_app(app_layout.app_name, "1.2.3")

    err, ver_info, _ = _stamp_app(
        app_layout.app_name,
        release_mode="minor",
    )

    app_layout.write_file_commit_and_push("test_repo", "my.js", "some text")

    err, ver_info, _ = _stamp_app(
        app_layout.app_name,
        release_mode="major",
    )

    capfd.readouterr()

    with vmn.VMNContextMAnager(["goto", "-v", "1.3.0", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

        sout, serr = capfd.readouterr()
        assert f"[INFO] You are at version 1.3.0 of {app_layout.app_name}\n" == sout

    with vmn.VMNContextMAnager(["goto", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

        sout, serr = capfd.readouterr()
        assert (
            f"[INFO] You are at the latest version 2.0.0 of {app_layout.app_name}\n"
            == sout
        )
예제 #2
0
def test_backward_compatability_with_previous_vmn(app_layout, capfd):
    app_layout.stamp_with_previous_vmn()
    out, err = capfd.readouterr()
    err, ver_info, _ = _stamp_app("app1", "major")
    assert err == 0
    out, err = capfd.readouterr()
    assert "[INFO] 0.0.3\n" == out

    app_layout.write_file_commit_and_push("test_repo", "f1.file", "msg1")

    err, ver_info, _ = _stamp_app("app1", "patch")
    assert err == 0
    assert ver_info["stamping"]["app"]["_version"] == "0.0.4"

    with vmn.VMNContextMAnager(["goto", "-v", "0.0.2", "app1"]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    with vmn.VMNContextMAnager(["goto", "-v", "0.0.3", "app1"]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    with vmn.VMNContextMAnager(["goto", "-v", "0.0.4", "app1"]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    with vmn.VMNContextMAnager(["goto", "app1"]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    err, ver_info, _ = _stamp_app("root_app/service1", "patch")
    assert err == 0
    assert ver_info["stamping"]["app"]["_version"] == "0.0.2"
예제 #3
0
def test_rc_goto(app_layout, capfd):
    _init_vmn_in_repo()
    _init_app(app_layout.app_name, "1.2.3")

    try:
        err, ver_info, _ = _stamp_app(
            app_layout.app_name, release_mode="minor", prerelease="rc_aaa"
        )
        assert err == 0
    except AssertionError:
        pass

    err, ver_info, _ = _stamp_app(
        app_layout.app_name, release_mode="minor", prerelease="rcaaa"
    )
    assert err == 0

    data = ver_info["stamping"]["app"]
    assert data["_version"] == "1.3.0-rcaaa1"

    with vmn.VMNContextMAnager(
        ["goto", "-v", "1.3.0-rcaaa1", app_layout.app_name]
    ) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0
예제 #4
0
def _show(
    app_name,
    version=None,
    verbose=None,
    raw=None,
    root=False,
    from_file=False,
    ignore_dirty=False,
):
    args_list = ["show"]
    if verbose is not None:
        args_list.append("--verbose")
    if version is not None:
        args_list.extend(["--version", f"{version}"])
    if raw is not None:
        args_list.append("--raw")
    if root:
        args_list.append("--root")
    if from_file:
        args_list.append("--from-file")
    if ignore_dirty:
        args_list.append("--ignore-dirty")

    args_list.append(app_name)

    with vmn.VMNContextMAnager(args_list) as vmn_ctx:
        err = vmn.handle_show(vmn_ctx)
        return err
예제 #5
0
def _release_app(app_name, version):
    with vmn.VMNContextMAnager(["release", "-v", version, app_name]) as vmn_ctx:
        err = vmn.handle_release(vmn_ctx)
        assert err == 0

        ver_info = vmn_ctx.vcs.backend.get_vmn_version_info(app_name)

        try:
            # Python3.9 only
            merged_dict = vmn_ctx.params | vmn_ctx.vcs.__dict__
        except:
            merged_dict = {**(vmn_ctx.params), **(vmn_ctx.vcs.__dict__)}

        return ver_info, merged_dict
예제 #6
0
def _init_app(app_name, starting_version="0.0.0"):
    with vmn.VMNContextMAnager(
        ["init-app", "-v", starting_version, app_name]
    ) as vmn_ctx:
        err = vmn.handle_init_app(vmn_ctx)
        assert err == 0
        # TODO: why validating this?
        assert len(vmn_ctx.vcs.actual_deps_state) == 1

        ver_info = vmn_ctx.vcs.backend.get_vmn_version_info(app_name)

        try:
            # Python3.9 only
            merged_dict = vmn_ctx.params | vmn_ctx.vcs.__dict__
        except:
            merged_dict = {**(vmn_ctx.params), **(vmn_ctx.vcs.__dict__)}

        return ver_info, merged_dict
예제 #7
0
def _stamp_app(app_name, release_mode=None, prerelease=None):
    args_list = ["stamp"]
    if release_mode is not None:
        args_list.extend(["-r", release_mode])

    if prerelease is not None:
        args_list.extend(["--pr", prerelease])

    args_list.append(app_name)

    with vmn.VMNContextMAnager(args_list) as vmn_ctx:
        err = vmn.handle_stamp(vmn_ctx)
        ver_info = vmn_ctx.vcs.backend.get_vmn_version_info(app_name)

        try:
            # Python3.9 only
            merged_dict = vmn_ctx.params | vmn_ctx.vcs.__dict__
        except:
            merged_dict = {**(vmn_ctx.params), **(vmn_ctx.vcs.__dict__)}

        return err, ver_info, merged_dict
예제 #8
0
def test_goto_deleted_repos(app_layout):
    _init_vmn_in_repo()
    _init_app(app_layout.app_name)

    err, _, params = _stamp_app(app_layout.app_name, "patch")
    assert err == 0

    conf = {
        "template": "[{major}][.{minor}][.{patch}]",
        "deps": {
            "../": {
                "test_repo": {
                    "vcs_type": app_layout.be_type,
                    "remote": app_layout._app_backend.be.remote(),
                }
            }
        },
        "extra_info": False,
    }
    for repo in (("repo1", "git"), ("repo2", "git")):
        be = app_layout.create_repo(repo_name=repo[0], repo_type=repo[1])

        conf["deps"]["../"].update(
            {repo[0]: {"vcs_type": repo[1], "remote": be.be.remote()}}
        )

        be.__del__()

    app_layout.write_conf(params["app_conf_path"], **conf)

    err, _, params = _stamp_app(app_layout.app_name, "patch")
    assert err == 0

    dir_path = app_layout._repos["repo2"]["path"]
    # deleting repo_b
    shutil.rmtree(dir_path)

    with vmn.VMNContextMAnager(["goto", "-v", "0.0.2", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0
예제 #9
0
def test_basic_goto(app_layout, capfd):
    _init_vmn_in_repo()
    _init_app(app_layout.app_name, "1.2.3")

    err, ver_info, _ = _stamp_app(app_layout.app_name, "minor")
    assert err == 0

    app_layout.write_file_commit_and_push("test_repo", "a.yxy", "msg")

    err, ver_info, _ = _stamp_app(app_layout.app_name, "patch")
    assert err == 0
    data = ver_info["stamping"]["app"]
    assert data["_version"] == "1.3.1"

    c1 = app_layout._app_backend.be.changeset()
    with vmn.VMNContextMAnager(["goto", "-v", "0.0.2", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 1
    with vmn.VMNContextMAnager(["goto", "-v", "1.3.0", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    # read to clear stderr and out
    out, err = capfd.readouterr()
    assert not err

    err, _, _ = _stamp_app(app_layout.app_name, "patch")
    assert err == 0

    out, err = capfd.readouterr()
    assert "[INFO] 1.3.0\n" == out

    c2 = app_layout._app_backend.be.changeset()
    assert c1 != c2
    with vmn.VMNContextMAnager(["goto", "-v", "1.3.1", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0
    c3 = app_layout._app_backend.be.changeset()
    assert c1 == c3

    with vmn.VMNContextMAnager(["goto", app_layout.app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    c4 = app_layout._app_backend.be.changeset()
    assert c1 == c4

    root_app_name = "some_root_app/service1"
    _init_app(root_app_name, "1.2.3")

    err, ver_info, _ = _stamp_app(root_app_name, "minor")
    assert err == 0

    rc1 = app_layout._app_backend.be.changeset()

    app_layout.write_file_commit_and_push("test_repo", "a.yxy", "msg")

    err, ver_info, _ = _stamp_app(root_app_name, "minor")
    assert err == 0

    rc2 = app_layout._app_backend.be.changeset()

    assert rc1 != rc2

    with vmn.VMNContextMAnager(["goto", "-v", "1.3.0", root_app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    assert rc1 == app_layout._app_backend.be.changeset()

    with vmn.VMNContextMAnager(["goto", root_app_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    assert rc2 == app_layout._app_backend.be.changeset()

    err, ver_info, _ = _stamp_app(root_app_name, "minor")
    assert err == 0

    assert rc2 == app_layout._app_backend.be.changeset()

    app_layout.write_file_commit_and_push("test_repo", "a.yxy", "msg")

    err, ver_info, _ = _stamp_app(root_app_name, "minor")
    assert err == 0
    data = ver_info["stamping"]["app"]
    assert data["_version"] == "1.5.0"

    rc3 = app_layout._app_backend.be.changeset()

    root_name = root_app_name.split("/")[0]

    with vmn.VMNContextMAnager(["goto", "--root", "-v", "1", root_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    assert rc1 == app_layout._app_backend.be.changeset()

    with vmn.VMNContextMAnager(["goto", "--root", root_name]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    assert rc3 == app_layout._app_backend.be.changeset()

    err, ver_info, _ = _stamp_app(root_app_name, "minor")
    assert err == 0
예제 #10
0
def test_basic_show(app_layout, capfd):
    _init_vmn_in_repo()
    _init_app(app_layout.app_name)

    err, _, _ = _stamp_app(app_layout.app_name, "patch")
    assert err == 0

    # read to clear stderr and out
    out, err = capfd.readouterr()
    assert not err

    err = _show(app_layout.app_name, raw=True)
    assert err == 0

    out, err = capfd.readouterr()
    assert "0.0.1\n" == out

    err = _show(app_layout.app_name, verbose=True)
    assert err == 0

    out, err = capfd.readouterr()
    try:
        tmp = yaml.safe_load(out)
        assert "dirty" not in tmp
    except Exception:
        assert False

    app_layout.write_file_commit_and_push("test_repo", "f1.file", "msg1")

    app_layout.write_file_commit_and_push("test_repo", "f1.file", "msg1", commit=False)

    err = _show(app_layout.app_name)
    assert err == 0

    out, err = capfd.readouterr()
    assert "dirty" in out

    err = _show(app_layout.app_name, ignore_dirty=True)
    assert err == 0

    out, err = capfd.readouterr()
    assert "0.0.1\n" == out

    err = _show(app_layout.app_name, verbose=True)
    assert err == 0

    out, err = capfd.readouterr()
    try:
        tmp = yaml.safe_load(out)
        assert "modified" in tmp["dirty"]
        assert "pending" in tmp["dirty"]
        assert len(tmp["dirty"]) == 2
    except Exception:
        assert False

    app_layout.write_file_commit_and_push("test_repo", "f1.file", "msg1", push=False)
    err = _show(app_layout.app_name, verbose=True)
    assert err == 0

    out, err = capfd.readouterr()
    try:
        tmp = yaml.safe_load(out)
        assert "modified" in tmp["dirty"]
        assert "outgoing" in tmp["dirty"]
        assert len(tmp["dirty"]) == 2
    except Exception:
        assert False

    app_layout.write_file_commit_and_push("test_repo", "f1.file", "msg1")
    err = _show(app_layout.app_name, verbose=True)
    assert err == 0

    out, err = capfd.readouterr()
    try:
        tmp = yaml.safe_load(out)
        assert "modified" in tmp["dirty"]
        assert len(tmp["dirty"]) == 1
    except Exception:
        assert False

    with vmn.VMNContextMAnager(["goto", "-v", "0.0.1", "test_app"]) as vmn_ctx:
        err = vmn.handle_goto(vmn_ctx)
        assert err == 0

    capfd.readouterr()

    err = _show(app_layout.app_name, raw=True)
    assert err == 0

    out, err = capfd.readouterr()
    assert "0.0.1\n" == out
예제 #11
0
def _init_vmn_in_repo(expected_res=0):
    with vmn.VMNContextMAnager(["init"]) as vmn_ctx:
        err = vmn.handle_init(vmn_ctx)
        assert err == expected_res