Skip to content

Commit 422c7ab

Browse files
committed
Fake paths with endswith
1 parent faf2d39 commit 422c7ab

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

readthedocs/rtd_tests/tests/test_builds.py

+27-37
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from readthedocs.doc_builder.environments import LocalBuildEnvironment
1818
from readthedocs.doc_builder.python_environments import Virtualenv
1919
from readthedocs.projects.models import Project, EnvironmentVariable
20-
from readthedocs.projects.tasks import UpdateDocsTaskStep
2120
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+
2323
from ..mocks.environment import EnvironmentMockGroup
2424

2525

@@ -80,14 +80,12 @@ def test_build_generate_index_file_force(self):
8080
python_env = Virtualenv(version=version, build_env=build_env)
8181
base_builder = MkdocsHTML(build_env, python_env)
8282

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+
}
8987

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):
9189
result = base_builder.create_index(extension='md', force_index=True)
9290
mock_open.assert_called_once_with(
9391
os.path.join(base_builder.docs_dir(), 'index.md'), 'w+'
@@ -113,14 +111,12 @@ def test_build_get_index_file_force(self):
113111
python_env = Virtualenv(version=version, build_env=build_env)
114112
base_builder = MkdocsHTML(build_env, python_env)
115113

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+
}
122118

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):
124120
result = base_builder.create_index(extension='md', force_index=True)
125121
self.assertEqual(len(mock_open.mock_calls), 0)
126122
self.assertEqual(result, 'index')
@@ -144,14 +140,12 @@ def test_build_generate_index_file(self):
144140
python_env = Virtualenv(version=version, build_env=build_env)
145141
base_builder = SphinxHTML(build_env, python_env)
146142

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+
}
153147

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):
155149
result = base_builder.create_index(extension='md')
156150
mock_open.assert_called_once_with(
157151
os.path.join(base_builder.docs_dir(), 'index.md'), 'w+'
@@ -177,14 +171,12 @@ def test_get_readme_file(self):
177171
python_env = Virtualenv(version=version, build_env=build_env)
178172
base_builder = SphinxHTML(build_env, python_env)
179173

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+
}
186178

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):
188180
result = base_builder.create_index(extension='md')
189181
self.assertEqual(len(mock_open.mock_calls), 0)
190182
self.assertEqual(result, 'README')
@@ -208,14 +200,12 @@ def test_get_index_file(self):
208200
python_env = Virtualenv(version=version, build_env=build_env)
209201
base_builder = SphinxHTML(build_env, python_env)
210202

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+
}
217207

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):
219209
result = base_builder.create_index(extension='md')
220210
self.assertEqual(len(mock_open.mock_calls), 0)
221211
self.assertEqual(result, 'index')

0 commit comments

Comments
 (0)