示例#1
0
    def inner(name, base=modules_tmpdir):
        if not isinstance(name, str):
            raise ValueError(name)
        base.join(name).ensure_dir()
        base.join(name).join("__init__.py").ensure()

        egg_setup = base.join("setup.py")
        egg_setup.write(
            textwrap.dedent(
                """
        from setuptools import setup
        setup(name='{0}',
              version='1.0',
              packages=['site_egg'],
              zip_safe=True)
        """.format(
                    name
                )
            )
        )

        import subprocess

        subprocess.check_call(
            [sys.executable, "setup.py", "bdist_egg"], cwd=str(modules_tmpdir)
        )
        egg_path, = modules_tmpdir.join("dist/").listdir()
        monkeypatch.syspath_prepend(str(egg_path))
        return egg_path
示例#2
0
def site_packages(modules_tmpdir, monkeypatch):
    """Create a fake site-packages."""
    rv = (modules_tmpdir.mkdir("lib").mkdir(
        f"python{sys.version_info.major}.{sys.version_info.minor}").mkdir(
            "site-packages"))
    monkeypatch.syspath_prepend(str(rv))
    return rv
示例#3
0
def site_packages(modules_tmpdir, monkeypatch):
    """Create a fake site-packages."""
    rv = modules_tmpdir \
        .mkdir('lib') \
        .mkdir('python{x[0]}.{x[1]}'.format(x=sys.version_info)) \
        .mkdir('site-packages')
    monkeypatch.syspath_prepend(str(rv))
    return rv
示例#4
0
def site_packages(modules_tmpdir, monkeypatch):
    """Create a fake site-packages."""
    rv = modules_tmpdir \
        .mkdir('lib') \
        .mkdir('python{x[0]}.{x[1]}'.format(x=sys.version_info)) \
        .mkdir('site-packages')
    monkeypatch.syspath_prepend(str(rv))
    return rv
示例#5
0
def site_packages(modules_tmpdir, monkeypatch):
    """Create a fake site-packages."""
    rv = (
        modules_tmpdir.mkdir("lib")
        .mkdir("python{x[0]}.{x[1]}".format(x=sys.version_info))
        .mkdir("site-packages")
    )
    monkeypatch.syspath_prepend(str(rv))
    return rv
示例#6
0
def test_apps(monkeypatch):
    monkeypatch.syspath_prepend(
        os.path.join(os.path.dirname(__file__), "test_apps"))
    original_modules = set(sys.modules.keys())

    yield

    # Remove any imports cached during the test. Otherwise "import app"
    # will work in the next test even though it's no longer on the path.
    for key in sys.modules.keys() - original_modules:
        sys.modules.pop(key)
示例#7
0
    def inner(name, base=modules_tmpdir):
        base.join(name).ensure_dir()
        base.join(name).join("__init__.py").ensure()

        egg_setup = base.join("setup.py")
        egg_setup.write(
            textwrap.dedent(f"""
                from setuptools import setup
                setup(
                    name="{name}",
                    version="1.0",
                    packages=["site_egg"],
                    zip_safe=True,
                )
                """))

        import subprocess

        subprocess.check_call([sys.executable, "setup.py", "bdist_egg"],
                              cwd=str(modules_tmpdir))
        (egg_path, ) = modules_tmpdir.join("dist/").listdir()
        monkeypatch.syspath_prepend(str(egg_path))
        return egg_path
示例#8
0
def modules_tmpdir(tmpdir, monkeypatch):
    """A tmpdir added to sys.path."""
    rv = tmpdir.mkdir("modules_tmpdir")
    monkeypatch.syspath_prepend(str(rv))
    return rv
示例#9
0
def test_apps(monkeypatch):
    monkeypatch.syspath_prepend(
        os.path.abspath(os.path.join(
            os.path.dirname(__file__), 'test_apps'))
    )
示例#10
0
def test_apps(monkeypatch):
    monkeypatch.syspath_prepend(
        os.path.abspath(os.path.join(os.path.dirname(__file__), "test_apps"))
    )
示例#11
0
def modules_tmpdir(tmpdir, monkeypatch):
    """A tmpdir added to sys.path."""
    rv = tmpdir.mkdir("modules_tmpdir")
    monkeypatch.syspath_prepend(str(rv))
    return rv