示例#1
0
def make_package(path):
    """Make a fake package at path.

    Even with --download, pip insists on extracting the downloaded packages (in
    order to find dependencies), so we can't just make empty files.
    """
    name, version = main.guess_name_version_from_filename(
        os.path.basename(path))

    with tempfile.TemporaryDirectory() as td:
        setup_py = os.path.join(td, 'setup.py')
        with open(setup_py, 'w') as f:
            f.write(
                'from setuptools import setup\n'
                'setup(name="{}", version="{}")\n'.format(name, version), )

        args = ('sdist', '--formats=zip')
        if path.endswith(('.tgz', '.tar.gz')):
            args = ('sdist', '--formats=gztar')
        elif path.endswith('.tar'):
            args = ('sdist', '--formats=tar')
        elif path.endswith('.whl'):
            args = ('bdist_wheel', )

        subprocess.check_call((sys.executable, setup_py) + args, cwd=td)
        created, = os.listdir(os.path.join(td, 'dist'))
        shutil.move(os.path.join(td, 'dist', created), path)
示例#2
0
def test_guess_name_version_from_filename_only_name(filename, name, version):
    """Broken version check tests.

    The real important thing is to be able to parse the name, but it's nice if
    we can parse the versions too. Unfortunately, we can't yet for these cases.
    """
    parsed_name, parsed_version = main.guess_name_version_from_filename(filename)
    assert parsed_name == name

    # If you can make this assertion fail, great! Move it up above!
    assert parsed_version != version
示例#3
0
def test_guess_name_version_from_filename_invalid(filename):
    with pytest.raises(ValueError):
        main.guess_name_version_from_filename(filename)
示例#4
0
def test_guess_name_version_from_filename(filename, name, version):
    assert main.guess_name_version_from_filename(filename) == (name, version)
示例#5
0
 def setup_py_contents(self):
     return ('from setuptools import setup\n'
             'setup(name={!r}, version={!r})\n').format(
                 *main.guess_name_version_from_filename(self.filename))