def test_repo_depends(db): assert server.repo_depends(db, 'r1') == [ Depends('DEPENDS', 'python', 'pkg2', ''), Depends('DEPENDS', 'python', 'six', ''), ] assert server.repo_depends(db, 'r2') == [ Depends('DEPENDS_DEV', 'python', 'pre-commit', ''), Depends('DEPENDS_DEV', 'python', 'pytest', ''), ]
def test_requirements_tools_just_reqs(tmpdir): with tmpdir.as_cwd(): tmpdir.join('requirements.txt').write('six') tmpdir.join('requirements-dev.txt').write('pre-commit\npytest\n') assert requirements_tools() == ( Depends('REQUIRES', 'python', 'six', ''), Depends('DEPENDS_DEV', 'python', 'pre-commit', ''), Depends('DEPENDS_DEV', 'python', 'pytest', ''), )
def test_requirements_tools_all_provided(tmpdir): with tmpdir.as_cwd(): tmpdir.join('requirements-minimal.txt').write('six') tmpdir.join('requirements.txt').write('six==1.11') tmpdir.join('requirements-dev-minimal.txt').write('mccabe') tmpdir.join('requirements-dev.txt').write('mccabe==0.6.1') assert requirements_tools() == ( Depends('DEPENDS', 'python', 'six', ''), Depends('REQUIRES', 'python', 'six', '==1.11'), Depends('DEPENDS_DEV', 'python', 'mccabe', ''), Depends('REQUIRES_DEV', 'python', 'mccabe', '==0.6.1'), )
def test_setup_py_has_install_dependencies(tmpdir): with tmpdir.as_cwd(): tmpdir.join('setup.py').write( 'from setuptools import setup, find_packages\n' 'setup(\n' ' name="mypkg",\n' ' install_requires=["six>=1.10.0", "pre-commit"],\n' ' packages=find_packages(),\n' ')\n', ) assert setup_py() == ( Depends('DEPENDS', 'python', 'six', '>=1.10.0'), Depends('DEPENDS', 'python', 'pre-commit', ''), )
def to_depends(relationship: str, requirement_s: str) -> Depends: try: req = Requirement(requirement_s) except InvalidRequirement: return Depends(relationship, NAME, requirement_s, ' (unable to parse)') spec_parts = [] if req.extras: spec_parts.append('[{}]'.format(','.join(sorted(req.extras)))) if req.specifier: spec_parts.append(str(req.specifier)) if req.marker: spec_parts.append(f';{req.marker}') spec = ''.join(spec_parts) return Depends(relationship, NAME, canonicalize_name(req.name), spec)
def package_rdepends( db: sqlite3.Connection, pkgname: str, ) -> List[Tuple[str, Depends]]: query = 'SELECT * FROM depends WHERE package_key = ? ORDER BY repo_name' rows = db.execute(query, (pkgname, )) return [(repo_name, Depends(*row)) for repo_name, *row in rows]
def test_from_reqs_file_comments(tmpdir): f = tmpdir.join('reqs.txt') f.write( '\n' '# hello world\n' 'six # more comments\n', ) expected = (Depends('X', 'python', 'six', ''),) assert tuple(python.from_reqs_file('X', f)) == expected
def test_fomr_reqs_file_editable_git(tmpdir): f = tmpdir.join('reqs.txt') f.write('-e git+https://github.com/asottile/cfgv') expected = ( Depends( 'X', 'python', '-e git+https://github.com/asottile/cfgv', ' (unable to parse)', ), ) assert tuple(python.from_reqs_file('X', f)) == expected
def repo_rdepends( db: sqlite3.Connection, repo_name: str, ) -> List[Tuple[str, Depends]]: query = ('SELECT depends.*\n' 'FROM packages\n' 'INNER JOIN depends ON depends.package_key = packages.key\n' 'WHERE packages.repo_name = ?\n' 'ORDER BY depends.repo_name\n') rows = db.execute(query, (repo_name, )).fetchall() return [(repo_name, Depends(*row)) for repo_name, *row in rows]
def test_from_reqs_file_ignores_local_paths(tmpdir): f = tmpdir.join('reqs.txt') f.write('-e foo\n-e .\nsix\n') tmpdir.join('foo').ensure_dir() expected = (Depends('X', 'python', 'six', ''),) assert tuple(python.from_reqs_file('X', f)) == expected
@pytest.mark.parametrize( ('s', 'expected'), ( ('pre-commit', 'pre-commit'), ('pre_commit', 'pre-commit'), ('PRE_COMMIT', 'pre-commit'), ), ) def test_to_name(s, expected): assert python.to_name(s) == expected @pytest.mark.parametrize( ('s', 'expected'), ( ('pre-commit', Depends('X', 'python', 'pre-commit', '')), ('six==1.10', Depends('X', 'python', 'six', '==1.10')), ('foo[bar,baz]', Depends('X', 'python', 'foo', '[bar,baz]')), ( 'typing;python_version=="2.7"', Depends('X', 'python', 'typing', ';python_version == "2.7"'), ), ), ) def test_to_depends(s, expected): assert python.to_depends('X', s) == expected def test_from_reqs_file_comments(tmpdir): f = tmpdir.join('reqs.txt') f.write(
def repo_depends(db: sqlite3.Connection, repo_name: str) -> List[Depends]: query = ('SELECT * FROM depends WHERE repo_name = ?\n' 'ORDER BY relationship, package_key') rows = db.execute(query, (repo_name, )).fetchall() return [Depends(*row) for _, *row in rows]
def test_package_rdepends(db): expected = [('r1', Depends('DEPENDS', 'python', 'six', ''))] assert server.package_rdepends(db, 'six') == expected
def test_repo_rdepends(db): assert server.repo_rdepends(db, 'r2') == [ ('r1', Depends('DEPENDS', 'python', 'pkg2', '')), ] assert server.repo_rdepends(db, 'r1') == []