
import os
import sphinx_tests_util
from xml.etree import ElementTree
from xml.dom import minidom


# =============================================================================
# Utility functions

def srcdir(name):
    test_root = os.path.abspath(os.path.dirname(__file__))
    return os.path.join(test_root, "data", name)


def pretty_print_xml(node):
    minidom_xml = minidom.parseString(ElementTree.tostring(node))
    output = minidom_xml.toprettyxml(indent="  ")
    lines = [line for line in output.splitlines() if line.strip()]
    print "\n".join(lines)


def with_app(*args, **kwargs):
    kwargs = kwargs.copy()
    if "srcdir" in kwargs:
        kwargs["srcdir"] = srcdir(kwargs["srcdir"])
    return sphinx_tests_util.with_app(*args, **kwargs)

@@ -643,16 +643,53 @@
 .copy()%0D
+%0A%0D%0A    # Expand test data directory.%0D
 %0A    if 
@@ -762,16 +762,138 @@
 dir%22%5D)%0D%0A
+%0D%0A    # By default use a fresh build environment.%0D%0A    if %22freshenv%22 not in kwargs:%0D%0A        kwargs%5B%22freshenv%22%5D = True%0D%0A%0D%0A
     retu

Use fresh build environment by default in tests