Skip to content

Commit a788898

Browse files
committed
Fake paths with endswith
1 parent 2ab59cb commit a788898

File tree

1 file changed

+26
-36
lines changed

1 file changed

+26
-36
lines changed

readthedocs/rtd_tests/tests/test_builds.py

+26-36
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from readthedocs.doc_builder.python_environments import Virtualenv
1616
from readthedocs.projects.models import Project
1717
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
1919
from readthedocs.rtd_tests.tests.test_config_wrapper import create_load
2020

2121
from ..mocks.environment import EnvironmentMockGroup
@@ -76,14 +76,12 @@ def test_build_generate_index_file_force(self):
7676
python_env = Virtualenv(version=version, build_env=build_env)
7777
base_builder = MkdocsHTML(build_env, python_env)
7878

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

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):
8785
result = base_builder.create_index(extension='md', force_index=True)
8886
mock_open.assert_called_once_with(
8987
os.path.join(base_builder.docs_dir(), 'index.md'), 'w+'
@@ -109,14 +107,12 @@ def test_build_get_index_file_force(self):
109107
python_env = Virtualenv(version=version, build_env=build_env)
110108
base_builder = MkdocsHTML(build_env, python_env)
111109

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

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):
120116
result = base_builder.create_index(extension='md', force_index=True)
121117
self.assertEqual(len(mock_open.mock_calls), 0)
122118
self.assertEqual(result, 'index')
@@ -140,14 +136,12 @@ def test_build_generate_index_file(self):
140136
python_env = Virtualenv(version=version, build_env=build_env)
141137
base_builder = SphinxHTML(build_env, python_env)
142138

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

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):
151145
result = base_builder.create_index(extension='md')
152146
mock_open.assert_called_once_with(
153147
os.path.join(base_builder.docs_dir(), 'index.md'), 'w+'
@@ -173,14 +167,12 @@ def test_get_readme_file(self):
173167
python_env = Virtualenv(version=version, build_env=build_env)
174168
base_builder = SphinxHTML(build_env, python_env)
175169

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

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):
184176
result = base_builder.create_index(extension='md')
185177
self.assertEqual(len(mock_open.mock_calls), 0)
186178
self.assertEqual(result, 'README')
@@ -204,14 +196,12 @@ def test_get_index_file(self):
204196
python_env = Virtualenv(version=version, build_env=build_env)
205197
base_builder = SphinxHTML(build_env, python_env)
206198

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

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

0 commit comments

Comments
 (0)