Exemple #1
0
def test_v2_diff():
    version_pattern = "YYYY.BUILD[-TAG]"
    raw_pattern = '__version__ = "YYYY.BUILD[-TAG]"'
    pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)
    file_patterns = {"src/bumpver/__init__.py": [pattern]}

    old_vinfo = v2version.parse_version_info("2018.0123", version_pattern)
    new_vinfo = v2version.parse_version_info("2019.1124", version_pattern)

    diff_str = v2rewrite.diff(old_vinfo, new_vinfo, file_patterns)
    lines = diff_str.split("\n")

    assert lines[:2] == [
        "--- src/bumpver/__init__.py",
        "+++ src/bumpver/__init__.py",
    ]

    assert lines[6].startswith('-__version__ = "20')
    assert lines[7].startswith('+__version__ = "20')

    assert not lines[6].startswith('-__version__ = "2018.0123"')

    assert lines[7] == '+__version__ = "2019.1124"'

    raw_pattern = "Copyright (c) 2018-YYYY"
    pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)
    file_patterns = {'LICENSE': [pattern]}
    diff_str = v2rewrite.diff(old_vinfo, new_vinfo, file_patterns)

    lines = diff_str.split("\n")
    assert lines[3].startswith("-MIT License Copyright (c) 2018-20")
    assert lines[4].startswith("+MIT License Copyright (c) 2018-2019")
Exemple #2
0
def test_v2_iter_rewritten():
    version_pattern = "YYYY.BUILD[-TAG]"
    new_vinfo = v2version.parse_version_info("2018.0123", version_pattern)

    file_patterns = {
        "src/bumpver/__init__.py": [
            v2patterns.compile_pattern(version_pattern,
                                       '__version__ = "YYYY.BUILD[-TAG]"'),
        ]
    }

    rewritten_datas = v2rewrite.iter_rewritten(file_patterns, new_vinfo)
    rfd = list(rewritten_datas)[0]
    expected = [
        "# This file is part of the bumpver project",
        "# https://github.com/mbarkhau/bumpver",
        "#",
        "# Copyright (c) 2018-2021 Manuel Barkhau ([email protected]) - MIT License",
        "# SPDX-License-Identifier: MIT",
        '"""BumpVer: A CLI program for versioning."""',
        '',
        '__version__ = "2018.0123"',
        '',
    ]
    assert rfd.new_lines == expected
Exemple #3
0
def test_v2_format_version():
    version_pattern = "vYYYY0M.BUILD[-TAG[NUM]]"
    in_version = "v200701.0033-beta"

    vinfo = v2version.parse_version_info(in_version,
                                         raw_pattern=version_pattern)
    out_version = v2version.format_version(vinfo, raw_pattern=version_pattern)
    assert in_version == out_version

    result = v2version.format_version(vinfo, raw_pattern="v0Y.BUILD[-TAG]")
    assert result == "v07.0033-beta"

    result = v2version.format_version(vinfo, raw_pattern="vYY.BLD[-TAG]")
    assert result == "v7.33-beta"

    result = v2version.format_version(vinfo, raw_pattern="vYY.BLD-TAG")
    assert result == "v7.33-beta"

    result = v2version.format_version(
        vinfo, raw_pattern='__version__ = "YYYY.BUILD[-TAG]"')
    assert result == '__version__ = "2007.0033-beta"'

    result = v2version.format_version(vinfo,
                                      raw_pattern='__version__ = "YYYY.BLD"')
    assert result == '__version__ = "2007.33"'
Exemple #4
0
def test_v2_optional_release():
    version_pattern = "YYYY.BUILD[-TAG]"
    new_vinfo = v2version.parse_version_info("2019.0003", version_pattern)

    raw_pattern = '__version__ = "YYYY.BUILD[-TAG]"'
    pattern = v2patterns.compile_pattern(version_pattern, raw_pattern)

    old_lines = OPTIONAL_RELEASE_FIXTURE.splitlines()
    new_lines = v2rewrite.rewrite_lines([pattern], new_vinfo, old_lines)

    assert len(new_lines) == len(old_lines)
    assert "2019.0003" not in "\n".join(old_lines)
    assert "2019.0003" in "\n".join(new_lines)
    assert '__version__ = "2019.0003"' in "\n".join(new_lines)

    new_vinfo = v2version.parse_version_info("2019.0004-beta", version_pattern)
    new_lines = v2rewrite.rewrite_lines([pattern], new_vinfo, old_lines)

    # make sure optional release tag is added back on
    assert len(new_lines) == len(old_lines)
    assert "2019.0004-beta" not in "\n".join(old_lines)
    assert "2019.0004-beta" in "\n".join(new_lines)
    assert '__version__ = "2019.0004-beta"' in "\n".join(new_lines)
Exemple #5
0
def test_v1_parse_versions(pattern_str, line, expected_vinfo):
    if "{" in pattern_str:
        pattern = v1patterns.compile_pattern(pattern_str)
        version_match = pattern.regexp.search(line)
    else:
        pattern = v2patterns.compile_pattern(pattern_str)
        version_match = pattern.regexp.search(line)

    if expected_vinfo is None:
        assert version_match is None
    else:
        assert version_match is not None

        version_str = version_match.group(0)

        if "{" in pattern_str:
            version_info = v1version.parse_version_info(
                version_str, pattern_str)
            assert version_info == expected_vinfo
        else:
            version_info = v2version.parse_version_info(
                version_str, pattern_str)
            assert version_info == expected_vinfo
Exemple #6
0
def test_v2_rewrite_lines():
    version_pattern = "vYYYY0M.BUILD[-TAG]"
    new_vinfo = v2version.parse_version_info("v201811.0123-beta",
                                             version_pattern)
    patterns = [
        v2patterns.compile_pattern(version_pattern,
                                   '__version__ = "{version}"')
    ]
    lines = v2rewrite.rewrite_lines(patterns, new_vinfo,
                                    ['__version__ = "v201809.0002-alpha"   '])
    assert lines == ['__version__ = "v201811.0123-beta"   ']

    lines = v2rewrite.rewrite_lines(
        patterns, new_vinfo,
        ['__version__ = "v201809.0002-alpha"    # comment'])
    assert lines == ['__version__ = "v201811.0123-beta"    # comment']

    patterns = [
        v2patterns.compile_pattern(version_pattern,
                                   '__version__ = "YYYY0M.BLD[PYTAGNUM]"')
    ]
    old_lines = ['__version__ = "201809.2a0"']
    lines = v2rewrite.rewrite_lines(patterns, new_vinfo, old_lines)
    assert lines == ['__version__ = "201811.123b0"']
Exemple #7
0
def test_v2_parse_versions():
    _vnfo = v2version.parse_version_info(
        "v201712.0033", raw_pattern="vYYYY0M.BUILD[-TAG[NUM]]")
    fvals = {'year_y': 2017, 'month': 12, 'bid': "0033"}
    assert _vnfo == v2version.parse_field_values_to_vinfo(fvals)