Skip to content

Commit 0b9b28c

Browse files
committed
Working on coding types and tests
We create a valid pytest for the coding module, exactly a test for the only type `SemverParamType`. For that type we also fix a deprecation related finding.
1 parent 84d85f2 commit 0b9b28c

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

click_types/coding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def convert(self, value, param, ctx):
2828
:rtype: str
2929
"""
3030
try:
31-
semver.parse(value)
31+
semver.VersionInfo.parse(value)
3232
return value
3333
except ValueError as e:
3434
self.fail('Not a valid version, {0}'.format(str(e)), param, ctx)

tests/test_cases/coding.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1-
#!/usr/bin/env python
21
import click
32

3+
from click.testing import CliRunner
44
from click_types.coding import SemVerParamType
55

66
semver = SemVerParamType()
7+
runner = CliRunner()
78

89

9-
def test_semver():
10-
version = click.prompt("Enter semantic version", type=semver)
11-
click.echo('Passed: Valid version, {0} is a valid SemVer string'.format(version))
10+
@click.command()
11+
@click.option('--version', type=semver)
12+
def semver_wrapper(version):
13+
pass
1214

1315

14-
if __name__ == "__main__":
15-
while True:
16-
test_semver()
16+
def test_success():
17+
18+
positive_semvers = [
19+
'1.2.3',
20+
'1.2.3-alpha',
21+
'1.2.3-beta+build1337'
22+
]
23+
for s in positive_semvers:
24+
print(s)
25+
response = runner.invoke(semver_wrapper, ['--version', s])
26+
assert response.exit_code == 0
27+
28+
29+
def test_failure():
30+
31+
negative_semvers = [
32+
'1.2',
33+
'1.2.3+build1337',
34+
'1.2.3-alpha-build4711'
35+
]
36+
37+
for s in negative_semvers:
38+
response = runner.invoke(semver, ['--version', s])
39+
assert response.exit_code == 1

0 commit comments

Comments
 (0)