コード例 #1
0
def test_deps_audit_command(temp_path: Path, capsys):
    reqs_path = temp_path / 'requirements.txt'
    reqs_path.write_text('six==1.12.0')

    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
        'nocolors': True,
    })

    command = DepsAuditCommand(argv=['jinja2==2.0'], config=config)
    result = command()

    captured = capsys.readouterr()
    print(captured.err)
    print(captured.out)
    assert result is False
    output = json.loads(captured.out)
    assert len(output) >= 2
    for entry in output:
        assert entry['current'] == '2.0'
        assert entry['name'] == 'jinja2'
コード例 #2
0
def test_bump_pyproject(temp_path: Path):
    from_path = temp_path / 'pyproject.toml'
    from_path.write_text(
        dedent("""
        [tool.poetry]
        name = "check-me"
        version = "1.2.3"

        [tool.poetry.dependencies]
        python = "*"

        [[tool.poetry.source]]
        name = "pypi"
        url = "https://pypi.org/pypi"
    """))
    before_toml = tomlkit.loads(from_path.read_text())
    config = Config()
    config.attach({
        'project': str(temp_path),
        'from': {
            'format': 'poetry',
            'path': 'pyproject.toml'
        },
    })

    command = ProjectBumpCommand(argv=['fix'], config=config)
    result = command()

    assert result is True
    after_toml = tomlkit.loads(from_path.read_text())
    assert after_toml['tool']['poetry'][
        'version'] == '1.2.4', 'Version was not bumped properly'
    after_toml['tool']['poetry']['version'] = '1.2.3'
    assert after_toml == before_toml, 'Bump command altered attributes other than version'
コード例 #3
0
def test_make_script(temp_path: Path):
    dotenv = temp_path / '.env'
    dotenv.touch()
    exe = temp_path / 'flake8'
    exe.touch()

    config = Config()
    config.attach({
        'project': str(temp_path),
        'dotenv': str(temp_path),
        'vars': {
            'KEY': 'value'
        },
    })

    command = VenvEntrypointCommand(argv=[], config=config)
    script = command._make_script(command=['flake8', '--help'], executable=exe)

    expected = """
        #!/usr/bin/env bash
        export KEY="value"
        . {dotenv}
        cd {path}
        {exe} --help $@
    """
    expected = expected.format(
        dotenv=str(dotenv.absolute()),
        path=str(temp_path.absolute()),
        exe=str(exe.absolute()),
    )
    assert script.strip() == dedent(expected).strip()
コード例 #4
0
def test_bump_command_with_placeholder_tag(temp_path: Path, tag_template,
                                           expected_tag):
    project_path = (temp_path / 'project')
    project_path.mkdir()
    init_path = (project_path / '__init__.py')
    init_path.write_text('__version__ = "1.2.3"')
    config = Config()
    config.attach({
        'project': str(project_path),
        'tag': tag_template,
    })
    # init local repo and add `__init__.py` to git index
    _run(['git', 'init'], project=project_path)

    # it's needed because bump command with tag generates not only tag, but also commit with --update flag
    # --update add to commit only modified files, not created (__init__.py in this case is created)
    _run(['git', 'add', '.'], project=project_path)

    command = ProjectBumpCommand(argv=['fix'], config=config)
    result = command()
    assert result is True

    # just read stdout from git tag command
    _, tags = _run(['git', 'tag'], project=project_path)
    assert tags == expected_tag
コード例 #5
0
ファイル: test_jail_install.py プロジェクト: yyolk/dephell
def test_jail_install_command(temp_path: Path, caplog):
    caplog.set_level(logging.DEBUG)

    venv_path = temp_path / 'venv'
    bin_path = temp_path / 'bin'
    bin_path.mkdir()

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
        'bin': str(bin_path),
    })

    command = JailInstallCommand(argv=['pycodestyle==2.5.0'], config=config)
    result = command()

    entrypoint_filename = 'pycodestyle'
    if IS_WINDOWS:
        entrypoint_filename += '.exe'

    assert result is True
    assert (bin_path / entrypoint_filename).exists()

    venv = VEnv(path=venv_path)
    assert venv.exists()
    assert (venv.bin_path / entrypoint_filename).exists()
    assert (venv.lib_path / 'pycodestyle-2.5.0.dist-info').exists()
コード例 #6
0
def test_generate_license_command(temp_path: Path):
    config = Config()
    config.attach({'project': str(temp_path)})
    command = GenerateLicenseCommand(argv=['MIT'], config=config)
    result = command()

    assert result is True
    assert (temp_path / 'LICENSE').exists()
    content = (temp_path / 'LICENSE').read_text()
    assert 'MIT License' in content
    assert str(date.today().year) in content
コード例 #7
0
def test_bump_command(temp_path: Path):
    (temp_path / 'project').mkdir()
    init_path = (temp_path / 'project' / '__init__.py')
    init_path.write_text('__version__ = "1.2.3"')
    config = Config()
    config.attach({
        'project': str(temp_path),
    })
    command = ProjectBumpCommand(argv=['fix'], config=config)
    result = command()
    assert result is True
    assert init_path.read_text() == '__version__ = "1.2.4"'
コード例 #8
0
ファイル: test_vendor_download.py プロジェクト: yyolk/dephell
def test_extract_modules(temp_path: Path, requirements_path: Path):
    config = Config()
    config.attach(dict(project=str(temp_path)))
    command = VendorDownloadCommand(argv=[], config=config)
    dep = DependencyMaker.from_requirement(source=RootDependency(),
                                           req='dephell')[0]
    result = command._extract_modules(
        dep=dep,
        archive_path=requirements_path / 'wheel.whl',
        output_path=temp_path,
    )
    assert result is True
    assert (temp_path / 'dephell').exists()
    assert (temp_path / 'dephell' / '__init__.py').exists()
コード例 #9
0
def test_convert_poetry_to_setup(temp_path: Path, requirements_path: Path):
    from_path = str(requirements_path / 'poetry.toml')
    to_path = temp_path / 'setup.py'
    config = Config()
    config.attach({
        'from': dict(format='poetry', path=from_path),
        'to': dict(format='poetry', path=str(to_path)),
        'project': str(temp_path),
    })
    command = DepsConvertCommand(argv=[], config=config)
    result = command()
    assert result is True
    assert to_path.exists()
    content = to_path.read_text()
    assert 'The description of the package' in content
コード例 #10
0
ファイル: test_package_show.py プロジェクト: techkuz/dephell
def test_package_show_command(capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
    })

    command = PackageShowCommand(argv=['textdistance'], config=config)
    result = command()

    assert result is True
    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert output['name'] == 'textdistance'
    assert output['license'] == 'MIT'
コード例 #11
0
def test_build_command(temp_path: Path):
    metainfo_path = str(temp_path / 'pyproject.toml')
    shutil.copy('tests/requirements/poetry.toml', metainfo_path)

    config = Config()
    config.attach({
        'from': dict(format='poetry', path=metainfo_path),
        'project': str(temp_path),
    })
    command = ProjectBuildCommand(argv=[], config=config)
    result = command()
    assert result is True
    assert (temp_path / 'setup.py').exists()
    assert (temp_path / 'my_package.egg-info' / 'PKG-INFO').exists()
    assert (temp_path / 'dist' / 'my_package-0.1.0.tar.gz').exists()
    assert (temp_path / 'dist' / 'my_package-0.1.0-py3-none-any.whl').exists()
コード例 #12
0
def test_package_search_command(capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
    })

    command = PackageSearchCommand(argv=['textdistance'], config=config)
    result = command()

    assert result is True
    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert len(output) == 1
    assert output[0]['name'] == 'textdistance'
    assert output[0]['url'] == 'https://pypi.org/project/textdistance/'
コード例 #13
0
def test_generate_editorconfig_command(temp_path: Path):
    (temp_path / 'setup.py').touch()
    (temp_path / 'README.md').touch()

    config = Config()
    config.attach({'project': str(temp_path)})
    command = GenerateEditorconfigCommand(argv=[], config=config)
    result = command()

    assert result is True
    assert (temp_path / '.editorconfig').exists()
    content = (temp_path / '.editorconfig').read_text()
    assert 'md' in content
    assert '[*.py]\nindent_style = space' in content
    assert 'Makefile' not in content
    assert '.go' not in content
コード例 #14
0
def test_inspect_config_command(temp_path: Path, capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
        'project': 'nani',
    })
    command = InspectConfigCommand(argv=[], config=config)
    result = command()
    assert result is True

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert output['project'] == 'nani'
    assert output['level'] == 'WARNING'
    assert output['prereleases'] is False
コード例 #15
0
def test_package_downloads_command(capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
    })

    command = PackageDownloadsCommand(argv=['DJANGO'], config=config)
    result = command()

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert result is True
    assert len(output['pythons']) > 4
    assert len(output['systems']) > 2
    assert '█' in output['pythons'][0]['chart']
コード例 #16
0
def test_package_install_command(temp_path: Path):
    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
    })

    command = PackageInstallCommand(argv=['six==1.12.0'], config=config)
    result = command()

    assert result is True
    assert (venv.lib_path / 'six-1.12.0.dist-info' / 'METADATA').exists()
コード例 #17
0
def test_venv_create_command(temp_path: Path):
    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
    })

    command = VenvCreateCommand(argv=[], config=config)
    result = command()

    assert result is True
    venv = VEnv(path=venv_path)
    assert venv.exists() is True
コード例 #18
0
ファイル: test_build.py プロジェクト: yyolk/dephell
def test_build_command(requirements_path, temp_path: Path):
    (temp_path / 'project').mkdir()
    (temp_path / 'project' / '__init__.py').touch()

    metainfo_path = str(requirements_path / 'poetry.toml')
    config = Config()
    config.attach({
        'from': dict(format='poetry', path=metainfo_path),
        'project': str(temp_path),
    })
    command = ProjectBuildCommand(argv=[], config=config)
    result = command()
    assert result is True
    assert (temp_path / 'setup.py').exists()
    assert (temp_path / 'my_package.egg-info' / 'PKG-INFO').exists()
    assert (temp_path / 'dist' / 'my-package-0.1.0.tar.gz').exists()
    assert (temp_path / 'dist' / 'my_package-0.1.0-py3-none-any.whl').exists()
コード例 #19
0
def test_deps_licenses_command(temp_path: Path, capsys):
    reqs_path = temp_path / 'requirements.txt'
    reqs_path.write_text('six==1.12.0')

    config = Config()
    config.attach({
        'from': dict(format='pip', path=str(reqs_path)),
        'level': 'WARNING',
        'silent': True,
    })

    command = DepsLicensesCommand(argv=[], config=config)
    result = command()

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert result is True
    assert output == {'MIT': ['six']}
コード例 #20
0
def test_inspect_venv_command(temp_path: Path, capsys):
    venv = VEnv(path=temp_path)
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(temp_path),
    })

    command = InspectVenvCommand(argv=[], config=config)
    result = command()
    assert result is True

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert output['exists'] is True
    assert output['bin'] == str(venv.bin_path)
コード例 #21
0
def test_venv_destroy_command(temp_path: Path):
    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
    })

    command = VenvDestroyCommand(argv=[], config=config)
    result = command()

    assert result is True
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
コード例 #22
0
ファイル: test_generate_travis.py プロジェクト: yyolk/dephell
def test_make_travis_pytest(temp_path):
    (temp_path / 'pyproject.toml').write_text(
        dedent(
            """
        [tool.dephell.some_env]
        from = {format = "setuppy", path = "setup.py"}
        command = "pytest -x"
        """, ))

    config = Config()
    config.attach({'project': str(temp_path)})
    command = GenerateTravisCommand(argv=[], config=config)
    result = command()

    assert result is True
    assert (temp_path / '.travis.yml').exists()
    content = (temp_path / '.travis.yml').read_text()
    print(content)
    assert 'some_env' in content
コード例 #23
0
def test_deps_add_command(temp_path: Path, capsys):
    reqs_path = temp_path / 'requirements.txt'
    reqs_path.write_text('six==1.12.0')

    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
        'nocolors': True,
        'from': dict(format='pip', path=reqs_path),
    })

    command = DepsAddCommand(argv=['jinja2==2.0'], config=config)
    result = command()

    captured = capsys.readouterr()
    print(captured.err)
    print(captured.out)
    assert result is True

    assert set(reqs_path.read_text().split()) == {'six==1.12.0', 'jinja2==2.0'}
コード例 #24
0
def test_deps_outdated_command_file(temp_path: Path, capsys):
    reqs_path = temp_path / 'requirements.txt'
    reqs_path.write_text('six==1.11.0')

    config = Config()
    config.attach({
        'from': dict(format='piplock', path=str(reqs_path)),
        'level': 'WARNING',
        'silent': True,
    })

    command = DepsOutdatedCommand(argv=[], config=config)
    result = command()

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert result is False
    assert len(output) == 1
    assert output[0]['name'] == 'six'
    assert output[0]['locked'] == '1.11.0'
    assert output[0]['latest'] != '1.11.0'
コード例 #25
0
ファイル: test_deps_install.py プロジェクト: yyolk/dephell
def test_deps_install_command(temp_path: Path):
    reqs_path = temp_path / 'requirements.txt'
    reqs_path.write_text('six==1.12.0')

    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'from': dict(format='pip', path=str(reqs_path)),
        'project': str(temp_path),
        'venv': str(venv_path),
    })

    command = DepsInstallCommand(argv=[], config=config)
    result = command()

    assert result is True
    assert (venv.lib_path / 'six-1.12.0.dist-info' / 'METADATA').exists()
コード例 #26
0
def test_deps_tree_command(temp_path: Path, capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
    })

    command = DepsTreeCommand(argv=['--type=json', 'autopep8==1.4.3'],
                              config=config)
    result = command()

    captured = capsys.readouterr()
    output = json.loads(captured.out)
    assert result is True
    assert len(output) == 2

    assert output[0]['name'] == 'autopep8'
    assert output[0]['dependencies'] == ['pycodestyle']

    assert output[1]['name'] == 'pycodestyle'
    assert output[1]['dependencies'] == []
コード例 #27
0
def test_convert_to_stdout(temp_path: Path, requirements_path: Path, capsys):
    from_path = str(requirements_path / 'poetry.toml')
    config = Config()
    config.attach({
        'from': {
            'format': 'poetry',
            'path': from_path
        },
        'to': {
            'format': 'setuppy',
            'path': 'stdout'
        },
        'project': str(temp_path),
    })

    command = DepsConvertCommand(argv=[], config=config)
    result = command()

    assert result is True
    captured = capsys.readouterr()
    assert 'setup(' in captured.out
    assert 'The description of the package' in captured.out
コード例 #28
0
def test_jail_install_command(temp_path: Path):
    venv_path = temp_path / 'venv'
    bin_path = temp_path / 'bin'
    bin_path.mkdir()

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
        'bin': str(bin_path),
    })

    command = JailInstallCommand(argv=['pycodestyle==2.5.0'], config=config)
    result = command()

    assert result is True
    assert (bin_path / 'pycodestyle').exists()

    venv = VEnv(path=venv_path)
    assert venv.exists()
    assert (venv.bin_path / 'pycodestyle').exists()
    assert (venv.lib_path / 'pycodestyle-2.5.0.dist-info').exists()
コード例 #29
0
def test_patch_imports(temp_path: Path):
    (temp_path / 'project').mkdir()
    (temp_path / 'project' / '__init__.py').write_text('import requests\nimport django')
    (temp_path / 'project' / 'vendor' / 'requests').mkdir(parents=True)
    (temp_path / 'project' / 'vendor' / 'requests' / '__init__.py').touch()

    config = Config()
    config.attach(dict(project=str(temp_path)))
    package = PackageRoot(name='project', path=temp_path)
    root = RootDependency(raw_name='project', package=package)
    resolver = Resolver(
        graph=Graph(root),
        mutator=Mutator(),
    )
    command = VendorImportCommand(argv=[], config=config)
    command._patch_imports(
        resolver=resolver,
        output_path=temp_path / 'project' / 'vendor',
    )

    expected = 'import project.vendor.requests as requests\nimport django'
    assert (temp_path / 'project' / '__init__.py').read_text() == expected
コード例 #30
0
def test_deps_outdated_command_venv(temp_path: Path, capsys):
    venv_path = temp_path / 'venv'
    venv = VEnv(path=venv_path)
    assert venv.exists() is False
    venv.create(python_path=sys.executable)

    config = Config()
    config.attach({
        'project': str(temp_path),
        'venv': str(venv_path),
        'level': 'WARNING',
        'silent': True,
    })

    command = DepsOutdatedCommand(argv=[], config=config)
    result = command()

    assert type(result) is bool
    if result is False:
        captured = capsys.readouterr()
        output = json.loads(captured.out)
        names = {line['name'] for line in output}
        assert len(names - {'pip', 'setuptools'}) == 0