15
15
from readthedocs .doc_builder .python_environments import Virtualenv
16
16
from readthedocs .projects .models import Project
17
17
from readthedocs .projects .tasks import UpdateDocsTask
18
- from readthedocs .rtd_tests .mocks .paths import fake_paths
18
+ from readthedocs .rtd_tests .mocks .paths import fake_paths_by_endswith
19
19
from readthedocs .rtd_tests .tests .test_config_wrapper import create_load
20
20
21
21
from ..mocks .environment import EnvironmentMockGroup
@@ -76,14 +76,12 @@ def test_build_generate_index_file_force(self):
76
76
python_env = Virtualenv (version = version , build_env = build_env )
77
77
base_builder = MkdocsHTML (build_env , python_env )
78
78
79
- def look_index_path (path ):
80
- if path .endswith ('README.md' ):
81
- return True
82
- elif path .endswith ('index.md' ):
83
- return False
84
- return False
79
+ paths = {
80
+ 'README.md' : True ,
81
+ 'index.md' : False ,
82
+ }
85
83
86
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
84
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
87
85
result = base_builder .create_index (extension = 'md' , force_index = True )
88
86
mock_open .assert_called_once_with (
89
87
os .path .join (base_builder .docs_dir (), 'index.md' ), 'w+'
@@ -109,14 +107,12 @@ def test_build_get_index_file_force(self):
109
107
python_env = Virtualenv (version = version , build_env = build_env )
110
108
base_builder = MkdocsHTML (build_env , python_env )
111
109
112
- def look_index_path (path ):
113
- if path .endswith ('README.md' ):
114
- return True
115
- elif path .endswith ('index.md' ):
116
- return True
117
- return False
110
+ paths = {
111
+ 'README.md' : True ,
112
+ 'index.md' : True ,
113
+ }
118
114
119
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
115
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
120
116
result = base_builder .create_index (extension = 'md' , force_index = True )
121
117
self .assertEqual (len (mock_open .mock_calls ), 0 )
122
118
self .assertEqual (result , 'index' )
@@ -140,14 +136,12 @@ def test_build_generate_index_file(self):
140
136
python_env = Virtualenv (version = version , build_env = build_env )
141
137
base_builder = SphinxHTML (build_env , python_env )
142
138
143
- def look_index_path (path ):
144
- if path .endswith ('README.md' ):
145
- return False
146
- elif path .endswith ('index.md' ):
147
- return False
148
- return False
139
+ paths = {
140
+ 'README.md' : False ,
141
+ 'index,md' : False ,
142
+ }
149
143
150
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
144
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
151
145
result = base_builder .create_index (extension = 'md' )
152
146
mock_open .assert_called_once_with (
153
147
os .path .join (base_builder .docs_dir (), 'index.md' ), 'w+'
@@ -173,14 +167,12 @@ def test_get_readme_file(self):
173
167
python_env = Virtualenv (version = version , build_env = build_env )
174
168
base_builder = SphinxHTML (build_env , python_env )
175
169
176
- def look_index_path (path ):
177
- if path .endswith ('README.md' ):
178
- return True
179
- elif path .endswith ('index.md' ):
180
- return False
181
- return False
170
+ paths = {
171
+ 'README.md' : True ,
172
+ 'index.md' : False ,
173
+ }
182
174
183
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
175
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
184
176
result = base_builder .create_index (extension = 'md' )
185
177
self .assertEqual (len (mock_open .mock_calls ), 0 )
186
178
self .assertEqual (result , 'README' )
@@ -204,14 +196,12 @@ def test_get_index_file(self):
204
196
python_env = Virtualenv (version = version , build_env = build_env )
205
197
base_builder = SphinxHTML (build_env , python_env )
206
198
207
- def look_index_path (path ):
208
- if path .endswith ('README.md' ):
209
- return False
210
- elif path .endswith ('index.md' ):
211
- return True
212
- return False
199
+ paths = {
200
+ 'README.md' : False ,
201
+ 'index.md' : True ,
202
+ }
213
203
214
- with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths ( look_index_path ):
204
+ with mock .patch ('readthedocs.doc_builder.base.open' , mock .mock_open ()) as mock_open , fake_paths_by_endswith ( paths ):
215
205
result = base_builder .create_index (extension = 'md' )
216
206
self .assertEqual (len (mock_open .mock_calls ), 0 )
217
207
self .assertEqual (result , 'index' )
0 commit comments