1
- # stdlib
2
- import sys
3
-
4
1
# 3rd party
5
2
import pytest
6
- import tox # type: ignore
7
- import tox .reporter # type: ignore
8
3
from coincidence .selectors import not_pypy
9
- from domdf_python_tools .paths import in_directory
10
-
4
+ from testing_tox import run_tox
11
5
12
- def test_rmdir_docs (tmp_pathplus , capsys ):
13
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
14
6
7
+ @pytest .fixture ()
8
+ def basic_docs_testenv (tmp_pathplus ):
15
9
build_dir = tmp_pathplus / "doc-source" / "build"
16
-
17
10
build_dir .mkdir (parents = True )
18
11
19
12
(tmp_pathplus / "tox.ini" ).write_lines ([
20
13
"[testenv:docs]" ,
21
14
"deps = sphinx" ,
22
15
"skip_install = True" ,
23
16
"commands = sphinx-build --version" ,
24
- 'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")' ,
25
17
])
26
18
27
- try :
28
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
29
- tox .cmdline (["-e" , "docs" , "-r" ])
19
+ return build_dir
30
20
21
+
22
+ def test_rmdir_docs (basic_docs_testenv , tmp_pathplus , capsys ):
23
+ with (tmp_pathplus / "tox.ini" ).open ('a' ) as fp :
24
+ fp .write ('recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")\n ' )
25
+
26
+ try :
27
+ run_tox (["-e" , "docs" , "-r" ], tmp_pathplus )
31
28
finally :
32
29
stdout = capsys .readouterr ().out
33
30
print (stdout )
34
31
35
32
assert (tmp_pathplus / "doc-source" ).is_dir ()
36
- assert not build_dir .is_dir ()
33
+ assert not basic_docs_testenv .is_dir ()
37
34
38
- assert f"docs recreate hook: removing { build_dir } " in stdout
35
+ assert f"docs recreate hook: removing { basic_docs_testenv } " in stdout
39
36
40
37
41
38
@not_pypy ("mypy does noy support PyPy" )
42
39
def test_rmdir_mypy (tmp_pathplus , capsys ):
43
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
44
40
45
41
cache_dir = tmp_pathplus / ".mypy_cache"
46
-
47
42
cache_dir .mkdir ()
48
43
49
44
(tmp_pathplus / "tox.ini" ).write_lines ([
@@ -55,127 +50,70 @@ def test_rmdir_mypy(tmp_pathplus, capsys):
55
50
])
56
51
57
52
try :
58
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
59
- tox .cmdline (["-e" , "mypy" , "-r" ])
60
-
53
+ run_tox (["-e" , "mypy" , "-r" ], tmp_pathplus )
61
54
finally :
62
55
stdout = capsys .readouterr ().out
63
56
print (stdout )
64
57
65
- stdout = capsys .readouterr ().out
66
- print (stdout )
67
-
68
58
assert not cache_dir .is_dir ()
69
59
70
60
assert f"mypy recreate hook: removing { cache_dir } " in stdout
71
61
72
62
73
- def test_simple_custom_hook (tmp_pathplus , capsys ):
74
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
75
-
76
- (tmp_pathplus / "tox.ini" ).write_lines ([
77
- "[testenv:docs]" ,
78
- "deps = sphinx" ,
79
- "skip_install = True" ,
80
- "commands = sphinx-build --version" ,
81
- 'recreate_hook = "hello world"' ,
82
- ])
63
+ def test_simple_custom_hook (basic_docs_testenv , tmp_pathplus , capsys ):
64
+ with (tmp_pathplus / "tox.ini" ).open ('a' ) as fp :
65
+ fp .write ('recreate_hook = "hello world"' )
83
66
84
67
try :
85
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
86
- tox .cmdline (["-e" , "docs" , "-r" ])
87
-
68
+ run_tox (["-e" , "docs" , "-r" ], tmp_pathplus )
88
69
finally :
89
70
stdout = capsys .readouterr ().out
90
71
print (stdout )
91
72
92
- stdout = capsys .readouterr ().out
93
- print (stdout )
94
-
95
73
assert f"docs recreate hook: hello world" in stdout
96
74
97
75
98
- def test_custom_hook (tmp_pathplus , capsys ):
99
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
100
-
101
- (tmp_pathplus / "tox.ini" ).write_lines ([
102
- "[testenv:docs]" ,
103
- "deps = sphinx" ,
104
- "skip_install = True" ,
105
- "commands = sphinx-build --version" ,
106
- "recreate_hook = custom_hook.custom_hook()" ,
107
- ])
76
+ def test_custom_hook (basic_docs_testenv , tmp_pathplus , capsys ):
77
+ with (tmp_pathplus / "tox.ini" ).open ('a' ) as fp :
78
+ fp .write ('recreate_hook = custom_hook.custom_hook()\n ' )
108
79
109
80
(tmp_pathplus / "custom_hook.py" ).write_lines ([
110
81
"def custom_hook() -> str:" ,
111
82
'\t return "this is a custom hook"' ,
112
83
])
113
84
114
85
try :
115
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
116
- tox .cmdline (["-e" , "docs" , "-r" ])
117
-
86
+ run_tox (["-e" , "docs" , "-r" ], tmp_pathplus )
118
87
finally :
119
88
stdout = capsys .readouterr ().out
120
89
print (stdout )
121
90
122
- stdout = capsys .readouterr ().out
123
- print (stdout )
124
-
125
91
assert f"docs recreate hook: this is a custom hook" in stdout
126
92
127
93
128
- def test_no_hook (tmp_pathplus , capsys ):
129
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
130
-
131
- (tmp_pathplus / "tox.ini" ).write_lines ([
132
- "[testenv:docs]" ,
133
- "deps = sphinx" ,
134
- "skip_install = True" ,
135
- "commands = sphinx-build --version" ,
136
- ])
94
+ def test_no_hook (basic_docs_testenv , tmp_pathplus , capsys ):
137
95
138
96
try :
139
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
140
- tox .cmdline (["-e" , "docs" , "-r" ])
97
+ run_tox (["-e" , "docs" , "-r" ], tmp_pathplus )
141
98
142
99
finally :
143
100
stdout = capsys .readouterr ().out
144
101
print (stdout )
145
102
146
- stdout = capsys .readouterr ().out
147
- print (stdout )
148
-
149
103
assert "docs recreate hook: " not in stdout
150
104
151
105
152
- def test_not_recreate (tmp_pathplus , capsys ):
153
- tox .reporter ._INSTANCE .tw ._file = sys .stdout
154
-
155
- build_dir = tmp_pathplus / "doc-source" / "build"
156
-
157
- build_dir .mkdir (parents = True )
158
-
159
- (tmp_pathplus / "tox.ini" ).write_lines ([
160
- "[testenv:docs]" ,
161
- "deps = sphinx" ,
162
- "skip_install = True" ,
163
- "commands = sphinx-build --version" ,
164
- 'recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")' ,
165
- ])
106
+ def test_not_recreate (basic_docs_testenv , tmp_pathplus , capsys ):
107
+ with (tmp_pathplus / "tox.ini" ).open ('a' ) as fp :
108
+ fp .write ('recreate_hook = builtin.rmdir(r"{toxinidir}/doc-source/build")\n ' )
166
109
167
110
try :
168
- with pytest .raises (SystemExit ), in_directory (tmp_pathplus ):
169
- tox .cmdline (["-e" , "docs" ])
170
-
111
+ run_tox (["-e" , "docs" ], tmp_pathplus )
171
112
finally :
172
113
stdout = capsys .readouterr ().out
173
114
print (stdout )
174
115
175
- stdout = capsys .readouterr ().out
176
- print (stdout )
177
-
178
116
assert (tmp_pathplus / "doc-source" ).is_dir ()
179
- assert build_dir .is_dir ()
117
+ assert basic_docs_testenv .is_dir ()
180
118
181
119
assert "docs recreate hook: " not in stdout
0 commit comments