17
17
from readthedocs .doc_builder .environments import LocalBuildEnvironment
18
18
from readthedocs .doc_builder .python_environments import Virtualenv
19
19
from readthedocs .projects .models import Project , EnvironmentVariable
20
- from readthedocs .projects .tasks import UpdateDocsTaskStep
21
20
from readthedocs .rtd_tests .tests .test_config_integration import create_load
22
- from readthedocs .rtd_tests .mocks .paths import fake_paths
21
+ from readthedocs .rtd_tests .mocks .paths import fake_paths_by_endswith
22
+
23
23
from ..mocks .environment import EnvironmentMockGroup
24
24
25
25
@@ -80,14 +80,12 @@ def test_build_generate_index_file_force(self):
80
80
python_env = Virtualenv (version = version , build_env = build_env )
81
81
base_builder = MkdocsHTML (build_env , python_env )
82
82
83
- def look_index_path (path ):
84
- if path .endswith ('README.md' ):
85
- return True
86
- elif path .endswith ('index.md' ):
87
- return False
88
- return False
83
+ paths = {
84
+ 'README.md' : True ,
85
+ 'index.md' : False ,
86
+ }
89
87
90
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
88
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
91
89
result = base_builder .create_index (extension = 'md' , force_index = True )
92
90
mock_open .assert_called_once_with (
93
91
os .path .join (base_builder .docs_dir (), 'index.md' ), 'w+'
@@ -113,14 +111,12 @@ def test_build_get_index_file_force(self):
113
111
python_env = Virtualenv (version = version , build_env = build_env )
114
112
base_builder = MkdocsHTML (build_env , python_env )
115
113
116
- def look_index_path (path ):
117
- if path .endswith ('README.md' ):
118
- return True
119
- elif path .endswith ('index.md' ):
120
- return True
121
- return False
114
+ paths = {
115
+ 'README.md' : True ,
116
+ 'index.md' : True ,
117
+ }
122
118
123
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
119
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
124
120
result = base_builder .create_index (extension = 'md' , force_index = True )
125
121
self .assertEqual (len (mock_open .mock_calls ), 0 )
126
122
self .assertEqual (result , 'index' )
@@ -144,14 +140,12 @@ def test_build_generate_index_file(self):
144
140
python_env = Virtualenv (version = version , build_env = build_env )
145
141
base_builder = SphinxHTML (build_env , python_env )
146
142
147
- def look_index_path (path ):
148
- if path .endswith ('README.md' ):
149
- return False
150
- elif path .endswith ('index.md' ):
151
- return False
152
- return False
143
+ paths = {
144
+ 'README.md' : False ,
145
+ 'index,md' : False ,
146
+ }
153
147
154
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
148
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
155
149
result = base_builder .create_index (extension = 'md' )
156
150
mock_open .assert_called_once_with (
157
151
os .path .join (base_builder .docs_dir (), 'index.md' ), 'w+'
@@ -177,14 +171,12 @@ def test_get_readme_file(self):
177
171
python_env = Virtualenv (version = version , build_env = build_env )
178
172
base_builder = SphinxHTML (build_env , python_env )
179
173
180
- def look_index_path (path ):
181
- if path .endswith ('README.md' ):
182
- return True
183
- elif path .endswith ('index.md' ):
184
- return False
185
- return False
174
+ paths = {
175
+ 'README.md' : True ,
176
+ 'index.md' : False ,
177
+ }
186
178
187
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
179
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
188
180
result = base_builder .create_index (extension = 'md' )
189
181
self .assertEqual (len (mock_open .mock_calls ), 0 )
190
182
self .assertEqual (result , 'README' )
@@ -208,14 +200,12 @@ def test_get_index_file(self):
208
200
python_env = Virtualenv (version = version , build_env = build_env )
209
201
base_builder = SphinxHTML (build_env , python_env )
210
202
211
- def look_index_path (path ):
212
- if path .endswith ('README.md' ):
213
- return False
214
- elif path .endswith ('index.md' ):
215
- return True
216
- return False
203
+ paths = {
204
+ 'README.md' : False ,
205
+ 'index.md' : True ,
206
+ }
217
207
218
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
208
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
219
209
result = base_builder .create_index (extension = 'md' )
220
210
self .assertEqual (len (mock_open .mock_calls ), 0 )
221
211
self .assertEqual (result , 'index' )
0 commit comments