# Path: uqbar/strings.py
# def ansi_escape(string):
#     return _ansi_escape_pattern.sub("", string)
# 
# def normalize(string: str) -> str:
#     """
#     Normalizes whitespace.
# 
#     Strips leading and trailing blank lines, dedents, and removes trailing
#     whitespace from the result.
#     """
#     string = string.replace("\t", "    ")
#     lines = string.split("\n")
#     while lines and (not lines[0] or lines[0].isspace()):
#         lines.pop(0)
#     while lines and (not lines[-1] or lines[-1].isspace()):
#         lines.pop()
#     for i, line in enumerate(lines):
#         lines[i] = line.rstrip()
#     string = "\n".join(lines)
#     string = textwrap.dedent(string)
#     return string


import pathlib
import shutil
import sys
import pytest
import sphinx.errors
from uqbar.strings import ansi_escape, normalize
    assert not app.config["uqbar_book_use_cache"]
    for filename, expected_content in [
        ("api.txt", api_content),
        ("directives.txt", directives_content),
        ("index.txt", index_content),
    ]:
        path = pathlib.Path(app.srcdir) / "_build" / "text" / filename
        actual_content = normalize(path.read_text())
        assert actual_content == expected_content


@pytest.mark.sphinx("text", testroot="uqbar-sphinx-book-broken")
def test_sphinx_book_text_broken_strict(app, status, warning, rm_dirs):
    """
    Build halts.
    """
    with pytest.raises(sphinx.errors.ExtensionError):
        app.build()
    assert normalize(ansi_escape(status.getvalue())) == normalize(
        """
        Running Sphinx v{sphinx_version}
        [uqbar-book] initializing cache db
        building [mo]: targets for 0 po files that are out of date
        building [text]: targets for 1 source files that are out of date
        updating environment: [new config] 1 added, 0 changed, 0 removed
        reading sources... [100%] index
        """.format(
            sphinx_version=sphinx.__version__
        )
    )

# Path: uqbar/strings.py
# def ansi_escape(string):
#     return _ansi_escape_pattern.sub("", string)
# 
# def normalize(string: str) -> str:
#     """
#     Normalizes whitespace.
# 
#     Strips leading and trailing blank lines, dedents, and removes trailing
#     whitespace from the result.
#     """
#     string = string.replace("\t", "    ")
#     lines = string.split("\n")
#     while lines and (not lines[0] or lines[0].isspace()):
#         lines.pop(0)
#     while lines and (not lines[-1] or lines[-1].isspace()):
#         lines.pop()
#     for i, line in enumerate(lines):
#         lines[i] = line.rstrip()
#     string = "\n".join(lines)
#     string = textwrap.dedent(string)
#     return string


# Path: tests/test_sphinx_book.py
import pathlib
import shutil
import sys
import pytest
import sphinx.errors
from uqbar.strings import ansi_escape, normalize

    assert not app.config["uqbar_book_use_cache"]
    for filename, expected_content in [
        ("api.txt", api_content),
        ("directives.txt", directives_content),
        ("index.txt", index_content),
    ]:
        path = pathlib.Path(app.srcdir) / "_build" / "text" / filename
        actual_content = normalize(path.read_text())
        assert actual_content == expected_content


@pytest.mark.sphinx("text", testroot="uqbar-sphinx-book-broken")
def test_sphinx_book_text_broken_strict(app, status, warning, rm_dirs):
    """
    Build halts.
    """
    with pytest.raises(sphinx.errors.ExtensionError):
        app.build()
    assert normalize(ansi_escape(status.getvalue())) == normalize(
        """
        Running Sphinx v{sphinx_version}
        [uqbar-book] initializing cache db
        building [mo]: targets for 0 po files that are out of date
        building [text]: targets for 1 source files that are out of date
        updating environment: [new config] 1 added, 0 changed, 0 removed
        reading sources... [100%] index
        """.format(
            sphinx_version=sphinx.__version__
        )
    )

    assert normalize(ansi_escape(warning.getvalue())) == normalize(