def test_status_iterator(app, status, warning): logging.setup(app, status, warning) # test for old_status_iterator status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ')) output = strip_escseq(status.getvalue()) assert 'testing ... hello sphinx world \n' in output assert yields == ['hello', 'sphinx', 'world'] # test for status_iterator (verbosity=0) status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ', length=3, verbosity=0)) output = strip_escseq(status.getvalue()) assert 'testing ... [ 33%] hello \r' in output assert 'testing ... [ 66%] sphinx \r' in output assert 'testing ... [100%] world \r\n' in output assert yields == ['hello', 'sphinx', 'world'] # test for status_iterator (verbosity=1) status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ', length=3, verbosity=1)) output = strip_escseq(status.getvalue()) assert 'testing ... [ 33%] hello\n' in output assert 'testing ... [ 66%] sphinx\n' in output assert 'testing ... [100%] world\n\n' in output assert yields == ['hello', 'sphinx', 'world']
def test_status_iterator(app, status, warning): logging.setup(app, status, warning) # test for old_status_iterator status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ')) output = strip_escseq(status.getvalue()) assert 'testing ... hello sphinx world \n' in output assert yields == ['hello', 'sphinx', 'world'] # test for status_iterator (verbosity=0) status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ', length=3, verbosity=0)) output = strip_escseq(status.getvalue()) assert 'testing ... [ 33%] hello \r' in output assert 'testing ... [ 66%] sphinx \r' in output assert 'testing ... [100%] world \r\n' in output assert yields == ['hello', 'sphinx', 'world'] # test for status_iterator (verbosity=1) status.truncate(0) yields = list(status_iterator(['hello', 'sphinx', 'world'], 'testing ... ', length=3, verbosity=1)) output = strip_escseq(status.getvalue()) assert 'testing ... [ 33%] hello\n' in output assert 'testing ... [ 66%] sphinx\n' in output assert 'testing ... [100%] world\n\n' in output assert yields == ['hello', 'sphinx', 'world']
def test_texinfo_warnings(app, status, warning): app.builder.build_all() warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue())) warnings_exp = TEXINFO_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/'))} assert re.match(warnings_exp + '$', warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + warnings_exp + \ '--- Got:\n' + warnings
def test_texinfo_warnings(app, status, warning): app.builder.build_all() warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue())) warnings_exp = TEXINFO_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/'))} assert re.match(warnings_exp + '$', warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + warnings_exp + \ '--- Got:\n' + warnings
def test_once_warning_log(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) logger.warning('message: %d', 1, once=True) logger.warning('message: %d', 1, once=True) logger.warning('message: %d', 2, once=True) assert 'WARNING: message: 1\nWARNING: message: 2\n' in strip_escseq(warning.getvalue())
def test_execfile_python2(capsys, app, status, warning, tempdir): logging.setup(app, status, warning) conf_py = tempdir / 'conf.py' conf_py.write_bytes(b'print "hello"\n') execfile_(conf_py, {}) msg = ('Support for evaluating Python 2 syntax is deprecated ' 'and will be removed in Sphinx 4.0. ' 'Convert %s to Python 3 syntax.\n' % conf_py) assert msg in strip_escseq(warning.getvalue()) captured = capsys.readouterr() assert captured.out == 'hello\n'
def test_execfile_python2(capsys, app, status, warning): logging.setup(app, status, warning) ns = {} with tempfile.NamedTemporaryFile() as tmp: tmp.write(b'print "hello"\n') tmp.flush() execfile_(tmp.name, ns) msg = ('Support for evaluating Python 2 syntax is deprecated ' 'and will be removed in Sphinx 4.0. ' 'Convert %s to Python 3 syntax.\n' % tmp.name) assert msg in strip_escseq(warning.getvalue()) captured = capsys.readouterr() assert captured.out == 'hello\n'
def test_progress_message(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) # standard case with progress_message('testing'): logger.info('blah ', nonl=True) output = strip_escseq(status.getvalue()) assert 'testing... blah done\n' in output # skipping case with progress_message('testing'): raise SkipProgressMessage('Reason: %s', 'error') output = strip_escseq(status.getvalue()) assert 'testing... skipped\nReason: error\n' in output # error case try: with progress_message('testing'): raise except Exception: pass output = strip_escseq(status.getvalue()) assert 'testing... failed\n' in output # decorator @progress_message('testing') def func(): logger.info('in func ', nonl=True) func() output = strip_escseq(status.getvalue()) assert 'testing... in func done\n' in output
def test_pending_warnings(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) logger.warning('message1') with logging.pending_warnings(): # not logged yet (bufferred) in here logger.warning('message2') logger.warning('message3') assert 'WARNING: message1' in warning.getvalue() assert 'WARNING: message2' not in warning.getvalue() assert 'WARNING: message3' not in warning.getvalue() # actually logged as ordered assert 'WARNING: message2\nWARNING: message3' in strip_escseq(warning.getvalue())
def test_linkcheck_allowed_redirects(app, warning): with http_server(make_redirect_handler(support_head=False)): app.build() with open(app.outdir / 'output.json') as fp: records = [json.loads(l) for l in fp.readlines()] assert len(records) == 2 result = {r["uri"]: r["status"] for r in records} assert result["http://localhost:7777/path1"] == "working" assert result["http://localhost:7777/path2"] == "redirected" assert ("index.rst.rst:1: WARNING: redirect http://localhost:7777/path2 - with Found to " "http://localhost:7777/?redirected=1\n" in strip_escseq(warning.getvalue())) assert len(warning.getvalue().splitlines()) == 1
def test_execfile_python2(capsys, app, status, warning): logging.setup(app, status, warning) ns = {} with tempfile.NamedTemporaryFile() as tmp: tmp.write(b'print "hello"\n') tmp.flush() execfile_(tmp.name, ns) msg = ( 'Support for evaluating Python 2 syntax is deprecated ' 'and will be removed in Sphinx 4.0. ' 'Convert %s to Python 3 syntax.\n' % tmp.name) assert msg in strip_escseq(warning.getvalue()) captured = capsys.readouterr() assert captured.out == 'hello\n'
def test_pending_warnings(app, status, warning): logging.setup(app, status, warning) logger = logging.getLogger(__name__) logger.warning('message1') with logging.pending_warnings(): # not logged yet (bufferred) in here logger.warning('message2') logger.warning('message3') assert 'WARNING: message1' in warning.getvalue() assert 'WARNING: message2' not in warning.getvalue() assert 'WARNING: message3' not in warning.getvalue() # actually logged as ordered assert 'WARNING: message2\nWARNING: message3' in strip_escseq(warning.getvalue())
def test_extensions(app, status, warning): app.setup_extension('shutil') assert strip_escseq(warning.getvalue()).startswith("WARNING: extension 'shutil'")
def test_extension_in_blacklist(app, status, warning): app.setup_extension('sphinxjp.themecore') msg = strip_escseq(warning.getvalue()) assert msg.startswith("WARNING: the extension 'sphinxjp.themecore' was")
def test_extensions(app, status, warning): app.setup_extension('shutil') assert strip_escseq( warning.getvalue()).startswith("WARNING: extension 'shutil'")
def test_extensions(app, status, warning): app.setup_extension('shutil') warning = strip_escseq(warning.getvalue()) assert "extension 'shutil' has no setup() function" in warning
def test_extensions(app, status, warning): app.setup_extension('shutil') warning = strip_escseq(warning.getvalue()) assert "extension 'shutil' has no setup() function" in warning
def test_extension_in_blacklist(app, status, warning): app.setup_extension('sphinxjp.themecore') msg = strip_escseq(warning.getvalue()) assert msg.startswith("WARNING: the extension 'sphinxjp.themecore' was")
def getwarning(warnings): return strip_escseq(warnings.getvalue().replace(os.sep, '/'))
def getwarning(warnings): return strip_escseq(warnings.getvalue().replace(os.sep, '/'))