mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
97 lines
3.7 KiB
Python
97 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
test_util
|
||
~~~~~~~~~~~~~~~
|
||
|
||
Tests util functions.
|
||
|
||
:copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS.
|
||
:license: BSD, see LICENSE for details.
|
||
"""
|
||
|
||
import pytest
|
||
from mock import patch
|
||
|
||
from sphinx.util import display_chunk, encode_uri, split_docinfo, status_iterator
|
||
from sphinx.util import logging
|
||
|
||
from util import with_app, strip_escseq
|
||
|
||
|
||
def test_encode_uri():
|
||
expected = (u'https://ru.wikipedia.org/wiki/%D0%A1%D0%B8%D1%81%D1%82%D0%B5%D0%BC%D0%B0_'
|
||
u'%D1%83%D0%BF%D1%80%D0%B0%D0%B2%D0%BB%D0%B5%D0%BD%D0%B8%D1%8F_'
|
||
u'%D0%B1%D0%B0%D0%B7%D0%B0%D0%BC%D0%B8_%D0%B4%D0%B0%D0%BD%D0%BD%D1%8B%D1%85')
|
||
uri = (u'https://ru.wikipedia.org/wiki'
|
||
u'/Система_управления_базами_данных')
|
||
assert expected, encode_uri(uri)
|
||
|
||
expected = (u'https://github.com/search?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+is%3A'
|
||
u'sprint-friendly+user%3Ajupyter&type=Issues&ref=searchresults')
|
||
uri = (u'https://github.com/search?utf8=✓&q=is%3Aissue+is%3Aopen+is%3A'
|
||
u'sprint-friendly+user%3Ajupyter&type=Issues&ref=searchresults')
|
||
assert expected, encode_uri(uri)
|
||
|
||
|
||
def test_splitdocinfo():
|
||
source = "Hello world.\n"
|
||
docinfo, content = split_docinfo(source)
|
||
assert docinfo == ''
|
||
assert content == 'Hello world.\n'
|
||
|
||
source = ":orphan:\n\nHello world.\n"
|
||
docinfo, content = split_docinfo(source)
|
||
assert docinfo == ':orphan:\n'
|
||
assert content == '\nHello world.\n'
|
||
|
||
source = ":author: Georg Brandl\n:title: Manual of Sphinx\n\nHello world.\n"
|
||
docinfo, content = split_docinfo(source)
|
||
assert docinfo == ':author: Georg Brandl\n:title: Manual of Sphinx\n'
|
||
assert content == '\nHello world.\n'
|
||
|
||
source = ":multiline: one\n\ttwo\n\tthree\n\nHello world.\n"
|
||
docinfo, content = split_docinfo(source)
|
||
assert docinfo == ":multiline: one\n\ttwo\n\tthree\n"
|
||
assert content == '\nHello world.\n'
|
||
|
||
|
||
def test_display_chunk():
|
||
assert display_chunk('hello') == 'hello'
|
||
assert display_chunk(['hello']) == 'hello'
|
||
assert display_chunk(['hello', 'sphinx', 'world']) == 'hello .. world'
|
||
assert display_chunk(('hello',)) == 'hello'
|
||
assert display_chunk(('hello', 'sphinx', 'world')) == 'hello .. world'
|
||
|
||
|
||
@pytest.mark.sphinx('dummy')
|
||
@patch('sphinx.util.console._tw', 40) # terminal width = 40
|
||
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']
|