Example #1
0
def test_upd_pth(temp_path: Path):
    command = ProjectRegisterCommand(argv=[], config=Config())

    path = Path()
    command._upd_pth(lib_path=temp_path, project_path=path)
    content = (temp_path / 'dephell.pth').read_text()
    assert content == '{}\n'.format(path.absolute())

    another_path = Path(__file__)
    command._upd_pth(lib_path=temp_path, project_path=another_path)
    content = (temp_path / 'dephell.pth').read_text()
    assert content == '{}\n{}\n'.format(path.absolute(), another_path)
Example #2
0
def test_upd_egg_link(temp_path: Path):
    command = ProjectRegisterCommand(argv=[], config=Config())
    lib_path = temp_path / 'lib'
    lib_path.mkdir()
    project_path = temp_path / 'project'
    project_path.mkdir()
    egg_info_path = project_path / 'project.egg-info'
    egg_info_path.mkdir()

    command._upd_egg_link(lib_path=lib_path, project_path=project_path)
    content = (lib_path / 'project.egg-link').read_text()
    assert content == '{}\n.'.format(egg_info_path.absolute())
Example #3
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'
Example #4
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
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()
Example #6
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
Example #7
0
def test_deps_tree_command(temp_path: Path, capsys):
    config = Config()
    config.attach({
        'level': 'WARNING',
        'silent': True,
        'nocolors': 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'] == []
Example #8
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
Example #9
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 = "*"
        sentry_sdk = ">=0.9.0"
        npm = "^0.9.0"
        reponame = { git = "ssh://git@our-git-server:port/group/reponame.git", branch = "v3_2" }

        [[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'
Example #10
0
def test_inspect_project_command(temp_path: Path, requirements_path: Path,
                                 capsys):
    from_path = str(requirements_path / 'poetry.toml')
    config = Config()
    config.attach({
        'from': {
            'format': 'poetry',
            'path': from_path
        },
        'project': str(temp_path),
        'nocolors': True,
        'silent': True,
    })

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

    captured = capsys.readouterr()
    print(captured.out)
    output = json.loads(captured.out)
    assert set(output) == {'name', 'version', 'description', 'links', 'python'}
    assert output['name'] == 'my-package'
    assert output['version'] == '0.1.0'
def test_make_contributing_pytest(temp_path):
    (temp_path / 'pyproject.toml').write_text(
        dedent(
            """
        [tool.dephell.isort]
        command = "isort -y"

        [tool.dephell.flake8]
        command = "flake8"

        [tool.dephell.pytest]
        command = "python -m pytest tests/"
        """, ))
    config = Config()
    config.attach({'project': str(temp_path)})
    command = GenerateContributingCommand(argv=[], config=config)
    result = command()

    assert result is True
    assert (temp_path / 'CONTRIBUTING.md').exists()
    content = (temp_path / 'CONTRIBUTING.md').read_text()
    assert '## Testing' in content
    assert '## Style' in content
    assert 'Sort imports' in content
Example #12
0
def test_attach_env_vars(given, expected):
    config = Config()
    result = config.attach_env_vars(env_vars=given)
    assert result == expected
Example #13
0
def test_load():
    config = Config()
    config.attach_file(path=str(Path('tests') / 'requirements' / 'dephell.toml'), env='some_env')
    assert config['from']['format'] == 'pip'
Example #14
0
def test_load(requirements_path: Path):
    config = Config()
    config.attach_file(path=str(requirements_path / 'dephell.toml'),
                       env='some_env')
    assert config['from']['format'] == 'pip'
Example #15
0
def test_load():
    config = Config()
    config.attach_file(path='./tests/requirements/dephell.toml',
                       env='some_env')
    assert config['from']['format'] == 'pip'