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")
def test_version(runner): result = runner.invoke(cli.cli, ['--version', "-vv"]) assert result.exit_code == 0 assert " version 20" in result.output pattern = v2patterns.compile_pattern("YYYY.BUILD[-TAG]") match = pattern.regexp.search(result.output) assert match
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
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"']
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)
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
def test_v2_patterns(pattern_str, line, expected): pattern = v2patterns.compile_pattern(pattern_str) result = pattern.regexp.search(line) result_val = None if result is None else result.group(0) assert result_val == expected, (pattern_str, line, pattern.regexp.pattern)