Skip to content

Commit 76206f9

Browse files
akbakb
authored andcommitted
Add tests
1 parent b7ed1b8 commit 76206f9

File tree

7 files changed

+125
-17
lines changed

7 files changed

+125
-17
lines changed

dev-requirements.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --output-file=dev-requirements.txt dev-requirements.in
6+
#
7+
ansicolors==1.0.2 # via cuvner
8+
appdirs==1.4.3 # via black
9+
argh==0.26.2 # via watchdog
10+
astroid==2.2.5 # via pylint
11+
atomicwrites==1.3.0 # via pytest
12+
attrs==19.1.0 # via black, pytest
13+
black==19.3b0
14+
bleach==3.1.0 # via readme-renderer
15+
bump2version==0.5.10
16+
check-manifest==0.39
17+
click==7.0 # via black, cuvner, towncrier
18+
coverage==4.5.3
19+
cuvner==18.0.1
20+
docutils==0.14
21+
filelock==3.0.12 # via tox
22+
importlib-metadata==0.18 # via pluggy, pytest, tox
23+
incremental==17.5.0 # via cuvner, towncrier
24+
isort==4.3.21
25+
jinja2==2.10.1 # via towncrier
26+
lazy-object-proxy==1.4.1 # via astroid
27+
markupsafe==1.1.1 # via jinja2
28+
mccabe==0.6.1 # via pylint
29+
more-itertools==7.1.0 # via pytest
30+
mypy-extensions==0.4.1 # via mypy
31+
mypy==0.720
32+
packaging==19.0 # via pytest, tox
33+
pathtools==0.1.2 # via watchdog
34+
pex==1.6.8
35+
pluggy==0.12.0 # via pytest, tox
36+
py==1.8.0 # via pytest, tox
37+
pygments==2.4.2
38+
pylint==2.3.1
39+
pyparsing==2.4.0 # via packaging
40+
pytest-sphinx==0.2.2
41+
pytest==5.0.1
42+
pyyaml==5.1.1 # via watchdog
43+
readme-renderer==24.0
44+
six==1.12.0 # via astroid, bleach, cuvner, packaging, readme-renderer, tox
45+
toml==0.10.0 # via black, check-manifest, towncrier, tox
46+
towncrier==19.2.0
47+
tox==3.13.2
48+
typed-ast==1.4.0 # via astroid, mypy
49+
typing-extensions==3.7.4 # via mypy
50+
unidiff==0.5.5 # via cuvner
51+
versioneer==0.18
52+
virtualenv==16.6.2 # via tox
53+
watchdog==0.9.0 # via cuvner
54+
wcwidth==0.1.7 # via pytest
55+
webencodings==0.5.1 # via bleach
56+
wrapt==1.11.2 # via astroid
57+
zipp==0.5.2 # via importlib-metadata

requirements.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
2-
click
1+
pyyaml
2+
lxml

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
# This file is autogenerated by pip-compile
33
# To update, run:
44
#
5-
# pip-compile --generate-hashes --output-file=requirements.txt setup.py
5+
# pip-compile --output-file=requirements.txt requirements.in
66
#
7-
click==7.0 \
8-
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
9-
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7
7+
lxml==4.3.4
8+
pyyaml==5.1.1

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ default_section = THIRDPARTY
3131
forced_separate = test_mario_addons
3232
not_skip = __init__.py
3333
skip = migrations
34-
known_third_party=click,mario,requests,setuptools,toml
34+
known_third_party=click,mario,pytest,requests,setuptools,toml
3535
ignore =
3636
.flake8
3737
dev-requirements.in

src/mario_addons/plugins/addons.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88

99
registry = plug.make_plugin_aliases_registry("mario_addons.plugins")
10-
print(registry)
11-
# TODO Add test cases in the toml.
1210

1311

1412
def read_csv(

src/mario_addons/plugins/addons.toml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
short_help = "Convert yaml to json"
77

88
[[alias.stage]]
9-
109
command = "stack"
1110
options = {code="yaml.safe_load ! json.dumps"}
1211

12+
[[alias.test_spec]]
13+
invocation = ["yml2json"]
14+
input = '''{"x": 1,}
15+
'''
16+
output = '''{"x": 1}
17+
'''
18+
19+
1320
### Search for xpath elements with xpath
1421

1522
[[alias]]
@@ -26,6 +33,22 @@
2633
[[alias.stage]]
2734
command="chain"
2835

36+
37+
[[alias.test_spec]]
38+
invocation = ["xpath", "//", "map", "x.text"]
39+
input = """
40+
<slide type="all">
41+
<title>Overview</title>
42+
<item>Anything in here</item>
43+
</slide>
44+
"""
45+
output = """
46+
Overview
47+
Anything in here
48+
"""
49+
50+
51+
2952
### Generate json objects
3053

3154
[[alias]]
@@ -60,6 +83,12 @@
6083
options = {code="json.dumps"}
6184

6285

86+
[[alias.test_spec]]
87+
invocation = ["jo", "x=1 y=2"]
88+
input = ""
89+
output = "{\"x\": 1, \"y\": 2}\n"
90+
91+
6392
[[alias]]
6493

6594
name = "jsonl"
@@ -97,3 +126,15 @@ options = {code="json.loads"}
97126
[[alias.stage]]
98127
command = "map"
99128
options = {code="dict(x)"}
129+
130+
[[alias.test_spec]]
131+
invocation = ["csv"]
132+
input = """
133+
name,age
134+
Alice,21
135+
Bob,22
136+
"""
137+
output = """
138+
{'name': 'Alice', 'age': '21'}
139+
{'name': 'Bob', 'age': '22'}
140+
"""

tests/test_mario_addons.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1-
from click.testing import CliRunner
1+
import subprocess
2+
import sys
23

3-
from mario_addons.cli import main
4+
import mario.aliasing
5+
import pytest
46

7+
import mario_addons.plugins.addons
58

6-
def test_main():
7-
runner = CliRunner()
8-
result = runner.invoke(main, [])
99

10-
assert result.output == "()\n"
11-
assert result.exit_code == 0
10+
SPECS = [
11+
spec
12+
for alias in mario_addons.plugins.addons.registry.aliases.values()
13+
for spec in alias.test_specs
14+
]
15+
16+
17+
@pytest.mark.parametrize("test_spec", SPECS)
18+
def test_alias_test_spec(test_spec: mario.aliasing.AliasTestSpec):
19+
20+
output = subprocess.check_output(
21+
[sys.executable, "-m", "mario"] + test_spec.invocation,
22+
input=test_spec.input.encode(),
23+
).decode()
24+
assert output == test_spec.output

0 commit comments

Comments
 (0)