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_html_warnings(app, status, warning): app.builder.build_all() html_warnings = strip_escseq(warning.getvalue().replace(os.sep, "/")) html_warnings_exp = HTML_WARNINGS % {"root": re.escape(app.srcdir.replace(os.sep, "/"))} assert re.match(html_warnings_exp + "$", html_warnings), ( "Warnings don't match:\n" + "--- Expected (regex):\n" + html_warnings_exp + "--- Got:\n" + html_warnings )
def test_texinfo(app, status, warning): TexinfoTranslator.ignore_missing_images = True app.builder.build_all() texinfo_warnings = strip_escseq(warning.getvalue().replace(os.sep, '/')) texinfo_warnings_exp = TEXINFO_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/'))} assert re.match(texinfo_warnings_exp + '$', texinfo_warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + texinfo_warnings_exp + \ '--- Got:\n' + texinfo_warnings # now, try to run makeinfo over it cwd = os.getcwd() os.chdir(app.outdir) try: try: p = Popen(['makeinfo', '--no-split', 'SphinxTests.texi'], stdout=PIPE, stderr=PIPE) except OSError: raise SkipTest # most likely makeinfo was not found else: stdout, stderr = p.communicate() retcode = p.returncode if retcode != 0: print(stdout) print(stderr) assert False, 'makeinfo exited with return code %s' % retcode finally: os.chdir(cwd)
def test_texinfo_warnings(app, status, warning): app.builder.build_all() warnings = strip_escseq(warning.getvalue().replace(os.sep, '/')) 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_output(app, status, warning): status.truncate(0) # __init__ writes to status status.seek(0) app.info("Nothing here...") assert status.getvalue() == "Nothing here...\n" status.truncate(0) status.seek(0) app.info("Nothing here...", True) assert status.getvalue() == "Nothing here..." old_count = app._warncount app.warn("Bad news!") assert strip_escseq(warning.getvalue()) == "WARNING: Bad news!\n" assert app._warncount == old_count + 1
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_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_html_output(app, status, warning): app.builder.build_all() html_warnings = strip_escseq(warning.getvalue().replace(os.sep, '/')) html_warnings_exp = HTML_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/'))} assert re.match(html_warnings_exp + '$', html_warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + html_warnings_exp + \ '--- Got:\n' + html_warnings for fname, paths in iteritems(HTML_XPATH): with (app.outdir / fname).open('rb') as fp: etree = HTML_PARSER.parse(fp) for path, check in paths: yield check_xpath, etree, fname, path, check check_static_entries(app.builder.outdir) check_extra_entries(app.builder.outdir)
def test_html_output(app, status, warning): app.builder.build_all() html_warnings = strip_escseq(warning.getvalue().replace(os.sep, '/')) html_warnings_exp = HTML_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/')) } assert re.match(html_warnings_exp + '$', html_warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + html_warnings_exp + \ '--- Got:\n' + html_warnings for fname, paths in iteritems(HTML_XPATH): with (app.outdir / fname).open('rb') as fp: etree = HTML_PARSER.parse(fp) for path, check in paths: yield check_xpath, etree, fname, path, check check_static_entries(app.builder.outdir) check_extra_entries(app.builder.outdir)
def test_latex(app, status, warning): LaTeXTranslator.ignore_missing_images = True app.builder.build_all() latex_warnings = strip_escseq(warning.getvalue().replace(os.sep, '/')) latex_warnings_exp = LATEX_WARNINGS % { 'root': re.escape(app.srcdir.replace(os.sep, '/'))} assert re.match(latex_warnings_exp + '$', latex_warnings), \ 'Warnings don\'t match:\n' + \ '--- Expected (regex):\n' + latex_warnings_exp + \ '--- Got:\n' + latex_warnings # file from latex_additional_files assert (app.outdir / 'svgimg.svg').isfile() # only run latex if all needed packages are there def kpsetest(filename): try: p = Popen(['kpsewhich', filename], stdout=PIPE) except OSError: # no kpsewhich... either no tex distribution is installed or it is # a "strange" one -- don't bother running latex return None else: p.communicate() if p.returncode != 0: # not found return False # found return True if kpsetest('article.sty') is None: raise SkipTest('not running latex, it doesn\'t seem to be installed') for filename in ['fancyhdr.sty', 'fancybox.sty', 'titlesec.sty', 'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty', 'threeparttable.sty']: if not kpsetest(filename): raise SkipTest('not running latex, the %s package doesn\'t ' 'seem to be installed' % filename) # now, try to run latex over it run_latex(app.outdir)
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 getwarning(warnings): return strip_escseq(warnings.getvalue().replace(os.sep, '/'))
def test_extensions(app, status, warning): app.setup_extension('shutil') assert strip_escseq(warning.getvalue()).startswith("WARNING: extension 'shutil'")