示例#1
0
class TestData(object):
    """
    Represents a bundle of pre-created test data.

    This copies a pristine set of test data into a root location that is
    designed to be test specific. The reason for this is when running the tests
    concurrently errors can be generated because the related tooling uses
    the directory as a work space. This leads to two concurrent processes
    trampling over each other. This class gets around that by copying all
    data into a directory and operating on the copied data.
    """
    def __init__(self, root, source=None):
        self.source = source or DATA_DIR
        self.root = Path(root).resolve()

    @classmethod
    def copy(cls, root):
        obj = cls(root)
        obj.reset()
        return obj

    def reset(self):
        # Check explicitly for the target directory to avoid overly-broad
        # try/except.
        if self.root.exists():
            shutil.rmtree(self.root)
        shutil.copytree(self.source, self.root, symlinks=True)

    @property
    def packages(self):
        return self.root.joinpath("packages")

    @property
    def packages2(self):
        return self.root.joinpath("packages2")

    @property
    def packages3(self):
        return self.root.joinpath("packages3")

    @property
    def src(self):
        return self.root.joinpath("src")

    @property
    def indexes(self):
        return self.root.joinpath("indexes")

    @property
    def reqfiles(self):
        return self.root.joinpath("reqfiles")

    @property
    def completion_paths(self):
        return self.root.joinpath("completion_paths")

    @property
    def find_links(self):
        return path_to_url(self.packages)

    @property
    def find_links2(self):
        return path_to_url(self.packages2)

    @property
    def find_links3(self):
        return path_to_url(self.packages3)

    @property
    def backends(self):
        return path_to_url(self.root.joinpath("backends"))

    def index_url(self, index="simple"):
        return path_to_url(self.root.joinpath("indexes", index))