summaryrefslogtreecommitdiff
path: root/tests/test_build.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2016-09-10 16:49:17 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2016-09-10 16:49:17 +0900
commitfae9eb778446c44df0f0ad4173542f3cb97dccc1 (patch)
treeffda2e94e53d25c6d73df47a2d936ee2886d88c3 /tests/test_build.py
parent1d7c82b3bb4127ab48c96c41321608ccfb0241ef (diff)
downloadsphinx-git-fae9eb778446c44df0f0ad4173542f3cb97dccc1.tar.gz
Fix tests are crashed under unstable network
Diffstat (limited to 'tests/test_build.py')
-rw-r--r--tests/test_build.py30
1 files changed, 15 insertions, 15 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index b1f25ea89..82569074d 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -17,7 +17,7 @@ from textwrap import dedent
from sphinx.errors import SphinxError
import sphinx.builders.linkcheck
-from util import with_app, with_tempdir, rootdir, tempdir, SkipTest, TestApp
+from util import mock, with_app, with_tempdir, rootdir, tempdir, SkipTest, TestApp
try:
from docutils.writers.manpage import Writer as ManWriter
@@ -25,14 +25,11 @@ except ImportError:
ManWriter = None
-class MockOpener(object):
- def open(self, req, **kwargs):
- class result(BytesIO):
- headers = None
- url = req.url
- return result()
-
-sphinx.builders.linkcheck.opener = MockOpener()
+def request_session_head(url, **kwargs):
+ response = mock.Mock()
+ response.status_code = 200
+ response.url = url
+ return response
def verify_build(buildername, srcdir):
@@ -68,12 +65,15 @@ def test_build_all():
""" % {'test_name': test_name})
)
- # note: no 'html' - if it's ok with dirhtml it's ok with html
- for buildername in ['dirhtml', 'singlehtml', 'latex', 'texinfo', 'pickle',
- 'json', 'text', 'htmlhelp', 'qthelp', 'epub2', 'epub',
- 'applehelp', 'changes', 'xml', 'pseudoxml', 'man',
- 'linkcheck']:
- yield verify_build, buildername, srcdir
+ with mock.patch('sphinx.builders.linkcheck.requests') as requests:
+ requests.Session().head = request_session_head
+
+ # note: no 'html' - if it's ok with dirhtml it's ok with html
+ for buildername in ['dirhtml', 'singlehtml', 'latex', 'texinfo', 'pickle',
+ 'json', 'text', 'htmlhelp', 'qthelp', 'epub2', 'epub',
+ 'applehelp', 'changes', 'xml', 'pseudoxml', 'man',
+ 'linkcheck']:
+ yield verify_build, buildername, srcdir
@with_tempdir