Skip to content

Commit 8bbd1cd

Browse files
committed
Improve test suite
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
1 parent 28d04af commit 8bbd1cd

File tree

2 files changed

+114
-20
lines changed

2 files changed

+114
-20
lines changed

tests/complex.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
complex - CLI interface
2+
***********************
3+
4+
argparse tester
5+
6+
complex [-h] [--root] [--no-help] [--foo | --bar] {first,f,second,third} ...
7+
8+
9+
optional arguments
10+
==================
11+
12+
* "-h", "--help" - show this help message and exit
13+
14+
* "--root" - root flag (default: "False")
15+
16+
* "--no-help" (default: "False")
17+
18+
19+
Exclusive
20+
=========
21+
22+
this is an exclusive group
23+
24+
* "--foo" - foo (default: "False")
25+
26+
* "--bar" - bar (default: "False")
27+
28+
29+
complex first (f)
30+
=================
31+
32+
a-first-help
33+
34+
complex first [-h] [--flag] [--root] one pos_two
35+
36+
37+
complex first positional arguments
38+
----------------------------------
39+
40+
* "one" - first positional argument (default: "None")
41+
42+
* "pos_two" - second positional argument (default: "1")
43+
44+
45+
complex first optional arguments
46+
--------------------------------
47+
48+
* "-h", "--help" - show this help message and exit
49+
50+
* "--flag" - a parser first flag (default: "False")
51+
52+
* "--root" - root flag (default: "False")
53+
54+
55+
complex second
56+
==============
57+
58+
complex second [-h] [--flag] [--root] one pos_two
59+
60+
61+
complex second positional arguments
62+
-----------------------------------
63+
64+
* "one" - first positional argument (default: "None")
65+
66+
* "pos_two" - second positional argument (default: "green")
67+
68+
69+
complex second optional arguments
70+
---------------------------------
71+
72+
* "-h", "--help" - show this help message and exit
73+
74+
* "--flag" - a parser second flag (default: "False")
75+
76+
* "--root" - root flag (default: "False")
77+
78+
79+
complex third
80+
=============
81+
82+
complex third [-h]
83+
84+
85+
complex third optional arguments
86+
--------------------------------
87+
88+
* "-h", "--help" - show this help message and exit

tests/test_logic.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,45 @@
33
from pathlib import Path
44

55
import pytest
6+
from _pytest.fixtures import SubRequest
67
from sphinx.testing.util import SphinxTestApp
78

89

9-
@pytest.mark.sphinx("html", testroot="basic")
10-
def test_basic_as_html(app: SphinxTestApp) -> None:
10+
@pytest.fixture()
11+
def build_outcome(app: SphinxTestApp, request: SubRequest) -> str:
1112
app.build()
12-
outcome = (Path(app.outdir) / "index.html").read_text()
13-
assert outcome
13+
ext = {"html": "html", "text": "txt"}
14+
ext = ext.get(request.node.get_closest_marker("sphinx").args[0])
15+
assert ext is not None
16+
return (Path(app.outdir) / f"index.{ext}").read_text()
17+
18+
19+
@pytest.mark.sphinx("html", testroot="basic")
20+
def test_basic_as_html(build_outcome: str) -> None:
21+
assert build_outcome
22+
23+
24+
@pytest.mark.sphinx("text", testroot="complex")
25+
def test_complex_as_text(build_outcome: str) -> None:
26+
expected = (Path(__file__).parent / "complex.txt").read_text()
27+
assert build_outcome == expected
1428

1529

1630
@pytest.mark.sphinx("html", testroot="complex")
17-
def test_complex_as_html(app: SphinxTestApp) -> None:
18-
app.build()
19-
outcome = (Path(app.outdir) / "index.html").read_text()
20-
assert outcome
31+
def test_complex_as_html(build_outcome: str) -> None:
32+
assert build_outcome
2133

2234

2335
@pytest.mark.sphinx("text", testroot="prog")
24-
def test_prog_as_text(app: SphinxTestApp) -> None:
25-
app.build()
26-
outcome = (Path(app.outdir) / "index.txt").read_text()
27-
assert outcome == "magic - CLI interface\n*********************\n\n magic\n"
36+
def test_prog_as_text(build_outcome: str) -> None:
37+
assert build_outcome == "magic - CLI interface\n*********************\n\n magic\n"
2838

2939

3040
@pytest.mark.sphinx("text", testroot="title-set")
31-
def test_set_title_as_text(app: SphinxTestApp) -> None:
32-
app.build()
33-
outcome = (Path(app.outdir) / "index.txt").read_text()
34-
assert outcome == "My own title\n************\n\n foo\n"
41+
def test_set_title_as_text(build_outcome: str) -> None:
42+
assert build_outcome == "My own title\n************\n\n foo\n"
3543

3644

3745
@pytest.mark.sphinx("text", testroot="title-empty")
38-
def test_empty_title_as_text(app: SphinxTestApp) -> None:
39-
app.build()
40-
outcome = (Path(app.outdir) / "index.txt").read_text()
41-
assert outcome == " foo\n"
46+
def test_empty_title_as_text(build_outcome: str) -> None:
47+
assert build_outcome == " foo\n"

0 commit comments

Comments
 (0)