Example #1
0
def test_multiline_search_is_found(tmpdir):
    tmpdir.chdir()

    tmpdir.join("the_alphabet.txt").write(
        dedent("""
      A
      B
      C
    """))

    tmpdir.join(".bumpv.cfg").write(
        dedent("""
    [bumpv]
    current_version = 9.8.7

    [bumpv:file:the_alphabet.txt]
    search =
      A
      B
      C
    replace =
      A
      B
      C
      {new_version}
      """).strip())

    main(['major'])

    assert dedent("""
      A
      B
      C
      10.0.0
    """) == tmpdir.join("the_alphabet.txt").read()
Example #2
0
def test_commit_and_tag_with_configfile(tmpdir, vcs):
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write("""[bumpversion]\ncommit = True\ntag = True""")

    check_call([vcs, "init"])
    tmpdir.join("VERSION").write("48.1.1")
    check_call([vcs, "add", "VERSION"])
    check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--current-version', '48.1.1', '--no-tag', 'VERSION'])

    assert '48.1.2' == tmpdir.join("VERSION").read()

    log = check_output([vcs, "log", "-p"]).decode("utf-8")

    assert '-48.1.1' in log
    assert '+48.1.2' in log
    assert 'Bump version: 48.1.1 → 48.1.2' in log

    tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v48.1.2' not in tag_out

    main(['patch', '--current-version', '48.1.2', 'VERSION'])

    assert '48.1.3' == tmpdir.join("VERSION").read()

    log = check_output([vcs, "log", "-p"])

    tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v48.1.3' in tag_out
Example #3
0
def test_multi_file_configuration(tmpdir, capsys):
    tmpdir.join("FULL_VERSION.txt").write("1.0.3")
    tmpdir.join("MAJOR_VERSION.txt").write("1")

    tmpdir.chdir()

    tmpdir.join(".bumpv.cfg").write(
        dedent("""
        [bumpv]
        current_version = 1.0.3

        [bumpv:file:FULL_VERSION.txt]

        [bumpv:file:MAJOR_VERSION.txt]
        serialize = {major}
        parse = \d+

        """))

    main(['major', '--verbose'])
    assert '2.0.0' in tmpdir.join("FULL_VERSION.txt").read()
    assert '2' in tmpdir.join("MAJOR_VERSION.txt").read()

    main(['patch'])
    assert '2.0.1' in tmpdir.join("FULL_VERSION.txt").read()
    assert '2' in tmpdir.join("MAJOR_VERSION.txt").read()
Example #4
0
def test_multiline_search_is_found(tmpdir):

    tmpdir.chdir()

    tmpdir.join("the_alphabet.txt").write(dedent("""
      A
      B
      C
    """))

    tmpdir.join(".bumpversion.cfg").write(dedent("""
    [bumpversion]
    current_version = 9.8.7

    [bumpversion:file:the_alphabet.txt]
    search =
      A
      B
      C
    replace =
      A
      B
      C
      {new_version}
      """).strip())

    main(['major'])

    assert dedent("""
      A
      B
      C
      10.0.0
    """) == tmpdir.join("the_alphabet.txt").read()
Example #5
0
def test_simple_replacement(tmpdir):
    tmpdir.join("VERSION").write("1.2.0")
    tmpdir.chdir()
    main(
        shlex_split(
            "patch --current-version 1.2.0 --new-version 1.2.1 VERSION"))
    assert "1.2.1" == tmpdir.join("VERSION").read()
Example #6
0
def test_commit_and_tag_with_configfile(tmpdir, vcs):
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write("""[bumpversion]\ncommit = True\ntag = True""")

    subprocess.check_call([vcs, "init"])
    tmpdir.join("VERSION").write("48.1.1")
    subprocess.check_call([vcs, "add", "VERSION"])
    subprocess.check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--current-version', '48.1.1', '--no-tag', 'VERSION'])

    assert '48.1.2' == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"]).decode("utf-8")

    assert '-48.1.1' in log
    assert '+48.1.2' in log
    assert 'Bump version: 48.1.1 → 48.1.2' in log

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v48.1.2' not in tag_out

    main(['patch', '--current-version', '48.1.2', 'VERSION'])

    assert '48.1.3' == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"])

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v48.1.3' in tag_out
Example #7
0
def test_multi_file_configuration(tmpdir, capsys):
    tmpdir.join("FULL_VERSION.txt").write("1.0.3")
    tmpdir.join("MAJOR_VERSION.txt").write("1")

    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write(dedent("""
        [bumpversion]
        current_version = 1.0.3

        [bumpversion:file:FULL_VERSION.txt]

        [bumpversion:file:MAJOR_VERSION.txt]
        serialize = {major}
        parse = \d+

        """))

    main(['major', '--verbose'])
    assert '2.0.0' in tmpdir.join("FULL_VERSION.txt").read()
    assert '2' in tmpdir.join("MAJOR_VERSION.txt").read()

    main(['patch'])
    assert '2.0.1' in tmpdir.join("FULL_VERSION.txt").read()
    assert '2' in tmpdir.join("MAJOR_VERSION.txt").read()
Example #8
0
def test_bump_version(tmpdir):

    tmpdir.join("file5").write("1.0.0")
    tmpdir.chdir()
    main(["patch", "--current-version", "1.0.0", "file5"])

    assert "1.0.1" == tmpdir.join("file5").read()
Example #9
0
def test_commit_and_tag(tmpdir, vcs):
    tmpdir.chdir()
    subprocess.check_call([vcs, "init"])
    tmpdir.join("VERSION").write("47.1.1")
    subprocess.check_call([vcs, "add", "VERSION"])
    subprocess.check_call([vcs, "commit", "-m", "initial commit"])

    main(["patch", "--current-version", "47.1.1", "--commit", "VERSION"])

    assert "47.1.2" == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"]).decode("utf-8")

    assert "-47.1.1" in log
    assert "+47.1.2" in log
    assert "Bump version: 47.1.1 → 47.1.2" in log

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b"v47.1.2" not in tag_out

    main(["patch", "--current-version", "47.1.2", "--commit", "--tag", "VERSION"])

    assert "47.1.3" == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"])

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b"v47.1.3" in tag_out
Example #10
0
def test_optional_value_from_documentation(tmpdir):

    tmpdir.join("optional_value_fromdoc.txt").write("1.alpha")
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write(dedent("""
      [bumpversion]
      current_version = 1.alpha
      parse = (?P<num>\d+)\.(?P<release>.*)
      serialize =
        {num}.{release}
        {num}
  
      [bumpversion:part:release]
      optional_value = gamma
      values =
        alpha
        beta
        gamma

      [bumpversion:file:optional_value_fromdoc.txt]
      """).strip())

    main(['release', '--verbose'])

    assert '1.beta' == tmpdir.join("optional_value_fromdoc.txt").read()

    main(['release', '--verbose'])

    assert '1' == tmpdir.join("optional_value_fromdoc.txt").read()
Example #11
0
def test_nonexisting_file(tmpdir):
    tmpdir.chdir()
    with pytest.raises(IOError):
        main(
            shlex_split(
                "patch --current-version 1.2.0 --new-version 1.2.1 doesnotexist.txt"
            ))
Example #12
0
def test_log_parse_doesnt_parse_current_version(tmpdir):
    tmpdir.chdir()

    with mock.patch("bumpversion.logger") as logger:
        main(['--parse', 'xxx', '--current-version', '12', '--new-version', '13', 'patch'])

    actual_log ="\n".join(_mock_calls_to_string(logger)[4:])

    EXPECTED_LOG = dedent("""
        info|Could not read config file at .bumpversion.cfg|
        info|Parsing current version '12' with 'xxx'|
        warn|Evaluating 'parse' option: 'xxx' does not parse current version '12'|
        info|Attempting to increment part 'patch'|
        info|Values are now: |
        info|Available serialization formats: '{major}.{minor}.{patch}'|
        info|Did not find key 'major' in {} when serializing version number|
        info|Opportunistic finding of new_version failed|
        info|New version will be '13'|
        info|Asserting files  contain string '12':|
        info|Would write to config file .bumpversion.cfg:|
        info|[bumpversion]
        current_version = 13

        |
    """).strip()

    assert actual_log == EXPECTED_LOG
Example #13
0
def test_git_commit(tmpdir):
    tmpdir.chdir()
    subprocess.check_call(["git", "init"])
    tmpdir.join("VERSION").write("47.1.1")
    subprocess.check_call(["git", "add", "VERSION"])
    subprocess.check_call(["git", "commit", "-m", "initial commit"])

    main(['--current-version', '47.1.1', '--commit', 'VERSION'])

    assert '47.1.2' == tmpdir.join("VERSION").read()

    log = subprocess.check_output(["git", "log", "--decorate=full", "-p"])

    assert '-47.1.1' in log
    assert '+47.1.2' in log
    assert u'Bump version: 47.1.1 → 47.1.2' in log.decode("utf-8")

    tag_out = subprocess.check_output(["git", "tag"])

    assert 'v47.1.2' not in tag_out

    main(['--current-version', '47.1.2', '--commit', '--tag', 'VERSION'])

    assert '47.1.3' == tmpdir.join("VERSION").read()

    log = subprocess.check_output(["git", "log", "--decorate=full", "-p"])

    tag_out = subprocess.check_output(["git", "tag"])

    assert 'v47.1.3' in tag_out
Example #14
0
def test_distance_to_latest_tag_as_part_of_new_version(tmpdir):
    # prepare
    tmpdir.join("mysourcefile").write("19.6.0")
    tmpdir.chdir()

    subprocess.check_call(["git", "init"])
    subprocess.check_call(["git", "add", "mysourcefile"])
    subprocess.check_call(["git", "commit", "-m", "initial"])
    subprocess.check_call(["git", "tag", "v19.6.0"])
    subprocess.check_call(
        ["git", "commit", "--allow-empty", "-m", "Just a commit 1"])
    subprocess.check_call(
        ["git", "commit", "--allow-empty", "-m", "Just a commit 2"])
    subprocess.check_call(
        ["git", "commit", "--allow-empty", "-m", "Just a commit 3"])

    # don't give current-version, that should come from tag
    main([
        'patch',
        '--parse',
        '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*',
        '--serialize',
        '{major}.{minor}.{patch}-pre{distance_to_latest_tag}',
        'mysourcefile',
    ])

    assert '19.6.1-pre3' == tmpdir.join("mysourcefile").read()
Example #15
0
def test_optional_value_from_documentation(tmpdir):
    tmpdir.join("optional_value_fromdoc.txt").write("1.alpha")
    tmpdir.chdir()

    tmpdir.join(".bumpv.cfg").write(
        dedent("""
      [bumpv]
      current_version = 1.alpha
      parse = (?P<num>\d+)(\.(?P<release>.*))?(\.)?
      serialize =
        {num}.{release}
        {num}

      [bumpv:part:release]
      optional_value = gamma
      values =
        alpha
        beta
        gamma

      [bumpv:file:optional_value_fromdoc.txt]
      """).strip())

    main(['release', '--verbose'])

    assert '1.beta' == tmpdir.join("optional_value_fromdoc.txt").read()

    main(['release', '--verbose'])

    assert '1' == tmpdir.join("optional_value_fromdoc.txt").read()
Example #16
0
def test_distance_to_latest_tag_as_part_of_new_version(tmpdir):
    # prepare
    tmpdir.join("mysourcefile").write("19.6.0")
    tmpdir.chdir()

    subprocess.check_call(["git", "init"])
    subprocess.check_call(["git", "add", "mysourcefile"])
    subprocess.check_call(["git", "commit", "-m", "initial"])
    subprocess.check_call(["git", "tag", "v19.6.0"])
    subprocess.check_call(["git", "commit", "--allow-empty", "-m", "Just a commit 1"])
    subprocess.check_call(["git", "commit", "--allow-empty", "-m", "Just a commit 2"])
    subprocess.check_call(["git", "commit", "--allow-empty", "-m", "Just a commit 3"])

    # don't give current-version, that should come from tag
    main(
        [
            "patch",
            "--parse",
            "(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+).*",
            "--serialize",
            "{major}.{minor}.{patch}-pre{distance_to_latest_tag}",
            "mysourcefile",
        ]
    )

    assert "19.6.1-pre3" == tmpdir.join("mysourcefile").read()
Example #17
0
def test_message_from_config_file(tmpdir, capsys, vcs):
    tmpdir.chdir()
    subprocess.check_call([vcs, "init"])
    tmpdir.join("VERSION").write("400.0.0")
    subprocess.check_call([vcs, "add", "VERSION"])
    subprocess.check_call([vcs, "commit", "-m", "initial commit"])

    tmpdir.join(".bumpversion.cfg").write(
        """[bumpversion]
current_version: 400.0.0
new_version: 401.0.0
commit: True
tag: True
message: {current_version} was old, {new_version} is new
tag_name: from-{current_version}-to-{new_version}"""
    )

    main(["major", "VERSION"])

    log = subprocess.check_output([vcs, "log", "-p"])

    assert b"400.0.0 was old, 401.0.0 is new" in log

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b"from-400.0.0-to-401.0.0" in tag_out
Example #18
0
def test_log_no_config_file_info_message(tmpdir, capsys):
    tmpdir.chdir()

    tmpdir.join("blargh.txt").write("1.0.0")

    with mock.patch("bumpversion.logger") as logger:
        main(['--verbose', '--verbose', '--current-version', '1.0.0', 'patch', 'blargh.txt'])

    actual_log ="\n".join(_mock_calls_to_string(logger)[4:])

    EXPECTED_LOG = dedent("""
        info|Could not read config file at .bumpversion.cfg|
        info|Parsing version '1.0.0' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'|
        info|Parsed the following values: major=1, minor=0, patch=0|
        info|Attempting to increment part 'patch'|
        info|Values are now: major=1, minor=0, patch=1|
        info|New version will be '1.0.1'|
        info|Asserting files blargh.txt contain the version string:|
        info|Found '1.0.0' in blargh.txt at line 0: 1.0.0|
        info|Changing file blargh.txt:|
        info|--- a/blargh.txt
        +++ b/blargh.txt
        @@ -1 +1 @@
        -1.0.0
        +1.0.1|
        info|Would write to config file .bumpversion.cfg:|
        info|[bumpversion]
        current_version = 1.0.1

        |
    """).strip()

    assert actual_log == EXPECTED_LOG
Example #19
0
def test_commit_and_tag(tmpdir, vcs):
    tmpdir.chdir()
    subprocess.check_call([vcs, "init"])
    tmpdir.join("VERSION").write("47.1.1")
    subprocess.check_call([vcs, "add", "VERSION"])
    subprocess.check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--current-version', '47.1.1', '--commit', 'VERSION'])

    assert '47.1.2' == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"]).decode("utf-8")

    assert '-47.1.1' in log
    assert '+47.1.2' in log
    assert 'Bump version: 47.1.1 → 47.1.2' in log

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v47.1.2' not in tag_out

    main(['patch', '--current-version', '47.1.2', '--commit', '--tag', 'VERSION'])

    assert '47.1.3' == tmpdir.join("VERSION").read()

    log = subprocess.check_output([vcs, "log", "-p"])

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v47.1.3' in tag_out
Example #20
0
def test_commit_and_tag(tmpdir, vcs):
    tmpdir.chdir()
    check_call([vcs, "init"])
    tmpdir.join("VERSION").write("47.1.1")
    check_call([vcs, "add", "VERSION"])
    check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--current-version', '47.1.1', '--commit', 'VERSION'])

    assert '47.1.2' == tmpdir.join("VERSION").read()

    log = check_output([vcs, "log", "-p"]).decode("utf-8")

    assert '-47.1.1' in log
    assert '+47.1.2' in log
    assert 'Bump version: 47.1.1 → 47.1.2' in log

    tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v47.1.2' not in tag_out

    main(['patch', '--current-version', '47.1.2', '--commit', '--tag', 'VERSION'])

    assert '47.1.3' == tmpdir.join("VERSION").read()

    log = check_output([vcs, "log", "-p"])

    tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'v47.1.3' in tag_out
Example #21
0
def test_dry_run(tmpdir, vcs):
    tmpdir.chdir()

    config = """[bumpversion]
current_version = 12
new_version = 12.2
files = file4
tag = True
commit = True
message = DO NOT BUMP VERSIONS WITH THIS FILE
"""

    version = "12"

    tmpdir.join("file4").write(version)
    tmpdir.join(".bumpversion.cfg").write(config)

    check_call([vcs, "init"])
    check_call([vcs, "add", "file4"])
    check_call([vcs, "add", ".bumpversion.cfg"])
    check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--dry-run'])

    assert config == tmpdir.join(".bumpversion.cfg").read()
    assert version == tmpdir.join("file4").read()

    vcs_log = check_output([vcs, "log"]).decode('utf-8')

    assert "initial commit" in vcs_log
    assert "DO NOT" not in vcs_log
Example #22
0
def test_listing(tmpdir, vcs):
    tmpdir.join("please_list_me.txt").write("0.5.5")
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write(dedent("""
        [bumpversion]
        files = please_list_me.txt
        current_version = 0.5.5
        commit = False
        tag = False
        """))

    check_call([vcs, "init"])
    check_call([vcs, "add", "please_list_me.txt"])
    check_call([vcs, "commit", "-m", "initial commit"])

    with mock.patch("bumpversion.logger_list") as logger:
        main(['--list', 'patch'])

    EXPECTED_LOG = dedent("""
        info|files=please_list_me.txt|
        info|current_version=0.5.5|
        info|commit=False|
        info|tag=False|
        info|new_version=0.5.6|
        """).strip()

    if vcs == "hg":
        EXPECTED_LOG = EXPECTED_LOG.replace("Git", "Mercurial")

    actual_log ="\n".join(_mock_calls_to_string(logger)[3:])

    assert actual_log == EXPECTED_LOG
Example #23
0
def test_dry_run(tmpdir, vcs):
    tmpdir.chdir()

    config = """[bumpversion]
current_version = 12
new_version = 12.2
files = file4
tag = True
commit = True
message = DO NOT BUMP VERSIONS WITH THIS FILE
"""

    version = "12"

    tmpdir.join("file4").write(version)
    tmpdir.join(".bumpversion.cfg").write(config)

    check_call([vcs, "init"])
    check_call([vcs, "add", "file4"])
    check_call([vcs, "add", ".bumpversion.cfg"])
    check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--dry-run'])

    assert config == tmpdir.join(".bumpversion.cfg").read()
    assert version == tmpdir.join("file4").read()

    vcs_log = check_output([vcs, "log"]).decode('utf-8')

    assert "initial commit" in vcs_log
    assert "DO NOT" not in vcs_log
Example #24
0
def test_bump_version(tmpdir):

    tmpdir.join("file5").write("1.0.0")
    tmpdir.chdir()
    main(['patch', '--current-version', '1.0.0', 'file5'])

    assert '1.0.1' == tmpdir.join("file5").read()
Example #25
0
def test_bump_non_numeric_parts(tmpdir, capsys):
    tmpdir.join("with_prereleases.txt").write("1.5.dev")
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write(dedent("""
        [bumpversion]
        files = with_prereleases.txt
        current_version = 1.5.dev
        parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<release>[a-z]+))?
        serialize =
          {major}.{minor}.{release}
          {major}.{minor}

        [bumpversion:part:release]
        optional_value = gamma
        values =
          dev
          gamma
        """))

    main(['release', '--verbose'])

    assert '1.5' == tmpdir.join("with_prereleases.txt").read()

    main(['minor', '--verbose'])

    assert '1.6.dev' == tmpdir.join("with_prereleases.txt").read()
Example #26
0
def test_bump_version(tmpdir):

    tmpdir.join("file5").write("1.0.0")
    tmpdir.chdir()
    main(['patch', '--current-version', '1.0.0', 'file5'])

    assert '1.0.1' == tmpdir.join("file5").read()
Example #27
0
    def bumpversion(self,
                    part,
                    commit=True,
                    tag=False,
                    message=None,
                    allow_dirty=False):
        """ Run bumpversion.main() with the specified arguments, and return the
        new computed version string.
        """
        import bumpversion

        args = ((['--verbose'] if self.verbose > 1 else []) +
                (['--allow-dirty'] if allow_dirty else []) +
                (['--commit'] if commit else ['--no-commit']) +
                (['--tag'] if tag else ['--no-tag']) +
                (['--message', message] if message is not None else []) +
                ['--list', part])
        log.debug("$ bumpversion %s" %
                  " ".join(a.replace(" ", "\\ ") for a in args))

        with capture_logger("bumpversion.list") as out:
            bumpversion.main(args)

        last_line = out.getvalue().splitlines()[-1]
        new_version = last_line.replace("new_version=", "")
        return new_version
Example #28
0
def test_log_no_config_file_info_message(tmpdir, capsys):
    tmpdir.chdir()

    tmpdir.join("blargh.txt").write("1.0.0")

    with mock.patch("bumpversion.logger") as logger:
        main(['--verbose', '--verbose', '--current-version', '1.0.0', 'patch', 'blargh.txt'])

    actual_log ="\n".join(_mock_calls_to_string(logger)[4:])

    EXPECTED_LOG = dedent("""
        info|Could not read config file at .bumpversion.cfg|
        info|Parsing current version '1.0.0' with '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'|
        info|Parsed the following values: major=1, minor=0, patch=0|
        info|Attempting to increment part 'patch'|
        info|Values are now: major=1, minor=0, patch=1|
        info|Available serialization formats: '{major}.{minor}.{patch}'|
        info|Found '{major}.{minor}.{patch}' to be a usable serialization format|
        info|Selected serialization format '{major}.{minor}.{patch}'|
        info|Serialized to '1.0.1'|
        info|New version will be '1.0.1'|
        info|Asserting files blargh.txt contain string '1.0.0':|
        info|Found '1.0.0' in blargh.txt at line 0: 1.0.0|
        info|Changing file blargh.txt:|
        info|--- a/blargh.txt
        +++ b/blargh.txt
        @@ -1 +1 @@
        -1.0.0
        +1.0.1|
    """).strip()

    assert actual_log == EXPECTED_LOG
Example #29
0
def test_nonexisting_file(tmpdir):
    tmpdir.chdir()
    tmpdir.join("mysourcecode.txt").write("1.2.3")
    with pytest.raises(IOError):
        main(shlex_split("patch --current-version 1.2.3 mysourcecode.txt doesnotexist2.txt"))

    # first file is unchanged because second didn't exist
    assert '1.2.3' == tmpdir.join("mysourcecode.txt").read()
Example #30
0
def test_nonexisting_file(tmpdir):
    tmpdir.chdir()
    tmpdir.join("mysourcecode.txt").write("1.2.3")
    with pytest.raises(IOError):
        main(shlex_split("patch --current-version 1.2.3 mysourcecode.txt doesnotexist2.txt"))

    # first file is unchanged because second didn't exist
    assert '1.2.3' == tmpdir.join("mysourcecode.txt").read()
Example #31
0
def test_simple_replacement_in_utf8_file(tmpdir):
    tmpdir.join("VERSION").write("Kröt1.3.0".encode('utf-8'), 'wb')
    tmpdir.chdir()
    main(
        shlex_split(
            "patch --current-version 1.3.0 --new-version 1.3.1 VERSION"))
    out = tmpdir.join("VERSION").read('rb')
    assert "'Kr\\xc3\\xb6t1.3.1'" in repr(out)
Example #32
0
def test_dirty_workdir(tmpdir, vcs):
    tmpdir.chdir()
    subprocess.check_call([vcs, "init"])
    tmpdir.join("dirty").write("i'm dirty")

    subprocess.check_call([vcs, "add", "dirty"])

    with pytest.raises(AssertionError):
        main(['patch', '--current-version', '1', '--new-version', '2', 'file7'])
Example #33
0
def version_bump(part):
    try:
        import bumpversion
    except ImportError:
        print_failure_message(
            'Install bumpversion to use this task, '
            "i.e., `pip install --upgrade bumpversion`.")
        raise SystemExit(1)
    bumpversion.main([part, '--commit', '--tag', '--list'])
Example #34
0
def test_non_vcs_operations_if_vcs_is_not_installed(tmpdir, vcs, monkeypatch):
    monkeypatch.setenv("PATH", "")

    tmpdir.chdir()
    tmpdir.join("VERSION").write("31.0.3")

    main(['major', '--current-version', '31.0.3', 'VERSION'])

    assert '32.0.0' == tmpdir.join("VERSION").read()
Example #35
0
def test_git_dirty_workdir(tmpdir):
    tmpdir.chdir()
    subprocess.check_call(["git", "init"])
    tmpdir.join("dirty").write("i'm dirty")

    subprocess.check_call(["git", "add", "dirty"])

    with pytest.raises(AssertionError):
        main(['--current-version', '1', '--new-version', '2', 'file7'])
Example #36
0
def test_search_replace_to_avoid_updating_unconcerned_lines(tmpdir, capsys):
    tmpdir.chdir()

    tmpdir.join("requirements.txt").write("Django>=1.5.6,<1.6\nMyProject==1.5.6")

    tmpdir.join(".bumpversion.cfg").write(dedent("""
      [bumpversion]
      current_version = 1.5.6

      [bumpversion:file:requirements.txt]
      search = MyProject=={current_version}
      replace = MyProject=={new_version}
      """).strip())

    with mock.patch("bumpversion.logger") as logger:
        main(['minor', '--verbose'])

    # beware of the trailing space (" ") after "serialize =":
    EXPECTED_LOG = dedent("""
        info|Reading config file .bumpversion.cfg:|
        info|[bumpversion]
        current_version = 1.5.6

        [bumpversion:file:requirements.txt]
        search = MyProject=={current_version}
        replace = MyProject=={new_version}|
        info|Parsing version '1.5.6' using regexp '(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)'|
        info|Parsed the following values: major=1, minor=5, patch=6|
        info|Attempting to increment part 'minor'|
        info|Values are now: major=1, minor=6, patch=0|
        info|New version will be '1.6.0'|
        info|Asserting files requirements.txt contain the version string:|
        info|Found 'MyProject==1.5.6' in requirements.txt at line 1: MyProject==1.5.6|
        info|Changing file requirements.txt:|
        info|--- a/requirements.txt
        +++ b/requirements.txt
        @@ -1,2 +1,2 @@
         Django>=1.5.6,<1.6
        -MyProject==1.5.6
        +MyProject==1.6.0|
        info|Writing to config file .bumpversion.cfg:|
        info|[bumpversion]
        current_version = 1.6.0

        [bumpversion:file:requirements.txt]
        search = MyProject=={current_version}
        replace = MyProject=={new_version}

        |
        """).strip()

    actual_log ="\n".join(_mock_calls_to_string(logger)[4:])

    assert actual_log == EXPECTED_LOG

    assert 'MyProject==1.6.0' in tmpdir.join("requirements.txt").read()
    assert 'Django>=1.5.6' in tmpdir.join("requirements.txt").read()
Example #37
0
def test_search_replace_expanding_changelog(tmpdir, capsys):

    tmpdir.chdir()

    tmpdir.join("CHANGELOG.md").write(dedent("""
    My awesome software project Changelog
    =====================================

    Unreleased
    ----------

    * Some nice feature
    * Some other nice feature

    Version v8.1.1 (2014-05-28)
    ---------------------------

    * Another old nice feature

    """))
    
    config_content = dedent("""
      [bumpversion]
      current_version = 8.1.1

      [bumpversion:file:CHANGELOG.md]
      search =
        Unreleased
        ----------
      replace =
        Unreleased
        ----------
        Version v{new_version} ({now:%Y-%m-%d})
        ---------------------------
    """)

    tmpdir.join(".bumpversion.cfg").write(config_content)

    with mock.patch("bumpversion.logger") as logger:
        main(['minor', '--verbose'])

    predate = dedent('''
      Unreleased
      ----------
      Version v8.2.0 (20
      ''').strip()

    postdate = dedent('''
      )
      ---------------------------

      * Some nice feature
      * Some other nice feature
      ''').strip()

    assert predate in tmpdir.join("CHANGELOG.md").read()
    assert postdate in tmpdir.join("CHANGELOG.md").read()
Example #38
0
def test_usage_string(tmpdir, capsys):
    tmpdir.chdir()

    with pytest.raises(SystemExit):
        main(['--help'])

    out, err = capsys.readouterr()
    assert err == ""
    assert out == EXPECTED_USAGE, "Usage string changed to \n\n\n{}\n\n\n".format(out)
Example #39
0
def test_dirty_workdir(tmpdir, vcs):
    tmpdir.chdir()
    check_call([vcs, "init"])
    tmpdir.join("dirty").write("i'm dirty")

    check_call([vcs, "add", "dirty"])

    with pytest.raises(AssertionError):
        main(['patch', '--current-version', '1', '--new-version', '2', 'file7'])
Example #40
0
def test_search_replace_expanding_changelog(tmpdir, capsys):
    tmpdir.chdir()

    tmpdir.join("CHANGELOG.md").write(
        dedent("""
    My awesome software project Changelog
    =====================================

    Unreleased
    ----------

    * Some nice feature
    * Some other nice feature

    Version v8.1.1 (2014-05-28)
    ---------------------------

    * Another old nice feature

    """))

    config_content = dedent("""
      [bumpv]
      current_version = 8.1.1

      [bumpv:file:CHANGELOG.md]
      search =
        Unreleased
        ----------
      replace =
        Unreleased
        ----------
        Version v{new_version} ({now:%Y-%m-%d})
        ---------------------------
    """)

    tmpdir.join(".bumpv.cfg").write(config_content)

    with mock.patch("bumpv.bumpv.logger"):
        main(['minor', '--verbose'])

    predate = dedent('''
      Unreleased
      ----------
      Version v8.2.0 (20
      ''').strip()

    postdate = dedent('''
      )
      ---------------------------

      * Some nice feature
      * Some other nice feature
      ''').strip()

    assert predate in tmpdir.join("CHANGELOG.md").read()
    assert postdate in tmpdir.join("CHANGELOG.md").read()
Example #41
0
def test_usage_string(tmpdir, capsys):
    tmpdir.chdir()

    with pytest.raises(SystemExit):
        main(['--help'])

    out, err = capsys.readouterr()
    assert err == ""
    assert out == EXPECTED_USAGE, "Usage string changed to \n\n\n{}\n\n\n".format(out)
Example #42
0
def test_force_dirty_workdir(tmpdir, vcs):
    tmpdir.chdir()
    check_call([vcs, "init"])
    tmpdir.join("dirty2").write("i'm dirty! 1.1.1")

    check_call([vcs, "add", "dirty2"])

    main(['patch', '--allow-dirty', '--current-version', '1.1.1', 'dirty2'])

    assert "i'm dirty! 1.1.2" == tmpdir.join("dirty2").read()
Example #43
0
def test_bumpversion_serialize_only_parts(tmpdir):
    tmpdir.join("file51").write("XXX1.1.8-master+allan1")
    tmpdir.chdir()
    main([
        '--current-version', '1.1.8-master+allan1', '--parse',
        '(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<prerel>[^\+]+))?(\+(?P<meta>.*))?',
        '--serialize', 'v{major}.{minor}', 'meta', 'file51'
    ])

    assert 'XXXv1.1' == tmpdir.join("file51").read()
Example #44
0
def test_dirty_workdir(tmpdir, vcs):
    tmpdir.chdir()
    check_call([vcs, "init"])
    tmpdir.join("dirty").write("i'm dirty")

    check_call([vcs, "add", "dirty"])

    with pytest.raises(WorkingDirectoryIsDirtyException):
        main(
            ['patch', '--current-version', '1', '--new-version', '2', 'file7'])
Example #45
0
def test_bump_version_custom_parse(tmpdir):
    tmpdir.join("file6").write("XXX1;0;0")
    tmpdir.chdir()
    main([
        '--current-version', 'XXX1;0;0', '--parse',
        'XXX(?P<spam>\d+);(?P<garlg>\d+);(?P<slurp>\d+)', '--serialize',
        'XXX{spam};{garlg};{slurp}', 'garlg', 'file6'
    ])

    assert 'XXX1;1;0' == tmpdir.join("file6").read()
Example #46
0
def test_non_vcs_operations_if_vcs_is_not_installed(tmpdir, vcs, monkeypatch):

    monkeypatch.setenv("PATH", "")

    tmpdir.chdir()
    tmpdir.join("VERSION").write("31.0.3")

    main(['major', '--current-version', '31.0.3', 'VERSION'])

    assert '32.0.0' == tmpdir.join("VERSION").read()
Example #47
0
def test_complex_info_logging(tmpdir, capsys):
    tmpdir.join("fileE").write("0.4")
    tmpdir.chdir()

    tmpdir.join(".bumpversion.cfg").write(dedent("""
        [bumpversion]
        files = fileE
        current_version = 0.4
        serialize =
          {major}.{minor}.{patch}
          {major}.{minor}
        parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?
        """).strip())

    with mock.patch("bumpversion.logger") as logger:
        main(['patch'])

    # beware of the trailing space (" ") after "serialize =":
    EXPECTED_LOG = dedent("""
        info|Reading config file .bumpversion.cfg:|
        info|[bumpversion]
        files = fileE
        current_version = 0.4
        serialize =
          {major}.{minor}.{patch}
          {major}.{minor}
        parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?|
        info|Parsing version '0.4' using regexp '(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?'|
        info|Parsed the following values: major=0, minor=4, patch=0|
        info|Attempting to increment part 'patch'|
        info|Values are now: major=0, minor=4, patch=1|
        info|New version will be '0.4.1'|
        info|Asserting files fileE contain the version string:|
        info|Found '0.4' in fileE at line 0: 0.4|
        info|Changing file fileE:|
        info|--- a/fileE
        +++ b/fileE
        @@ -1 +1 @@
        -0.4
        +0.4.1|
        info|Writing to config file .bumpversion.cfg:|
        info|[bumpversion]
        files = fileE
        current_version = 0.4.1
        serialize = 
        	{major}.{minor}.{patch}
        	{major}.{minor}
        parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?
        
        |
        """).strip()

    actual_log ="\n".join(_mock_calls_to_string(logger)[4:])

    assert actual_log == EXPECTED_LOG
Example #48
0
def test_default_config_file(tmpdir):
    tmpdir.join("file2").write("0.10.2")
    tmpdir.join(".bumpversion.cfg").write("""[bumpversion]
current_version: 0.10.2
new_version: 0.10.3
files: file2""")

    tmpdir.chdir()
    main([])

    assert "0.10.3" == tmpdir.join("file2").read()
Example #49
0
def test_config_file(tmpdir):
    tmpdir.join("file1").write("0.9.34")
    tmpdir.join("mybumpconfig.cfg").write("""[bumpversion]
current_version: 0.9.34
new_version: 0.9.35
files: file1""")

    tmpdir.chdir()
    main(shlex_split("--config-file mybumpconfig.cfg"))

    assert "0.9.35" == tmpdir.join("file1").read()
Example #50
0
def test_missing_bumpversion_cfg(tmpdir):
    tmpdir.chdir()
    tmpdir.join('setup.py').write("""setup(
    name='bumpversion',
    version='0.10.2',
    url='https://github.com/peritus/bumpversion',
    author='Filip Noetzel',
)
""")
    with pytest.raises(SystemExit):
        main([])
Example #51
0
def test_bumpversion_custom_parse_semver(tmpdir):
    tmpdir.join("file15").write("XXX1.1.7-master+allan1")
    tmpdir.chdir()
    main([
        '--current-version', '1.1.7-master+allan1', '--parse',
        '(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<prerel>[^\+]+))?(\+(?P<meta>.*))?',
        '--serialize', '{major}.{minor}.{patch}-{prerel}+{meta}', 'meta',
        'file15'
    ])

    assert 'XXX1.1.7-master+allan2' == tmpdir.join("file15").read()
Example #52
0
def test_multiple_serialize_twopart_patch(tmpdir):
    tmpdir.join("fileC").write("0.7")
    tmpdir.chdir()
    main([
        '--current-version', '0.7', '--parse',
        '(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?', '--serialize',
        '{major}.{minor}.{patch}', '--serialize', '{major}.{minor}', 'patch',
        'fileC'
    ])

    assert '0.7.1' == tmpdir.join("fileC").read()
Example #53
0
def test_config_file(tmpdir):
    tmpdir.join("file1").write("0.9.34")
    tmpdir.join("mybumpconfig.cfg").write("""[bumpversion]
current_version: 0.9.34
new_version: 0.9.35
files: file1""")

    tmpdir.chdir()
    main(shlex_split("patch --config-file mybumpconfig.cfg"))

    assert "0.9.35" == tmpdir.join("file1").read()
Example #54
0
def test_default_config_file(tmpdir):
    tmpdir.join("file2").write("0.10.2")
    tmpdir.join(".bumpversion.cfg").write("""[bumpversion]
current_version: 0.10.2
new_version: 0.10.3
files: file2""")

    tmpdir.chdir()
    main(['patch'])

    assert "0.10.3" == tmpdir.join("file2").read()
Example #55
0
def test_search_replace_cli(tmpdir, capsys):
    tmpdir.join("file89").write("My birthday: 3.5.98\nCurrent version: 3.5.98")
    tmpdir.chdir()
    main([
         '--current-version', '3.5.98',
         '--search', 'Current version: {current_version}',
         '--replace', 'Current version: {new_version}',
         'minor',
         'file89',
         ])

    assert 'My birthday: 3.5.98\nCurrent version: 3.6.0' == tmpdir.join("file89").read()
Example #56
0
def test_tag_name(tmpdir, vcs):
    tmpdir.chdir()
    subprocess.check_call([vcs, "init"])
    tmpdir.join("VERSION").write("31.1.1")
    subprocess.check_call([vcs, "add", "VERSION"])
    subprocess.check_call([vcs, "commit", "-m", "initial commit"])

    main(['patch', '--current-version', '31.1.1', '--commit', '--tag', 'VERSION', '--tag-name', 'ReleasedVersion-{new_version}'])

    tag_out = subprocess.check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]])

    assert b'ReleasedVersion-31.1.2' in tag_out
Example #57
0
def test_bumpversion_serialize_only_parts(tmpdir):
    tmpdir.join("file51").write("XXX1.1.8-master+allan1")
    tmpdir.chdir()
    main([
         '--current-version', '1.1.8-master+allan1',
         '--parse', '(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<prerel>[^\+]+))?(\+(?P<meta>.*))?',
         '--serialize', 'v{major}.{minor}',
         'meta',
         'file51'
         ])

    assert 'XXXv1.1' == tmpdir.join("file51").read()
Example #58
0
def test_bumpversion_custom_parse_semver(tmpdir):
    tmpdir.join("file15").write("XXX1.1.7-master+allan1")
    tmpdir.chdir()
    main([
         '--current-version', '1.1.7-master+allan1',
         '--parse', '(?P<major>\d+).(?P<minor>\d+).(?P<patch>\d+)(-(?P<prerel>[^\+]+))?(\+(?P<meta>.*))?',
         '--serialize', '{major}.{minor}.{patch}-{prerel}+{meta}',
         'meta',
         'file15'
         ])

    assert 'XXX1.1.7-master+allan2' == tmpdir.join("file15").read()