6
6
7
7
from projects .tasks import build_docs
8
8
from rtd_tests .factories .projects_factories import ProjectFactory
9
+ from rtd_tests .mocks .paths import fake_paths_lookup
9
10
from doc_builder .loader import get_builder_class
10
11
11
12
@@ -29,22 +30,6 @@ def build_subprocess_side_effect(*args, **kwargs):
29
30
return subprocess .Popen (* args , ** kwargs )
30
31
31
32
32
- def fake_paths (* paths ):
33
- """
34
- Returns a context manager that patches ``os.path.exists`` to return
35
- ``True`` for the given ``paths``.
36
- """
37
-
38
- original_exists = os .path .exists
39
-
40
- def patched_exists (path ):
41
- if path in paths :
42
- return True
43
- return original_exists (path )
44
-
45
- return mock .patch .object (os .path , 'exists' , patched_exists )
46
-
47
-
48
33
class BuildTests (TestCase ):
49
34
50
35
@mock .patch ('slumber.Resource' )
@@ -68,11 +53,13 @@ def test_build(self, mock_Popen, mock_api_versions, mock_chdir, mock_apiv2_downl
68
53
69
54
mock_apiv2_downloads .get .return_value = {'downloads' : "no_url_here" }
70
55
71
- conf_path = os .path .join (project .checkout_path (version .slug ), project .conf_py_file )
56
+ conf_path = os .path .join (
57
+ project .checkout_path (version .slug ),
58
+ project .conf_py_file )
72
59
73
60
# Mock open to simulate existing conf.py file
74
61
with mock .patch ('codecs.open' , mock .mock_open (), create = True ):
75
- with fake_paths ( conf_path ):
62
+ with fake_paths_lookup ({ conf_path : True } ):
76
63
built_docs = build_docs (version ,
77
64
False ,
78
65
False ,
@@ -136,7 +123,7 @@ def test_build_respects_pdf_flag(self,
136
123
137
124
# Mock open to simulate existing conf.py file
138
125
with mock .patch ('codecs.open' , mock .mock_open (), create = True ):
139
- with fake_paths ( conf_path ):
126
+ with fake_paths_lookup ({ conf_path : True } ):
140
127
built_docs = build_docs (version ,
141
128
False ,
142
129
False ,
@@ -180,7 +167,7 @@ def test_build_respects_epub_flag(self,
180
167
181
168
# Mock open to simulate existing conf.py file
182
169
with mock .patch ('codecs.open' , mock .mock_open (), create = True ):
183
- with fake_paths ( conf_path ):
170
+ with fake_paths_lookup ({ conf_path : True } ):
184
171
built_docs = build_docs (version ,
185
172
False ,
186
173
False ,
0 commit comments