Esempio n. 1
0
def test_dev_egg_cache_updated_on_upload_of_dev1rXXXX_egg(pytestconfig,
                                                          pypi_chishop_with_egg_cache):
    cache = pypi_chishop_with_egg_cache.egg_cache
    dev_cache = pypi_chishop_with_egg_cache.dev_egg_cache
    with PkgTemplate(name="acme.pypipkg", dev=False,
                     metadata=dict(name="acme.pypipkg", version="1.2.3.dev1-r184247")) as pkg:
        pkg.install_package('pytest-cov')
        pkg.create_pypirc(pypi_chishop_with_egg_cache.get_rc())

        pkg.run_with_coverage([os.path.join(pkg.trunk_dir, "setup.py"),
                               'bdist_egg', 'register', 'upload',
                               '--show-response'], pytestconfig,
                              env=dict(pkg.env, HOME=pkg.workspace), cd=HERE, capture_stdout=False)
        egg = 'acme.pypipkg-1.2.3.dev1_r184247-py%d.%d.egg' % sys.version_info[:2]

        assert not os.path.exists(os.path.join(cache, 'ap', egg))
        assert os.path.exists(os.path.join(dev_cache, 'ap', egg))
        py, pyc = (os.path.join('acme', 'pypipkg', '__init__.' + ext)
                   for ext in ('py', 'pyc'))
        with closing(ZipFile(os.path.join(dev_cache, 'ap', egg))) as z:
            f = z.open(pyc)
            magic = f.read(4)
            stamp = struct.unpack('<L', f.read(4))[0]
            code = marshal.loads(f.read())  # remainder of the file
            assert magic == imp.get_magic()
            assert (datetime.fromtimestamp(stamp) ==
                    datetime(*z.getinfo(py).date_time))
            assert isinstance(code, types.CodeType)
            assert code.co_filename == os.path.join(dev_cache, 'ap', egg, py)
Esempio n. 2
0
def test_egg_caches_not_updated_on_upload_of_dev1_egg(pytestconfig, pypi_chishop_with_egg_cache):
    cache = pypi_chishop_with_egg_cache.egg_cache
    dev_cache = pypi_chishop_with_egg_cache.dev_egg_cache
    with PkgTemplate(name="acme.pypipkg", dev=True,
                     metadata=dict(name="acme.pypipkg", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')
        pkg.create_pypirc(pypi_chishop_with_egg_cache.get_rc())

        pkg.run_with_coverage([os.path.join(pkg.trunk_dir, "setup.py"),
                               'bdist_egg', 'register', 'upload',
                               '--show-response'], pytestconfig,
                              env=dict(pkg.env, HOME=pkg.workspace), cd=HERE, capture_stdout=False)
        egg = 'acme.pypipkg-1.2.3.dev1-py%d.%d.egg' % sys.version_info[:2]
        assert not os.path.exists(os.path.join(cache, 'ap', egg))
        assert not os.path.exists(os.path.join(dev_cache, 'ap', egg))
Esempio n. 3
0
def test_easyinstall_command_links_to_package_from_cache_in_preference_to_fetching_from_pypi(
        pytestconfig,
        pypi_chishop_with_egg_cache):
    """ Creates template, runs easy_install from the setuptools command
    Find and install latest non-dev version of a given package, and then
    try and import it, check that it is an egglink into the egg cache.
    """

    cache = pypi_chishop_with_egg_cache.egg_cache

    pypi_url = "http://%s:%s/simple" % (pypi_chishop_with_egg_cache.hostname,
                                        pypi_chishop_with_egg_cache.port)

    with PkgTemplate(name="acme.pypipkg", dev=False,
                     metadata=dict(name="acme.pypipkg", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')
        pkg.create_pypirc(pypi_chishop_with_egg_cache.get_rc())
        new_env = copy.copy(pkg.env)
        new_env['HOME'] = pkg.workspace
        setup_cmd = [os.path.join(pkg.trunk_dir, "setup.py")]
        setup_cmd += ['bdist_egg', 'register', 'upload', '--show-response']

        pkg.run_with_coverage(setup_cmd, pytestconfig, env=new_env, cd=HERE, capture_stdout=False)

        path_of_egg_in_cache = os.path.join(cache, 'ap', ('acme.pypipkg-1.2.3-py%d.%d.egg' %
                                                          sys.version_info[:2]))
        assert os.path.exists(path_of_egg_in_cache)

    with PkgTemplate(name="acme.pypipkg", dev=False,
                     metadata=dict(name="acme.pypipkg", version="1.2.3")) as pkg:
        pkg.install_package('pytest-cov')

        easyinstall_env = {}
        easyinstall_env['VIRTUALENV_SEARCH_PATH'] = cache

        easyinstall_cmd = [os.path.join(pkg.trunk_dir, "setup.py"),
                           "easy_install", '-i', pypi_url, "acme.pypipkg"]

        pkg.run_with_coverage(easyinstall_cmd, pytestconfig, cd=HERE, env=easyinstall_env,
                              capture_stdout=False)

        [pkg.run(cmd, capture=False, cd=HERE) for cmd in [
            '%s -c "import acme.pypipkg"' % (pkg.python),
        ]]
        installed = pkg.installed_packages()
        assert installed['acme.pypipkg'].version == '1.2.3'
        assert installed['acme.pypipkg'].isrel
        assert installed['acme.pypipkg'].source_path == path_of_egg_in_cache