Skip to content

Commit 635198c

Browse files
committed
add first simple test
1 parent 0f1638f commit 635198c

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Provide some base configurations for tests."""
2+
import pytest
3+
import py.path # pyright: reportMissingModuleSource=false
4+
5+
6+
TEST_CASES_PATH = py.path.local(__file__).realpath() / '..' / 'test_cases'
7+
8+
9+
def find_all_test_cases():
10+
"""Generate list of test cases.
11+
12+
:yield: generates each test case as list item
13+
:rtype: str
14+
"""
15+
for c in TEST_CASES_PATH.listdir(sort=True):
16+
c = c.basename
17+
if c.endswith('.py'):
18+
yield c.replace('.py', '')
19+
20+
21+
TEST_CASES = list(find_all_test_cases())
22+
23+
24+
def pytest_addoption(parser):
25+
"""Change command line options defaults.
26+
27+
We want run our tests only in three modes
28+
`live` - interact with an existing API
29+
`record` - interact with an existing API and record the interactions
30+
`replay` - replay previouly recorded interactions with API
31+
32+
:param parser: A parser object
33+
:type parser: object parser
34+
"""
35+
parser.addoption(
36+
"--vcrmode",
37+
action="store",
38+
default="replay",
39+
choices=["replay", "record", "live"],
40+
help="mode for vcr recording; one of ['replay', 'record', 'live']",
41+
)
42+
43+
44+
@pytest.fixture
45+
def vcrmode(request):
46+
"""Return vcrmode of a request.
47+
48+
:param request: A request object
49+
:type request: object request
50+
:return: vcrmode
51+
:rtype: str
52+
"""
53+
return request.config.getoption("vcrmode")
54+
55+
56+
def cassette_name(test_name=None):
57+
"""Generate cassette_name."""
58+
return 'tests/fixtures/{0}.yml'.format(test_name)

tests/test_cases/coding.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
import click
3+
4+
from click_types.coding import SemVerParamType
5+
6+
semver = SemVerParamType()
7+
8+
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))
12+
13+
14+
if __name__ == "__main__":
15+
while True:
16+
test_semver()

0 commit comments

Comments
 (0)