-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Semantic Version Check v1.0.0 Release
- Loading branch information
Showing
14 changed files
with
313 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
__version__ = '0.0.1' | ||
__version__ = '1.0.0' | ||
|
||
from .main import regex, version_check | ||
|
||
__all__ = ['regex', 'version_check'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Allow executing through `python -m semantic_version_check`. | ||
Allow Semantic Version Check to be executable through | ||
`python -m semantic_version_check`. | ||
""" | ||
from __future__ import absolute_import | ||
|
||
from semantic_version_check.cli import main | ||
|
||
if __name__ == "__main__": # pragma: no cover | ||
main(prog_name='semantic-version-check') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import sys | ||
|
||
import click | ||
|
||
from semantic_version_check.main import SemanticVersionFormatError, version_check | ||
|
||
|
||
@click.command() | ||
@click.argument('version') | ||
def main(version): | ||
|
||
try: | ||
version_check(version) | ||
except SemanticVersionFormatError: | ||
sys.exit(1) | ||
|
||
|
||
if __name__ == "__main__": # pragma: no cover | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import re | ||
from typing import Callable, Match, Pattern | ||
|
||
regex = re.compile( | ||
r'^(?P<major>0|[1-9]\d*)' | ||
r'\.' | ||
r'(?P<minor>0|[1-9]\d*)' | ||
r'\.' | ||
r'(?P<patch>0|[1-9]\d*)' | ||
r'(?:-' | ||
r'(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)' | ||
r'(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?' | ||
r'(?:\+' | ||
r'(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' | ||
) | ||
|
||
|
||
class RegExMatcher: | ||
@staticmethod | ||
def match(regex: Pattern, string: str) -> Match: | ||
match_result = regex.match(string) | ||
if not match_result: | ||
raise SemanticVersionFormatError( | ||
"Regex '{regex}' did not match string '{string}'".format( | ||
regex=regex.pattern, string=string | ||
) | ||
) | ||
return match_result | ||
|
||
|
||
# Simple Adapter | ||
class VersionCheck: | ||
def __init__(self, regex_matcher: Callable[[Pattern, str], Match]): | ||
self._regex_matcher = regex_matcher | ||
|
||
def __call__(self, string): | ||
return self._regex_matcher(regex, string) | ||
|
||
|
||
class SemanticVersionFormatError(Exception): | ||
pass | ||
|
||
|
||
# Simple callable | ||
version_check = VersionCheck(RegExMatcher.match) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def version_check(): | ||
from semantic_version_check import version_check | ||
|
||
return version_check | ||
|
||
|
||
@pytest.fixture | ||
def reg_missmath(): | ||
from semantic_version_check.main import SemanticVersionFormatError | ||
|
||
return SemanticVersionFormatError | ||
|
||
|
||
@pytest.fixture | ||
def regex(): | ||
from semantic_version_check import regex | ||
|
||
return regex | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'version', | ||
( | ||
'1.2.0', | ||
'1.0.0', | ||
'200.5.0', | ||
'0.5.0', | ||
'0.0.1', | ||
'1.0.0-alpha', | ||
'0.0.1-alpha.1', | ||
'3.1.5-alpha.beta', | ||
'1.34.6-beta.11', | ||
'1.0.0-alpha-beta', | ||
'1.0.0-alpha-beta-a-b', | ||
'1.0.0-alpha-beta.1.2.3-1-a-s', | ||
'1.34.6-beta.11-1', | ||
'2.0.12-rc.1', | ||
), | ||
) | ||
def test_version_check(version, version_check): | ||
match_object = version_check(version) | ||
assert match_object is not None | ||
assert match_object.group(1) | ||
assert match_object.group(2) | ||
assert match_object.group(3) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'version', | ||
( | ||
'1.0', | ||
'200', | ||
'1', | ||
'0.5', | ||
'1.0-alpha', | ||
'1.0.0.alpha', | ||
'0.1-alpha.1', | ||
'3-alpha.beta', | ||
'34.6-beta.11', | ||
'2.0.12.1-rc.1', | ||
), | ||
) | ||
def test_wrong_version(version, version_check, regex, reg_missmath): | ||
import re | ||
|
||
with pytest.raises( | ||
reg_missmath, | ||
match="Regex '{regex}' did not match string '{string}'".format( | ||
regex=re.escape(regex.pattern), string=version | ||
), | ||
): | ||
version_check(version) |
Oops, something went wrong.