Example #1
0
def files_not_bumped(test_repo: Path) -> bool:
    toml_path = test_repo / "pyproject.toml"
    new_toml = tomlkit.loads(toml_path.text())
    assert new_toml["tool"]["tbump"]["version"]["current"] == "1.2.41-alpha-1"

    return all(
        (
            file_contains(test_repo / "package.json", '"version": "1.2.41-alpha-1"'),
            file_contains(test_repo / "package.json", '"other-dep": "1.2.41-alpha-1"'),
            file_contains(test_repo / "pub.js", "PUBLIC_VERSION = '1.2.41'"),
        )
    )
def test_file_bumper_simple(test_repo: Path) -> None:
    bumper = tbump.file_bumper.FileBumper(test_repo)
    config_file = tbump.config.get_config_file(test_repo)
    assert bumper.working_path == test_repo
    bumper.set_config_file(config_file)
    patches = bumper.get_patches(new_version="1.2.41-alpha-2")
    for patch in patches:
        patch.apply()

    assert file_contains(test_repo / "package.json",
                         '"version": "1.2.41-alpha-2"')
    assert file_contains(test_repo / "package.json",
                         '"other-dep": "1.2.41-alpha-1"')
    assert file_contains(test_repo / "pub.js", "PUBLIC_VERSION = '1.2.41'")
    assert file_contains(test_repo / "glob-one.c",
                         'version_one = "1.2.41-alpha-2"')
    assert file_contains(test_repo / "glob-two.v",
                         'version_two = "1.2.41-alpha-2"')
def test_changing_same_file_twice(tmp_path: Path) -> None:
    tbump_path = tmp_path / "tbump.toml"
    tbump_path.write_text(r"""
        [version]
        current = "1.2.3"
        regex = '''
            (?P<major>\d+)
            \.
            (?P<minor>\d+)
            (
              \.
              (?P<patch>\d+)
            )?
        '''

        [git]
        message_template = "Bump to {new_version}"
        tag_template = "v{new_version}"

        [[file]]
        src = "foo.c"
        version_template = "{major}.{minor}"
        search = "PUBLIC_VERSION"

        [[file]]
        src = "foo.c"
        search = "FULL_VERSION"

        """)

    foo_c = tmp_path / "foo.c"
    foo_c.write_text("""
        #define FULL_VERSION "1.2.3"
        #define PUBLIC_VERSION "1.2"
        """)
    bumper = tbump.file_bumper.FileBumper(tmp_path)
    config_file = tbump.config.get_config_file(tmp_path)
    bumper.set_config_file(config_file)
    patches = bumper.get_patches(new_version="1.3.0")
    for patch in patches:
        patch.do()

    assert file_contains(tmp_path / foo_c, '#define FULL_VERSION "1.3.0"')
    assert file_contains(tmp_path / foo_c, '#define PUBLIC_VERSION "1.3"')
def files_bumped(test_repo: Path, using_pyproject: bool = False) -> bool:
    if using_pyproject:
        cfg_path = test_repo / "pyproject.toml"
        new_toml = tomlkit.loads(cfg_path.read_text())
        current_version = new_toml["tool"]["tbump"]["version"]["current"]
    else:
        cfg_path = test_repo / "tbump.toml"
        new_toml = tomlkit.loads(cfg_path.read_text())
        current_version = new_toml["version"]["current"]

    assert current_version == "1.2.41-alpha-2"

    return all((
        file_contains(test_repo / "package.json",
                      '"version": "1.2.41-alpha-2"'),
        file_contains(test_repo / "package.json",
                      '"other-dep": "1.2.41-alpha-1"'),
        file_contains(test_repo / "pub.js", "PUBLIC_VERSION = '1.2.41'"),
    ))
Example #5
0
def test_interactive_abort(test_repo: Path, mocker: Any) -> None:
    ask_mock = mocker.patch("cli_ui.ask_yes_no")
    ask_mock.return_value = False

    with pytest.raises(SystemExit):
        tbump.main.main(["-C", test_repo, "1.2.41-alpha-2"])

    ask_mock.assert_called_with("Looking good?", default=False)
    assert file_contains(test_repo / "VERSION", "1.2.41-alpha-1")
    rc, out = tbump.git.run_git_captured(test_repo, "tag", "--list")
    assert "v1.2.42-alpha-2" not in out
Example #6
0
def test_abort_if_file_does_not_match(
        test_repo: Path, message_recorder: MessageRecorder) -> None:
    invalid_src = test_repo / "foo.txt"
    invalid_src.write_text("this is foo")
    tbump_path = test_repo / "tbump.toml"
    with tbump_path.open("a") as f:
        f.write("""\
        [[file]]
        src = "foo.txt"
        """)
    tbump.git.run_git(test_repo, "add", ".")
    tbump.git.run_git(test_repo, "commit", "--message", "add foo.txt")

    with pytest.raises(SystemExit):
        tbump.main.main(["-C", str(test_repo), "1.2.42", "--non-interactive"])
    assert message_recorder.find("not found")
    assert file_contains(test_repo / "VERSION", "1.2.41-alpha-1")
Example #7
0
def test_bump_files_defaults_to_working_dir(test_repo: Path) -> None:
    with test_repo:
        tbump.bump_files("1.2.42")

    assert file_contains(test_repo / "package.json", '"version": "1.2.42"')
Example #8
0
def test_bump_files_with_repo_path(test_repo: Path) -> None:
    tbump.bump_files("1.2.42", test_repo)

    assert file_contains(test_repo / "package.json", '"version": "1.2.42"')
Example #9
0
def test_bump_files_defaults_to_working_dir(test_repo: Path,
                                            monkeypatch: Any) -> None:
    monkeypatch.chdir(test_repo)
    tbump.bump_files("1.2.42")

    assert file_contains(test_repo / "package.json", '"version": "1.2.42"')