From fae9eb778446c44df0f0ad4173542f3cb97dccc1 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 10 Sep 2016 16:49:17 +0900 Subject: [PATCH] Fix tests are crashed under unstable network --- tests/test_build.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_build.py b/tests/test_build.py index b1f25ea897..82569074d1 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