Пример #1
0
def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        with temp_environ():
            with open(p.pipfile_path, 'w') as f:
                f.write("""
[[source]]
url = 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@pypi.org/simple'
verify_ssl = true
name = 'pypi'

[packages]
six = "*"
""")
            project = Project()

            os.environ['PYPI_USERNAME'] = '******'
            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() is None

            c = p.pipenv('install')
            assert c.return_code == 0
            lock_hash = project.get_lockfile_hash()
            assert lock_hash is not None
            assert lock_hash == project.calculate_pipfile_hash()

            # sanity check on pytest
            assert 'PYPI_USERNAME' not in str(pipfile.load(p.pipfile_path))
            assert c.return_code == 0
            assert project.get_lockfile_hash(
            ) == project.calculate_pipfile_hash()

            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash(
            ) == project.calculate_pipfile_hash()

            with open(p.pipfile_path, 'a') as f:
                f.write('requests = "==2.14.0"\n')
            assert project.get_lockfile_hash(
            ) != project.calculate_pipfile_hash()
Пример #2
0
def test_environment_variable_value_does_not_change_hash(PipenvInstance, pypi):
    with PipenvInstance(chdir=True, pypi=pypi) as p:
        with temp_environ():
            with open(p.pipfile_path, 'w') as f:
                f.write("""
[[source]]
url = 'https://${PYPI_USERNAME}:${PYPI_PASSWORD}@pypi.org/simple'
verify_ssl = true
name = 'pypi'
[requires]
python_version = '2.7'
[packages]
flask = "==0.12.2"
""")
            project = Project()

            os.environ['PYPI_USERNAME'] = '******'
            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() is None

            c = p.pipenv('install')
            lock_hash = project.get_lockfile_hash()
            assert lock_hash is not None
            assert lock_hash == project.calculate_pipfile_hash()

            # sanity check on pytest
            assert 'PYPI_USERNAME' not in str(pipfile.load(p.pipfile_path))
            assert c.return_code == 0
            assert project.get_lockfile_hash() == project.calculate_pipfile_hash()

            os.environ['PYPI_PASSWORD'] = '******'
            assert project.get_lockfile_hash() == project.calculate_pipfile_hash()

            with open(p.pipfile_path, 'a') as f:
                f.write('requests = "==2.14.0"\n')
            assert project.get_lockfile_hash() != project.calculate_pipfile_hash()
def check_dir(dir_path: Optional[Path] = None) -> bool:
    """
    Check whether specified directory container a valid and
    up-to-date Pipfile.lock. Lack of Pipfile.lock is considered
    as success.
    """
    cur_path: Path = os.getcwd()

    try:
        if dir_path:
            os.chdir(dir_path)

        project = Project()
        if not project.lockfile_exists:
            return

        old_hash = project.get_lockfile_hash()
        new_hash = project.calculate_pipfile_hash()
        return old_hash == new_hash
    finally:
        os.chdir(cur_path)