setup to reduce code duplication

This commit is contained in:
Manuel Barkhau 2020-09-08 20:59:52 +00:00
parent e053af589e
commit 3cbf0e82b1
10 changed files with 271 additions and 267 deletions

View file

@ -1,3 +1,4 @@
import pycalver.patterns as v1patterns
from pycalver import parse
SETUP_PY_FIXTURE = """
@ -11,17 +12,17 @@ setuptools.setup(
def test_default_parse_patterns():
lines = SETUP_PY_FIXTURE.splitlines()
patterns = ["{pycalver}", "{pep440_pycalver}"]
matches = list(parse.iter_matches(lines, patterns))
lines = SETUP_PY_FIXTURE.splitlines()
patterns = ["{pycalver}", "{pep440_pycalver}"]
re_patterns = [v1patterns.compile_pattern(p) for p in patterns]
matches = list(parse.iter_matches(lines, re_patterns))
assert len(matches) == 2
assert matches[0].lineno == 3
assert matches[1].lineno == 6
assert matches[0].pattern == patterns[0]
assert matches[1].pattern == patterns[1]
assert matches[0].pattern == re_patterns[0]
assert matches[1].pattern == re_patterns[1]
assert matches[0].match == "v201712.0002-alpha"
assert matches[1].match == "201712.2a0"
@ -30,16 +31,16 @@ def test_default_parse_patterns():
def test_explicit_parse_patterns():
lines = SETUP_PY_FIXTURE.splitlines()
patterns = ["__version__ = '{pycalver}'", "version='{pep440_pycalver}'"]
matches = list(parse.iter_matches(lines, patterns))
patterns = ["__version__ = '{pycalver}'", "version='{pep440_pycalver}'"]
re_patterns = [v1patterns.compile_pattern(p) for p in patterns]
matches = list(parse.iter_matches(lines, re_patterns))
assert len(matches) == 2
assert matches[0].lineno == 3
assert matches[1].lineno == 6
assert matches[0].pattern == patterns[0]
assert matches[1].pattern == patterns[1]
assert matches[0].pattern == re_patterns[0]
assert matches[1].pattern == re_patterns[1]
assert matches[0].match == "__version__ = 'v201712.0002-alpha'"
assert matches[1].match == "version='201712.2a0'"
@ -57,16 +58,17 @@ README_RST_FIXTURE = """
def test_badge_parse_patterns():
lines = README_RST_FIXTURE.splitlines()
patterns = ["badge/CalVer-{calver}{build}-{release}-blue.svg", ":alt: CalVer {pycalver}"]
patterns = ["badge/CalVer-{calver}{build}-{release}-blue.svg", ":alt: CalVer {pycalver}"]
re_patterns = [v1patterns.compile_pattern(p) for p in patterns]
matches = list(parse.iter_matches(lines, re_patterns))
matches = list(parse.iter_matches(lines, patterns))
assert len(matches) == 2
assert matches[0].lineno == 3
assert matches[1].lineno == 5
assert matches[0].pattern == patterns[0]
assert matches[1].pattern == patterns[1]
assert matches[0].pattern == re_patterns[0]
assert matches[1].pattern == re_patterns[1]
assert matches[0].match == "badge/CalVer-v201809.0002--beta-blue.svg"
assert matches[1].match == ":alt: CalVer v201809.0002-beta"