def test_install_uses_telemetry(monkeypatch, tmp_directory): _write_sample_conda_env(env_name='telemetry') Path('setup.py').write_text(setup_py) mock = Mock() monkeypatch.setattr(install.telemetry, "log_api", mock) install.main(False) assert mock.call_count == 2
def test_build_uses_telemetry(monkeypatch, tmp_directory): _write_sample_conda_env() Path('setup.py').write_text(setup_py) mock = Mock() monkeypatch.setattr(sys, 'argv', ['python', '--entry-point', 'test_pkg.entry.with_doc']) monkeypatch.setattr(build.telemetry, "log_api", mock) build.main(catch_exception=False) assert mock.call_count == 1
def test_non_package_with_conda_with_dev_deps(tmp_directory): _write_sample_conda_env() _write_sample_conda_env('environment.dev.yml') runner = CliRunner() runner.invoke(install, catch_exceptions=False) assert set(os.listdir()) == { 'environment.yml', 'environment.lock.yml', 'environment.dev.yml', 'environment.dev.lock.yml' }
def test_install_lock_package_with_conda(tmp_directory, monkeypatch, mock_cmdr_wrapped, pkg_manager, cleanup_conda_tmp_env, create_dev_lock): _write_sample_conda_env('environment.lock.yml') if create_dev_lock: _write_sample_conda_env('environment.dev.lock.yml') Path('setup.py').write_text(setup_py) runner = CliRunner() runner.invoke(install, args='--use-lock', catch_exceptions=False) pip = install_module._path_to_pip_in_env_with_name(shutil.which('conda'), 'my_tmp_env') expected = [ call(pkg_manager, 'env', 'create', '--file', 'environment.lock.yml', '--force', description='Creating env'), call(pip, 'install', '--editable', '.', description='Installing project'), call(pkg_manager, 'env', 'update', '--file', 'environment.dev.lock.yml', description='Installing dev dependencies') ] if os.name == 'nt': expected.insert( 0, call(pkg_manager, 'env', 'list', '--json', capture_output=True)) if not create_dev_lock: expected.pop(-1) assert mock_cmdr_wrapped.call_args_list == expected assert all( [Path(c[0][0]).is_file() for c in mock_cmdr_wrapped.call_args_list])
def test_install_non_package_with_conda(tmp_directory, monkeypatch, mock_cmdr_wrapped): # to make it fail if it attempts to look for pip, see docstring in the # '_locate_pip_inside_conda' method for details mock_locate = Mock(side_effect=ValueError) monkeypatch.setattr(install_module, '_locate_pip_inside_conda', mock_locate) _write_sample_conda_env() runner = CliRunner() runner.invoke(install, catch_exceptions=False) # check first argument is the path to the conda binary instead of just # "conda" since we discovered that fails sometimes on Windows assert all( [Path(c[0][0]).is_file() for c in mock_cmdr_wrapped.call_args_list]) assert set(os.listdir()) == {'environment.yml', 'environment.lock.yml'}
def test_install_package_conda(tmp_directory, mock_cmdr_wrapped): _write_sample_conda_env() Path('setup.py').write_text(setup_py) runner = CliRunner() runner.invoke(install, catch_exceptions=False) # check it calls "pip install --editable ." assert mock_cmdr_wrapped.call_args_list[-2][1][ 'description'] == 'Installing project' # check first argument is the path to the conda binary instead of just # "conda" since we discovered that fails sometimes on Windows assert all( [Path(c[0][0]).is_file() for c in mock_cmdr_wrapped.call_args_list]) assert set(os.listdir()) == { 'environment.yml', 'environment.lock.yml', 'sample_package.egg-info', 'setup.py', }
def test_install_lock_non_package_with_conda( tmp_directory, monkeypatch, mock_cmdr_wrapped, pkg_manager, error_if_calling_locate_pip_inside_conda, cleanup_conda_tmp_env, create_dev_lock): _write_sample_conda_env('environment.lock.yml') if create_dev_lock: _write_sample_conda_env('environment.dev.lock.yml') runner = CliRunner() runner.invoke(install, args='--use-lock', catch_exceptions=False) expected = [ call(pkg_manager, 'env', 'create', '--file', 'environment.lock.yml', '--force', description='Creating env'), call(pkg_manager, 'env', 'update', '--file', 'environment.dev.lock.yml', description='Installing dev dependencies') ] if os.name == 'nt': expected.insert( 0, call(pkg_manager, 'env', 'list', '--json', capture_output=True)) if not create_dev_lock: expected.pop(-1) assert mock_cmdr_wrapped.call_args_list == expected assert all( [Path(c[0][0]).is_file() for c in mock_cmdr_wrapped.call_args_list])