From 9d2655d83ded1a772c47e9d930cfcca83a56c4cd Mon Sep 17 00:00:00 2001 From: mtkennerly Date: Wed, 26 Jun 2024 23:03:09 -0400 Subject: [PATCH] Increase line length --- dunamai/__init__.py | 162 +++++++------------------- dunamai/__main__.py | 9 +- pyproject.toml | 4 +- tests/integration/test_dunamai.py | 40 ++----- tests/unit/test_dunamai.py | 183 +++++++----------------------- tests/unit/test_main.py | 4 +- 6 files changed, 98 insertions(+), 304 deletions(-) diff --git a/dunamai/__init__.py b/dunamai/__init__.py index f24af34..b31462b 100644 --- a/dunamai/__init__.py +++ b/dunamai/__init__.py @@ -186,9 +186,7 @@ def message(self) -> str: return "" -def _pattern_error( - primary: str, pattern: Union[str, Pattern], tags: Optional[Sequence[str]] = None -) -> str: +def _pattern_error(primary: str, pattern: Union[str, Pattern], tags: Optional[Sequence[str]] = None) -> str: parts = [primary, "Pattern:\n{}".format(pattern)] if tags is not None: @@ -214,11 +212,7 @@ def _run_cmd( ) output = result.stdout.decode().strip() if codes and result.returncode not in codes: - raise RuntimeError( - "The command '{}' returned code {}. Output:\n{}".format( - command, result.returncode, output - ) - ) + raise RuntimeError("The command '{}' returned code {}. Output:\n{}".format(command, result.returncode, output)) return (result.returncode, output) @@ -267,9 +261,7 @@ def _match_version_pattern( except re.error as e: raise re.error( _pattern_error( - "The pattern is an invalid regular expression: {}".format( - e.msg # type: ignore - ), + "The pattern is an invalid regular expression: {}".format(e.msg), # type: ignore pattern, ), e.pattern, # type: ignore @@ -283,9 +275,7 @@ def _match_version_pattern( if base is not None: break except IndexError: - raise ValueError( - _pattern_error("The pattern did not include required capture group 'base'", pattern) - ) + raise ValueError(_pattern_error("The pattern did not include required capture group 'base'", pattern)) if pattern_match is None or base is None: if latest_source: raise ValueError( @@ -315,9 +305,7 @@ def _match_version_pattern( except ValueError: raise ValueError("Epoch '{}' is not a valid number".format(epoch)) - return _MatchedVersionPattern( - source, base, stage_revision, newer_unmatched_tags, tagged_metadata, epoch - ) + return _MatchedVersionPattern(source, base, stage_revision, newer_unmatched_tags, tagged_metadata, epoch) def _blank(value: Optional[_T], default: _T) -> _T: @@ -375,9 +363,7 @@ def _detect_vcs(expected_vcs: Optional[Vcs], path: Optional[Path]) -> Vcs: if code != 0: if expected_vcs == Vcs.Git and dubious_ownership_flag in msg: raise RuntimeError(dubious_ownership_error) - raise RuntimeError( - "This does not appear to be a {} project".format(expected_vcs.value.title()) - ) + raise RuntimeError("This does not appear to be a {} project".format(expected_vcs.value.title())) return expected_vcs else: disproven = [] @@ -415,9 +401,7 @@ def _detect_vcs_from_archival(path: Optional[Path]) -> Optional[Vcs]: return None -def _find_higher_file( - name: str, start: Optional[Path], limit: Optional[str] = None -) -> Optional[Path]: +def _find_higher_file(name: str, start: Optional[Path], limit: Optional[str] = None) -> Optional[Path]: """ :param name: Bare name of a file we'd like to find. :param limit: Give up if we find a file/folder with this name. @@ -435,9 +419,7 @@ def _find_higher_file( class _GitRefInfo: - def __init__( - self, ref: str, commit: str, creatordate: str, committerdate: str, taggerdate: str - ): + def __init__(self, ref: str, commit: str, creatordate: str, committerdate: str, taggerdate: str): self.fullref = ref self.commit = commit self.creatordate = self.normalize_git_dt(creatordate) @@ -457,10 +439,7 @@ def normalize_git_dt(timestamp: str) -> Optional[dt.datetime]: return _parse_git_timestamp_iso_strict(timestamp) def __repr__(self): - return ( - "_GitRefInfo(ref={!r}, commit={!r}, creatordate={!r}," - " committerdate={!r}, taggerdate={!r})" - ).format( + return ("_GitRefInfo(ref={!r}, commit={!r}, creatordate={!r}," " committerdate={!r}, taggerdate={!r})").format( self.fullref, self.commit_offset, self.creatordate, self.committerdate, self.taggerdate ) @@ -478,9 +457,7 @@ def commit_offset(self) -> int: return self.tag_topo_lookup[self.fullref] except KeyError: raise RuntimeError( - "Unable to determine commit offset for ref {} in data: {}".format( - self.fullref, self.tag_topo_lookup - ) + "Unable to determine commit offset for ref {} in data: {}".format(self.fullref, self.tag_topo_lookup) ) @property @@ -499,19 +476,15 @@ def normalize_tag_ref(ref: str) -> str: return "refs/tags/{}".format(ref) @staticmethod - def from_git_tag_topo_order( - tag_branch: str, git_version: List[int], path: Optional[Path] - ) -> Mapping[str, int]: - cmd = ( - '{} --simplify-by-decoration --topo-order --decorate=full {} "--format=%H%d"' - ).format(_git_log(git_version), tag_branch) + def from_git_tag_topo_order(tag_branch: str, git_version: List[int], path: Optional[Path]) -> Mapping[str, int]: + cmd = ('{} --simplify-by-decoration --topo-order --decorate=full {} "--format=%H%d"').format( + _git_log(git_version), tag_branch + ) if git_version >= [2, 16]: cmd += " --decorate-refs=refs/tags/" code, logmsg = _run_cmd(cmd, path) - filtered_lines = [ - x for x in logmsg.strip().splitlines(keepends=False) if " (" not in x or "tag: " in x - ] + filtered_lines = [x for x in logmsg.strip().splitlines(keepends=False) if " (" not in x or "tag: " in x] tag_lookup = {} for tag_offset, line in enumerate(filtered_lines): @@ -522,9 +495,7 @@ def from_git_tag_topo_order( if tags: # remove trailing ')' tags = tags[:-1] - taglist = [ - tag.strip() for tag in tags.split(", ") if tag.strip().startswith("tag: ") - ] + taglist = [tag.strip() for tag in tags.split(", ") if tag.strip().startswith("tag: ")] taglist = [tag.split()[-1] for tag in taglist] taglist = [_GitRefInfo.normalize_tag_ref(tag) for tag in taglist] for tag in taglist: @@ -637,9 +608,7 @@ def __repr__(self) -> str: def __eq__(self, other: Any) -> bool: if not isinstance(other, Version): - raise TypeError( - "Cannot compare Version with type {}".format(other.__class__.__qualname__) - ) + raise TypeError("Cannot compare Version with type {}".format(other.__class__.__qualname__)) return ( self.base == other.base and self.stage == other.stage @@ -676,9 +645,7 @@ def _matches_partial(self, other: "Version") -> bool: def __lt__(self, other: Any) -> bool: if not isinstance(other, Version): - raise TypeError( - "Cannot compare Version with type {}".format(other.__class__.__qualname__) - ) + raise TypeError("Cannot compare Version with type {}".format(other.__class__.__qualname__)) import packaging.version as pv @@ -863,9 +830,7 @@ def parse(cls, version: str, pattern: Union[str, Pattern] = Pattern.Default) -> failed = False try: - matched_pattern = _match_version_pattern( - pattern, [normalized], True, strict=True, pattern_prefix=None - ) + matched_pattern = _match_version_pattern(pattern, [normalized], True, strict=True, pattern_prefix=None) except ValueError: failed = True @@ -1087,9 +1052,7 @@ def from_git( vcs=vcs, ) - matched_pattern = _match_version_pattern( - pattern, [tag], latest_tag, strict, pattern_prefix - ) + matched_pattern = _match_version_pattern(pattern, [tag], latest_tag, strict, pattern_prefix) if matched_pattern is None: return cls._fallback( strict, @@ -1144,28 +1107,20 @@ def from_git( branch = msg code, msg = _run_cmd( - '{} -n 1 --format="format:{}"'.format( - _git_log(git_version), "%H" if full_commit else "%h" - ), + '{} -n 1 --format="format:{}"'.format(_git_log(git_version), "%H" if full_commit else "%h"), path, codes=[0, 128], ) if code == 128: - return cls._fallback( - strict, distance=0, dirty=True, branch=branch, concerns=concerns, vcs=vcs - ) + return cls._fallback(strict, distance=0, dirty=True, branch=branch, concerns=concerns, vcs=vcs) commit = msg timestamp = None if git_version < [2, 2]: - code, msg = _run_cmd( - '{} -n 1 --pretty=format:"%ci"'.format(_git_log(git_version)), path - ) + code, msg = _run_cmd('{} -n 1 --pretty=format:"%ci"'.format(_git_log(git_version)), path) timestamp = _parse_git_timestamp_iso(msg) else: - code, msg = _run_cmd( - '{} -n 1 --pretty=format:"%cI"'.format(_git_log(git_version)), path - ) + code, msg = _run_cmd('{} -n 1 --pretty=format:"%cI"'.format(_git_log(git_version)), path) timestamp = _parse_git_timestamp_iso_strict(msg) code, msg = _run_cmd("git describe --always --dirty", path) @@ -1177,9 +1132,7 @@ def from_git( dirty = True if git_version < [2, 7]: - code, msg = _run_cmd( - 'git for-each-ref "refs/tags/**" --format "%(refname)" --sort -creatordate', path - ) + code, msg = _run_cmd('git for-each-ref "refs/tags/**" --format "%(refname)" --sort -creatordate', path) if not msg: try: code, msg = _run_cmd("git rev-list --count HEAD", path) @@ -1197,13 +1150,10 @@ def from_git( vcs=vcs, ) tags = [line.replace("refs/tags/", "") for line in msg.splitlines()] - matched_pattern = _match_version_pattern( - pattern, tags, latest_tag, strict, pattern_prefix - ) + matched_pattern = _match_version_pattern(pattern, tags, latest_tag, strict, pattern_prefix) else: code, msg = _run_cmd( - 'git for-each-ref "refs/tags/**" --merged {}'.format(tag_branch) - + ' --format "%(refname)' + 'git for-each-ref "refs/tags/**" --merged {}'.format(tag_branch) + ' --format "%(refname)' "@{%(objectname)" "@{%(creatordate:iso-strict)" "@{%(*committerdate:iso-strict)" @@ -1238,9 +1188,7 @@ def from_git( detailed_tags.append(_GitRefInfo(*parts).with_tag_topo_lookup(tag_topo_lookup)) tags = [t.ref for t in sorted(detailed_tags, key=lambda x: x.sort_key, reverse=True)] - matched_pattern = _match_version_pattern( - pattern, tags, latest_tag, strict, pattern_prefix - ) + matched_pattern = _match_version_pattern(pattern, tags, latest_tag, strict, pattern_prefix) if matched_pattern is None: try: @@ -1325,9 +1273,7 @@ def from_mercurial( branch = data.get("branch") if tag is None or tag == "null": - return cls._fallback( - strict, distance=distance, commit=commit, branch=branch, vcs=vcs - ) + return cls._fallback(strict, distance=distance, commit=commit, branch=branch, vcs=vcs) all_tags_file = _find_higher_file(".hgtags", path, ".hg") if all_tags_file is None: @@ -1341,9 +1287,7 @@ def from_mercurial( continue all_tags.append(parts[1]) - matched_pattern = _match_version_pattern( - pattern, all_tags, latest_tag, strict, pattern_prefix - ) + matched_pattern = _match_version_pattern(pattern, all_tags, latest_tag, strict, pattern_prefix) if matched_pattern is None: return cls._fallback( strict, @@ -1376,9 +1320,7 @@ def from_mercurial( code, msg = _run_cmd("hg branch", path) branch = msg - code, msg = _run_cmd( - 'hg id --template "{}"'.format("{id}" if full_commit else "{id|short}"), path - ) + code, msg = _run_cmd('hg id --template "{}"'.format("{id}" if full_commit else "{id|short}"), path) commit = msg if set(msg) != {"0"} else None code, msg = _run_cmd('hg log --limit 1 --template "{date|rfc3339date}"', path) @@ -1485,9 +1427,7 @@ def from_darcs( distance = int(msg) except Exception: distance = 0 - return cls._fallback( - strict, distance=distance, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs - ) + return cls._fallback(strict, distance=distance, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs) tags = msg.splitlines() matched_pattern = _match_version_pattern(pattern, tags, latest_tag, strict, pattern_prefix) @@ -1569,9 +1509,7 @@ def from_subversion( timestamp = _parse_timestamp(msg) if not commit: - return cls._fallback( - strict, distance=0, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs - ) + return cls._fallback(strict, distance=0, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs) code, msg = _run_cmd('svn ls -v -r {} "{}/{}"'.format(commit, url, tag_dir), path) lines = [line.split(maxsplit=5) for line in msg.splitlines()[1:]] tags_to_revs = {line[-1].strip("/"): int(line[0]) for line in lines} @@ -1580,14 +1518,10 @@ def from_subversion( distance = int(commit) except Exception: distance = 0 - return cls._fallback( - strict, distance=distance, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs - ) + return cls._fallback(strict, distance=distance, commit=commit, dirty=dirty, timestamp=timestamp, vcs=vcs) tags_to_sources_revs = {} for tag, rev in tags_to_revs.items(): - code, msg = _run_cmd( - 'svn log -v "{}/{}/{}" --stop-on-copy'.format(url, tag_dir, tag), path - ) + code, msg = _run_cmd('svn log -v "{}/{}/{}" --stop-on-copy'.format(url, tag_dir, tag), path) for line in msg.splitlines(): match = re.search(r"A /{}/{} \(from .+?:(\d+)\)".format(tag_dir, tag), line) if match: @@ -1687,11 +1621,7 @@ def from_bazaar( timestamp=timestamp, vcs=vcs, ) - tags_to_revs = { - line.split()[0]: int(line.split()[1]) - for line in msg.splitlines() - if line.split()[1] != "?" - } + tags_to_revs = {line.split()[0]: int(line.split()[1]) for line in msg.splitlines() if line.split()[1] != "?"} tags = [x[1] for x in sorted([(v, k) for k, v in tags_to_revs.items()], reverse=True)] matched_pattern = _match_version_pattern(pattern, tags, latest_tag, strict, pattern_prefix) @@ -1756,9 +1686,7 @@ def from_fossil( code, msg = _run_cmd("fossil branch current", path) branch = msg - code, msg = _run_cmd( - "fossil sql \"SELECT value FROM vvar WHERE name = 'checkout-hash' LIMIT 1\"", path - ) + code, msg = _run_cmd("fossil sql \"SELECT value FROM vvar WHERE name = 'checkout-hash' LIMIT 1\"", path) commit = msg.strip("'") code, msg = _run_cmd( @@ -1825,8 +1753,7 @@ def from_fossil( ) tags_to_distance = [ - (line.rsplit(",", 1)[0][5:-1], int(line.rsplit(",", 1)[1]) - 1) - for line in msg.splitlines() + (line.rsplit(",", 1)[0][5:-1], int(line.rsplit(",", 1)[1]) - 1) for line in msg.splitlines() ] matched_pattern = _match_version_pattern( @@ -1933,9 +1860,7 @@ def from_pijul( if line.startswith("State "): tag_state = line.split("State ", 1)[1] elif line.startswith("Date:"): - tag_timestamp = _parse_timestamp( - line.split("Date: ", 1)[1].replace(" UTC", "Z"), space=True - ) + tag_timestamp = _parse_timestamp(line.split("Date: ", 1)[1].replace(" UTC", "Z"), space=True) elif line.startswith(" "): tag_message += line[4:] tag_after_header = True @@ -1956,9 +1881,7 @@ def from_pijul( else: tag_message += line if tag_after_header: - tag_meta.append( - {"state": tag_state, "timestamp": tag_timestamp, "message": tag_message.strip()} - ) + tag_meta.append({"state": tag_state, "timestamp": tag_timestamp, "message": tag_message.strip()}) tag_meta_by_msg = {} # type: dict for meta in tag_meta: @@ -1968,10 +1891,7 @@ def from_pijul( ): tag_meta_by_msg[meta["message"]] = meta - tags = [ - t["message"] - for t in sorted(tag_meta_by_msg.values(), key=lambda x: x["timestamp"], reverse=True) - ] + tags = [t["message"] for t in sorted(tag_meta_by_msg.values(), key=lambda x: x["timestamp"], reverse=True)] matched_pattern = _match_version_pattern(pattern, tags, latest_tag, strict, pattern_prefix) if matched_pattern is None: diff --git a/dunamai/__main__.py b/dunamai/__main__.py index 8cbe82e..e664864 100644 --- a/dunamai/__main__.py +++ b/dunamai/__main__.py @@ -91,10 +91,7 @@ "action": "store_true", "dest": "strict", "default": False, - "help": ( - "Elevate warnings to errors." - " When there are no tags, fail instead of falling back to 0.0.0" - ), + "help": ("Elevate warnings to errors." " When there are no tags, fail instead of falling back to 0.0.0"), }, { "triggers": ["--path"], @@ -269,9 +266,7 @@ def from_vcs( path: Optional[Path], pattern_prefix: Optional[str], ) -> None: - version = Version.from_vcs( - vcs, pattern, latest_tag, tag_dir, tag_branch, full_commit, strict, path, pattern_prefix - ) + version = Version.from_vcs(vcs, pattern, latest_tag, tag_dir, tag_branch, full_commit, strict, path, pattern_prefix) for concern in version.concerns: print("Warning: {}".format(concern.message()), file=sys.stderr) diff --git a/pyproject.toml b/pyproject.toml index 38fba7a..498d714 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,10 +43,10 @@ ruff = {version = "^0.0.272", python = "^3.7"} dunamai = 'dunamai.__main__:main' [tool.black] -line-length = 100 +line-length = 120 [tool.ruff] -line-length = 100 +line-length = 120 extend-select = ["W605", "N"] [build-system] diff --git a/tests/integration/test_dunamai.py b/tests/integration/test_dunamai.py index 30b6be3..a65fcde 100644 --- a/tests/integration/test_dunamai.py +++ b/tests/integration/test_dunamai.py @@ -59,9 +59,7 @@ def inner(command, expected_code: int = 0, env: Optional[dict] = None): return inner -def make_from_callback( - function: Callable, clear: bool = True, chronological: bool = True -) -> Callable: +def make_from_callback(function: Callable, clear: bool = True, chronological: bool = True) -> Callable: def inner(*args, fresh: bool = False, **kwargs): version = function(*args, **kwargs) if fresh: @@ -124,9 +122,7 @@ def test__version__from_git__with_annotated_tags(tmp_path) -> None: # Detect dirty if untracked files (vcs / "bar.txt").write_text("bye") assert from_vcs() == Version("0.0.0", distance=1, dirty=True, branch=b) - assert from_vcs(ignore_untracked=True) == Version( - "0.0.0", distance=1, dirty=False, branch=b - ) + assert from_vcs(ignore_untracked=True) == Version("0.0.0", distance=1, dirty=False, branch=b) # Once the untracked file is removed we are no longer dirty (vcs / "bar.txt").unlink() @@ -159,12 +155,8 @@ def test__version__from_git__with_annotated_tags(tmp_path) -> None: assert from_explicit_vcs(Vcs.Any) == Version("0.1.0", dirty=False, branch=b) assert from_explicit_vcs(Vcs.Git) == Version("0.1.0", dirty=False, branch=b) assert run("dunamai from any --bump") == "0.1.0" - assert run('dunamai from git --format "{commit}"') != run( - 'dunamai from git --format "{commit}" --full-commit' - ) - assert run('dunamai from any --format "{commit}"') != run( - 'dunamai from any --format "{commit}" --full-commit' - ) + assert run('dunamai from git --format "{commit}"') != run('dunamai from git --format "{commit}" --full-commit') + assert run('dunamai from any --format "{commit}"') != run('dunamai from any --format "{commit}" --full-commit') if not legacy: # Verify tags with '/' work @@ -425,9 +417,7 @@ def test__version__from_git__archival_untagged() -> None: assert Version.from_any_vcs() == detected - assert ( - Version.from_git(full_commit=True).commit == "8fe614dbf9e767e70442ab8f56e99bd08d7e782d" - ) + assert Version.from_git(full_commit=True).commit == "8fe614dbf9e767e70442ab8f56e99bd08d7e782d" with pytest.raises(RuntimeError): Version.from_git(strict=True) @@ -549,9 +539,7 @@ def test__version__from_mercurial(tmp_path) -> None: assert run('dunamai from mercurial --format "{commit}"') != run( 'dunamai from mercurial --format "{commit}" --full-commit' ) - assert run('dunamai from any --format "{commit}"') != run( - 'dunamai from any --format "{commit}" --full-commit' - ) + assert run('dunamai from any --format "{commit}"') != run('dunamai from any --format "{commit}" --full-commit') run("hg tag v0.1.0") assert from_vcs() == Version("0.1.0", dirty=False, branch=b) @@ -662,9 +650,7 @@ def test__version__from_darcs(tmp_path) -> None: assert from_vcs(path=vcs) == Version("0.1.0", dirty=False) -@pytest.mark.skipif( - None in [shutil.which("svn"), shutil.which("svnadmin")], reason="Requires Subversion" -) +@pytest.mark.skipif(None in [shutil.which("svn"), shutil.which("svnadmin")], reason="Requires Subversion") def test__version__from_subversion(tmp_path) -> None: vcs = tmp_path / "dunamai-svn" vcs.mkdir() @@ -706,9 +692,7 @@ def test__version__from_subversion(tmp_path) -> None: # Two commits, but still no tag. Version should still be 0.0.0. assert from_vcs() == Version("0.0.0", distance=2, commit="2", dirty=False) - run( - 'svn copy {0}/trunk {0}/tags/v0.1.0 -m "Tag 1"'.format(vcs_srv_uri) - ) # commit 3 and first tag! + run('svn copy {0}/trunk {0}/tags/v0.1.0 -m "Tag 1"'.format(vcs_srv_uri)) # commit 3 and first tag! run("svn update") # 3 commits, one tag (v.0.1.0), version should be 0.1.0. @@ -753,9 +737,7 @@ def test__version__from_subversion(tmp_path) -> None: # #3), so version should be 0.1.0. run("svn update -r 3") assert from_vcs() == Version("0.1.0", distance=0, commit="3", dirty=False) - assert from_vcs(latest_tag=True) == Version( - "0.1.0", distance=0, commit="3", dirty=False - ) + assert from_vcs(latest_tag=True) == Version("0.1.0", distance=0, commit="3", dirty=False) assert from_vcs(path=vcs) == Version("0.1.0", distance=0, commit="3", dirty=False) @@ -792,9 +774,7 @@ def test__version__from_bazaar(tmp_path) -> None: run("bzr add .") run('bzr commit -m "Second"') assert from_vcs() == Version("0.1.0", distance=1, commit="2", dirty=False, branch=b) - assert from_any_vcs_unmocked() == Version( - "0.1.0", distance=1, commit="2", dirty=False, branch=b - ) + assert from_any_vcs_unmocked() == Version("0.1.0", distance=1, commit="2", dirty=False, branch=b) run("bzr tag unmatched") assert from_vcs() == Version("0.1.0", distance=1, commit="2", dirty=False, branch=b) diff --git a/tests/unit/test_dunamai.py b/tests/unit/test_dunamai.py index dc143b9..bb0d527 100644 --- a/tests/unit/test_dunamai.py +++ b/tests/unit/test_dunamai.py @@ -81,9 +81,7 @@ def test__pattern__parse() -> None: def test__version__init() -> None: - v = Version( - "1", stage=("a", 2), distance=3, commit="abc", dirty=True, tagged_metadata="def", epoch=4 - ) + v = Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True, tagged_metadata="def", epoch=4) assert v.base == "1" assert v.stage == "a" assert v.revision == 2 @@ -136,34 +134,22 @@ def test__version__ordering() -> None: def test__version__serialize__pep440() -> None: assert Version("0.1.0").serialize() == "0.1.0" - assert ( - Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize() - == "1a2.post3.dev0+abc" - ) + assert Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize() == "1a2.post3.dev0+abc" assert ( Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize(dirty=True) == "1a2.post3.dev0+abc.dirty" ) assert ( - Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize(metadata=False) - == "1a2.post3.dev0" + Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize(metadata=False) == "1a2.post3.dev0" ) assert ( - Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize( - metadata=False, dirty=True - ) + Version("1", stage=("a", 2), distance=3, commit="abc", dirty=True).serialize(metadata=False, dirty=True) == "1a2.post3.dev0" ) - assert ( - Version("1", stage=("a", 0), distance=3, commit="abc", dirty=False).serialize() - == "1a0.post3.dev0+abc" - ) + assert Version("1", stage=("a", 0), distance=3, commit="abc", dirty=False).serialize() == "1a0.post3.dev0+abc" assert Version("1", stage=("a", 2), distance=0, commit="abc", dirty=False).serialize() == "1a2" - assert ( - Version("1", stage=("a", 2), distance=3, commit="000", dirty=False).serialize() - == "1a2.post3.dev0+000" - ) + assert Version("1", stage=("a", 2), distance=3, commit="000", dirty=False).serialize() == "1a2.post3.dev0+000" assert Version("1", stage=("a", None)).serialize() == "1a0" assert Version("1", stage=("b", 2)).serialize() == "1b2" @@ -179,9 +165,7 @@ def test__version__serialize__pep440() -> None: assert Version("0.1.0", stage=("post", 1)).serialize() == "0.1.0.post1" assert Version("0.1.0", stage=("post", 1), distance=3).serialize() == "0.1.0.post1.dev3" - assert ( - Version("0.1.0", stage=("post", 1), distance=3).serialize(bump=True) == "0.1.0.post2.dev3" - ) + assert Version("0.1.0", stage=("post", 1), distance=3).serialize(bump=True) == "0.1.0.post2.dev3" assert Version("0.1.0", stage=("dev", 1)).serialize() == "0.1.0.dev1" assert Version("0.1.0", stage=("dev", 1), distance=3).serialize() == "0.1.0.dev4" assert Version("0.1.0", stage=("dev", 1), distance=3).serialize(bump=True) == "0.1.0.dev5" @@ -192,15 +176,11 @@ def test__version__serialize__semver() -> None: assert Version("0.1.0").serialize(style=style) == "0.1.0" assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(style=style) == "0.1.0-alpha.2.post.3+abc" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize( - dirty=True, style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(dirty=True, style=style) == "0.1.0-alpha.2.post.3+abc.dirty" ) assert ( @@ -217,21 +197,15 @@ def test__version__serialize__semver() -> None: ) assert ( - Version("0.1.0", stage=("alpha", 0), distance=3, commit="abc", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 0), distance=3, commit="abc", dirty=False).serialize(style=style) == "0.1.0-alpha.0.post.3+abc" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize(style=style) == "0.1.0-alpha.2" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="000", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="000", dirty=False).serialize(style=style) == "0.1.0-alpha.2.post.3+000" ) @@ -242,13 +216,9 @@ def test__version__serialize__semver() -> None: assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.0" assert Version("0.1.0", distance=3).serialize(style=style, bump=True) == "0.1.1-pre.3" assert ( - Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True) - == "0.1.0-alpha.2.pre.3" - ) - assert ( - Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True) - == "0.1.0-beta.3.pre.4" + Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True) == "0.1.0-alpha.2.pre.3" ) + assert Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True) == "0.1.0-beta.3.pre.4" assert Version("0.1.0", epoch=2).serialize(style=style) == "0.1.0" @@ -258,15 +228,11 @@ def test__version__serialize__pvp() -> None: assert Version("0.1.0").serialize(style=style) == "0.1.0" assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(style=style) == "0.1.0-alpha-2-post-3-abc" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize( - dirty=True, style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="abc", dirty=True).serialize(dirty=True, style=style) == "0.1.0-alpha-2-post-3-abc-dirty" ) assert ( @@ -283,21 +249,15 @@ def test__version__serialize__pvp() -> None: ) assert ( - Version("0.1.0", stage=("alpha", 0), distance=3, commit="abc", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 0), distance=3, commit="abc", dirty=False).serialize(style=style) == "0.1.0-alpha-0-post-3-abc" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=0, commit="abc", dirty=False).serialize(style=style) == "0.1.0-alpha-2" ) assert ( - Version("0.1.0", stage=("alpha", 2), distance=3, commit="000", dirty=False).serialize( - style=style - ) + Version("0.1.0", stage=("alpha", 2), distance=3, commit="000", dirty=False).serialize(style=style) == "0.1.0-alpha-2-post-3-000" ) @@ -308,13 +268,9 @@ def test__version__serialize__pvp() -> None: assert Version("0.1.0").serialize(style=style, bump=True) == "0.1.0" assert Version("0.1.0", distance=3).serialize(style=style, bump=True) == "0.1.1-pre-3" assert ( - Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True) - == "0.1.0-alpha-2-pre-3" - ) - assert ( - Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True) - == "0.1.0-beta-3-pre-4" + Version("0.1.0", stage=("alpha", None), distance=3).serialize(style=style, bump=True) == "0.1.0-alpha-2-pre-3" ) + assert Version("0.1.0", stage=("beta", 2), distance=4).serialize(style=style, bump=True) == "0.1.0-beta-3-pre-4" assert Version("0.1.0", epoch=2).serialize(style=style) == "0.1.0" @@ -329,18 +285,11 @@ def test__version__serialize__pep440_metadata() -> None: assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False) == "0.1.0a1" assert Version("0.1.0", distance=1, commit="abc").serialize() == "0.1.0.post1.dev0+abc" - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=True) - == "0.1.0.post1.dev0+abc" - ) - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=False) == "0.1.0.post1.dev0" - ) + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=True) == "0.1.0.post1.dev0+abc" + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=False) == "0.1.0.post1.dev0" assert ( - Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize( - tagged_metadata=True - ) + Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize(tagged_metadata=True) == "0.1.0.post1.dev0+def.abc" ) @@ -352,29 +301,15 @@ def test__version__serialize__semver_with_metadata() -> None: assert Version("0.1.0").serialize(metadata=False, style=style) == "0.1.0" assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(style=style) == "0.1.0-a.1" - assert ( - Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style) - == "0.1.0-a.1+abc" - ) - assert ( - Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style) - == "0.1.0-a.1" - ) + assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style) == "0.1.0-a.1+abc" + assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style) == "0.1.0-a.1" assert Version("0.1.0", distance=1, commit="abc").serialize(style=style) == "0.1.0-post.1+abc" - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style) - == "0.1.0-post.1+abc" - ) - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=False, style=style) - == "0.1.0-post.1" - ) + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style) == "0.1.0-post.1+abc" + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=False, style=style) == "0.1.0-post.1" assert ( - Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize( - style=style, tagged_metadata=True - ) + Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize(style=style, tagged_metadata=True) == "0.1.0-post.1+def.abc" ) @@ -386,29 +321,15 @@ def test__version__serialize__pvp_with_metadata() -> None: assert Version("0.1.0").serialize(metadata=False, style=style) == "0.1.0" assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(style=style) == "0.1.0-a-1" - assert ( - Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style) - == "0.1.0-a-1-abc" - ) - assert ( - Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style) - == "0.1.0-a-1" - ) + assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=True, style=style) == "0.1.0-a-1-abc" + assert Version("0.1.0", stage=("a", 1), commit="abc").serialize(metadata=False, style=style) == "0.1.0-a-1" assert Version("0.1.0", distance=1, commit="abc").serialize(style=style) == "0.1.0-post-1-abc" - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style) - == "0.1.0-post-1-abc" - ) - assert ( - Version("0.1.0", distance=1, commit="abc").serialize(metadata=False, style=style) - == "0.1.0-post-1" - ) + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=True, style=style) == "0.1.0-post-1-abc" + assert Version("0.1.0", distance=1, commit="abc").serialize(metadata=False, style=style) == "0.1.0-post-1" assert ( - Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize( - style=style, tagged_metadata=True - ) + Version("0.1.0", distance=1, commit="abc", tagged_metadata="def").serialize(style=style, tagged_metadata=True) == "0.1.0-post-1-def-abc" ) @@ -436,15 +357,10 @@ def test__version__serialize__semver_with_dirty() -> None: assert Version("0.1.0", dirty=False).serialize(dirty=True, style=style) == "0.1.0" assert Version("0.1.0", dirty=True).serialize(metadata=True, style=style) == "0.1.0" - assert ( - Version("0.1.0", dirty=True).serialize(metadata=True, dirty=True, style=style) - == "0.1.0+dirty" - ) + assert Version("0.1.0", dirty=True).serialize(metadata=True, dirty=True, style=style) == "0.1.0+dirty" assert Version("0.1.0", dirty=True).serialize(metadata=False, style=style) == "0.1.0" - assert ( - Version("0.1.0", dirty=True).serialize(metadata=False, dirty=True, style=style) == "0.1.0" - ) + assert Version("0.1.0", dirty=True).serialize(metadata=False, dirty=True, style=style) == "0.1.0" def test__version__serialize__pvp_with_dirty() -> None: @@ -456,22 +372,14 @@ def test__version__serialize__pvp_with_dirty() -> None: assert Version("0.1.0", dirty=False).serialize(dirty=True, style=style) == "0.1.0" assert Version("0.1.0", dirty=True).serialize(metadata=True, style=style) == "0.1.0" - assert ( - Version("0.1.0", dirty=True).serialize(metadata=True, dirty=True, style=style) - == "0.1.0-dirty" - ) + assert Version("0.1.0", dirty=True).serialize(metadata=True, dirty=True, style=style) == "0.1.0-dirty" assert Version("0.1.0", dirty=True).serialize(metadata=False, style=style) == "0.1.0" - assert ( - Version("0.1.0", dirty=True).serialize(metadata=False, dirty=True, style=style) == "0.1.0" - ) + assert Version("0.1.0", dirty=True).serialize(metadata=False, dirty=True, style=style) == "0.1.0" def test__version__serialize__format_as_str() -> None: - format = ( - "{base},{stage},{revision},{distance},{commit},{dirty}" - ",{branch},{branch_escaped},{timestamp}" - ) + format = "{base},{stage},{revision},{distance},{commit},{dirty}" ",{branch},{branch_escaped},{timestamp}" assert Version("0.1.0").serialize(format=format) == "0.1.0,,,0,,clean,,," assert ( Version( @@ -569,9 +477,7 @@ def test__get_version__first_choice() -> None: def test__get_version__third_choice() -> None: - assert get_version("dunamai_nonexistent_test", third_choice=lambda: Version("3")) == Version( - "3" - ) + assert get_version("dunamai_nonexistent_test", third_choice=lambda: Version("3")) == Version("3") def test__get_version__fallback() -> None: @@ -793,9 +699,7 @@ def test__serialize_pep440(): assert serialize_pep440("1.2.3", metadata=[4]) == "1.2.3+4" assert ( - serialize_pep440( - "1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"] - ) + serialize_pep440("1.2.3", epoch=0, stage="a", revision=4, post=5, dev=6, metadata=["foo", "bar"]) == "0!1.2.3a4.post5.dev6+foo.bar" ) @@ -818,10 +722,7 @@ def test__serialize_semver(): assert serialize_semver("1.2.3", metadata=["foo", "bar"]) == "1.2.3+foo.bar" assert serialize_semver("1.2.3", metadata=[4]) == "1.2.3+4" - assert ( - serialize_semver("1.2.3", pre=["alpha", 4], metadata=["foo", "bar"]) - == "1.2.3-alpha.4+foo.bar" - ) + assert serialize_semver("1.2.3", pre=["alpha", 4], metadata=["foo", "bar"]) == "1.2.3-alpha.4+foo.bar" with pytest.raises(ValueError): serialize_semver("foo") diff --git a/tests/unit/test_main.py b/tests/unit/test_main.py index a4f72d3..1ab04ee 100644 --- a/tests/unit/test_main.py +++ b/tests/unit/test_main.py @@ -62,9 +62,7 @@ def test__parse_args__from(): def test__parse_args__check(): - assert parse_args(["check", "0.1.0"]) == Namespace( - command="check", version="0.1.0", style="pep440" - ) + assert parse_args(["check", "0.1.0"]) == Namespace(command="check", version="0.1.0", style="pep440") assert parse_args(["check", "0.1.0", "--style", "semver"]).style == "semver" assert parse_args(["check", "0.1.0", "--style", "pvp"]).style == "pvp"