Example #1
0
def test_healthy_default_creator(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    # should be healthy right after creation
    assert python.healthy(prefix, C.DEFAULT) is True

    # even if a `types.py` file exists, should still be healthy
    tmpdir.join('types.py').ensure()
    assert python.healthy(prefix, C.DEFAULT) is True
Example #2
0
def test_healthy_venv_creator(python_dir):
    # venv creator produces slightly different pyvenv.cfg
    prefix, tmpdir = python_dir

    with envcontext((('VIRTUALENV_CREATOR', 'venv'), )):
        python.install_environment(prefix, C.DEFAULT, ())

    assert python.healthy(prefix, C.DEFAULT) is True
Example #3
0
def test_unhealthy_old_virtualenv(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    # simulate "old" virtualenv by deleting this file
    os.remove(prefix.path('py_env-default/pyvenv.cfg'))

    assert python.healthy(prefix, C.DEFAULT) is False
Example #4
0
def test_unhealthy_system_version_changes(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    with open(prefix.path('py_env-default/pyvenv.cfg'), 'a') as f:
        f.write('base-executable = /does/not/exist\n')

    assert python.healthy(prefix, C.DEFAULT) is False
Example #5
0
def test_unhealthy_with_version_change(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    with open(prefix.path('py_env-default/pyvenv.cfg'), 'w') as f:
        f.write('version_info = 1.2.3\n')

    assert python.healthy(prefix, C.DEFAULT) is False
Example #6
0
def test_unhealthy_python_goes_missing(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    exe_name = 'python' if sys.platform != 'win32' else 'python.exe'
    py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
    os.remove(py_exe)

    assert python.healthy(prefix, C.DEFAULT) is False
Example #7
0
def test_healthy_types_py_in_cwd(tmpdir):
    with tmpdir.as_cwd():
        prefix = tmpdir.join('prefix').ensure_dir()
        prefix.join('setup.py').write('import setuptools; setuptools.setup()')
        prefix = Prefix(str(prefix))
        python.install_environment(prefix, C.DEFAULT, ())

        # even if a `types.py` file exists, should still be healthy
        tmpdir.join('types.py').ensure()
        assert python.healthy(prefix, C.DEFAULT) is True
Example #8
0
def test_unhealthy_then_replaced(python_dir):
    prefix, tmpdir = python_dir

    python.install_environment(prefix, C.DEFAULT, ())

    # simulate an exe which returns an old version
    exe_name = 'python.exe' if sys.platform == 'win32' else 'python'
    py_exe = prefix.path(python.bin_dir('py_env-default'), exe_name)
    os.rename(py_exe, f'{py_exe}.tmp')

    with open(py_exe, 'w') as f:
        f.write('#!/usr/bin/env bash\necho 1.2.3\n')
    make_executable(py_exe)

    # should be unhealthy due to version mismatch
    assert python.healthy(prefix, C.DEFAULT) is False

    # now put the exe back and it should be healthy again
    os.replace(f'{py_exe}.tmp', py_exe)

    assert python.healthy(prefix, C.DEFAULT) is True
Example #9
0
def test_healthy_types_py_in_cwd(tmpdir):
    with tmpdir.as_cwd():
        # even if a `types.py` file exists, should still be healthy
        tmpdir.join('types.py').ensure()
        # this env doesn't actually exist (for test speed purposes)
        assert python.healthy(Prefix(str(tmpdir)), C.DEFAULT) is True