Reduce pip_sync test duplication (#502)

Move venv creation and running python to check the installation into
function instead of copy&pasting them every time
This commit is contained in:
konsti
2023-11-27 11:21:40 +01:00
committed by GitHub
parent afda835544
commit 71295702bf
3 changed files with 120 additions and 434 deletions
+25 -1
View File
@@ -1,7 +1,31 @@
#![allow(dead_code)]
use assert_cmd::Command;
use assert_fs::assert::PathAssert;
use assert_fs::fixture::PathChild;
use assert_fs::TempDir;
use insta_cmd::get_cargo_bin;
use std::path::PathBuf;
pub(crate) const BIN_NAME: &str = "puffin";
// Not all tests use them and cargo warns otherwise
#[allow(dead_code)]
pub(crate) const INSTA_FILTERS: &[(&str, &str)] = &[
(r"(\d+\.)?\d+(ms|s)", "[TIME]"),
(r"--cache-dir .*", "--cache-dir [CACHE_DIR]"),
];
pub(crate) fn create_venv_py312(temp_dir: &TempDir, cache_dir: &TempDir) -> PathBuf {
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
venv.to_path_buf()
}
+41 -59
View File
@@ -1,6 +1,5 @@
#![cfg(all(feature = "python", feature = "pypi"))]
use std::path::PathBuf;
use std::process::Command;
use anyhow::Result;
@@ -10,36 +9,19 @@ use assert_fs::TempDir;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use common::{BIN_NAME, INSTA_FILTERS};
use common::{create_venv_py312, BIN_NAME, INSTA_FILTERS};
mod common;
// Exclude any packages uploaded after this date.
static EXCLUDE_NEWER: &str = "2023-11-18T12:00:00Z";
fn make_venv_py312(temp_dir: &TempDir, cache_dir: &TempDir) -> PathBuf {
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
venv.to_path_buf()
}
/// Resolve a specific version of Django from a `requirements.in` file.
#[test]
fn compile_requirements_in() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("django==5.0b1")?;
@@ -103,7 +85,7 @@ fn missing_venv() -> Result<()> {
fn compile_pyproject_toml() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -140,7 +122,7 @@ dependencies = [
fn compile_constraints_txt() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("django==5.0b1")?;
@@ -172,7 +154,7 @@ fn compile_constraints_txt() -> Result<()> {
fn compile_constraints_inline() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("django==5.0b1")?;
@@ -204,7 +186,7 @@ fn compile_constraints_inline() -> Result<()> {
fn compile_constraints_markers() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("anyio")?;
@@ -239,7 +221,7 @@ fn compile_constraints_markers() -> Result<()> {
fn compile_pyproject_toml_extra() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -279,7 +261,7 @@ optional-dependencies.foo = [
fn compile_pyproject_toml_extra_name_normalization() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -319,7 +301,7 @@ optional-dependencies."FrIeNdLy-._.-bArD" = [
fn compile_pyproject_toml_extra_missing() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -359,7 +341,7 @@ optional-dependencies.foo = [
fn compile_pyproject_toml_extras_missing() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -403,7 +385,7 @@ optional-dependencies.foo = [
fn compile_requirements_file_extra() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("django==5.0b1")?;
@@ -439,7 +421,7 @@ fn compile_requirements_file_extra() -> Result<()> {
fn invalid_extra_name() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -479,7 +461,7 @@ optional-dependencies.foo = [
fn compile_python_312() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("black==23.10.1")?;
@@ -508,7 +490,7 @@ fn compile_python_312() -> Result<()> {
fn compile_python_37() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("black==23.10.1")?;
@@ -589,7 +571,7 @@ fn compile_numpy_py38() -> Result<()> {
fn compile_wheel_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?;
@@ -616,7 +598,7 @@ fn compile_wheel_url_dependency() -> Result<()> {
fn compile_sdist_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz")?;
@@ -644,7 +626,7 @@ fn compile_sdist_url_dependency() -> Result<()> {
fn compile_git_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git")?;
@@ -676,7 +658,7 @@ fn compile_git_https_dependency() -> Result<()> {
fn compile_git_branch_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@1.0.x")?;
@@ -704,7 +686,7 @@ fn compile_git_branch_https_dependency() -> Result<()> {
fn compile_git_tag_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@3.0.0")?;
@@ -732,7 +714,7 @@ fn compile_git_tag_https_dependency() -> Result<()> {
fn compile_git_long_commit_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str(
@@ -762,7 +744,7 @@ fn compile_git_long_commit_https_dependency() -> Result<()> {
fn compile_git_short_commit_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask @ git+https://github.com/pallets/flask.git@d92b64a")?;
@@ -790,7 +772,7 @@ fn compile_git_short_commit_https_dependency() -> Result<()> {
fn compile_git_refs_https_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in
@@ -819,7 +801,7 @@ fn compile_git_refs_https_dependency() -> Result<()> {
fn compile_git_subdirectory_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("example-pkg-a @ git+https://github.com/pypa/sample-namespace-packages.git@df7530eeb8fa0cb7dbb8ecb28363e8e36bfa2f45#subdirectory=pkg_resources/pkg_a")?;
@@ -847,7 +829,7 @@ fn compile_git_subdirectory_dependency() -> Result<()> {
fn compile_git_concurrent_access() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in
@@ -876,7 +858,7 @@ fn compile_git_concurrent_access() -> Result<()> {
fn compile_git_mismatched_name() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in
@@ -905,7 +887,7 @@ fn compile_git_mismatched_name() -> Result<()> {
fn mixed_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/c3/fc/254c3e9b5feb89ff5b9076a23218dafbc99c96ac5941e900b71206e6313b/werkzeug-3.0.1-py3-none-any.whl")?;
@@ -933,7 +915,7 @@ fn mixed_url_dependency() -> Result<()> {
fn conflicting_direct_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("werkzeug==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?;
@@ -961,7 +943,7 @@ fn conflicting_direct_url_dependency() -> Result<()> {
fn compatible_direct_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("werkzeug==2.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?;
@@ -988,7 +970,7 @@ fn compatible_direct_url_dependency() -> Result<()> {
fn conflicting_repeated_url_dependency_version_mismatch() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("werkzeug @ https://files.pythonhosted.org/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?;
@@ -1017,7 +999,7 @@ fn conflicting_repeated_url_dependency_version_mismatch() -> Result<()> {
fn conflicting_repeated_url_dependency_version_match() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("werkzeug @ git+https://github.com/pallets/werkzeug.git@2.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?;
@@ -1044,7 +1026,7 @@ fn conflicting_repeated_url_dependency_version_match() -> Result<()> {
fn conflicting_transitive_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("flask==3.0.0\nwerkzeug @ https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl")?;
@@ -1073,7 +1055,7 @@ fn conflicting_transitive_url_dependency() -> Result<()> {
fn disallowed_transitive_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/13257454/transitive_url_dependency.zip")?;
@@ -1102,7 +1084,7 @@ fn disallowed_transitive_url_dependency() -> Result<()> {
fn allowed_transitive_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/13257454/transitive_url_dependency.zip")?;
@@ -1137,7 +1119,7 @@ fn allowed_transitive_url_dependency() -> Result<()> {
fn allowed_transitive_canonical_url_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("transitive_url_dependency @ https://github.com/astral-sh/ruff/files/13257454/transitive_url_dependency.zip")?;
@@ -1169,7 +1151,7 @@ fn allowed_transitive_canonical_url_dependency() -> Result<()> {
fn compile_pyproject_toml_all_extras() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -1211,7 +1193,7 @@ optional-dependencies.bar = [
fn compile_does_not_allow_both_extra_and_all_extras() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -1267,7 +1249,7 @@ optional-dependencies.bar = [
fn compile_unsolvable_requirements() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -1303,7 +1285,7 @@ dependencies = ["django==5.0b1", "django==5.0a1"]
fn compile_unsolvable_requirements_version_not_available() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let pyproject_toml = temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
@@ -1338,7 +1320,7 @@ dependencies = ["django==300.1.4"]
fn compile_exclude_newer() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.in");
requirements_in.write_str("tqdm")?;
@@ -1427,7 +1409,7 @@ fn compile_exclude_newer() -> Result<()> {
fn compile_wheel_path_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
// Download a wheel.
let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?;
@@ -1464,7 +1446,7 @@ fn compile_wheel_path_dependency() -> Result<()> {
fn compile_source_distribution_path_dependency() -> Result<()> {
let temp_dir = TempDir::new()?;
let cache_dir = TempDir::new()?;
let venv = make_venv_py312(&temp_dir, &cache_dir);
let venv = create_venv_py312(&temp_dir, &cache_dir);
// Download a source distribution.
let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz")?;
+54 -374
View File
@@ -1,5 +1,6 @@
#![cfg(all(feature = "python", feature = "pypi"))]
use std::path::Path;
use std::process::Command;
use anyhow::{Context, Result};
@@ -8,10 +9,19 @@ use assert_fs::prelude::*;
use insta_cmd::_macro_support::insta;
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin};
use common::{BIN_NAME, INSTA_FILTERS};
use common::{create_venv_py312, BIN_NAME, INSTA_FILTERS};
mod common;
fn check_command(venv: &Path, command: &str, temp_dir: &Path) {
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg(command)
.current_dir(temp_dir)
.assert()
.success();
}
#[test]
fn missing_requirements_txt() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
@@ -55,19 +65,7 @@ fn missing_venv() -> Result<()> {
fn install() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -85,12 +83,7 @@ fn install() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe", &temp_dir);
Ok(())
}
@@ -100,19 +93,7 @@ fn install() -> Result<()> {
fn install_copy() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -132,12 +113,7 @@ fn install_copy() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe", &temp_dir);
Ok(())
}
@@ -147,19 +123,7 @@ fn install_copy() -> Result<()> {
fn install_hardlink() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -179,12 +143,7 @@ fn install_hardlink() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe", &temp_dir);
Ok(())
}
@@ -194,19 +153,7 @@ fn install_hardlink() -> Result<()> {
fn install_many() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -224,12 +171,7 @@ fn install_many() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe; import tomli")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe; import tomli", &cache_dir);
Ok(())
}
@@ -239,19 +181,7 @@ fn install_many() -> Result<()> {
fn noop() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -279,12 +209,7 @@ fn noop() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe", &temp_dir);
Ok(())
}
@@ -295,19 +220,7 @@ fn noop() -> Result<()> {
fn link() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv1 = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -318,15 +231,15 @@ fn link() -> Result<()> {
.arg("requirements.txt")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("VIRTUAL_ENV", venv1.as_os_str())
.current_dir(&temp_dir)
.assert()
.success();
let venv = temp_dir.child(".venv");
let venv2 = temp_dir.child(".venv2");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg(venv2.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
@@ -334,7 +247,7 @@ fn link() -> Result<()> {
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
venv2.assert(predicates::path::is_dir());
insta::with_settings!({
filters => INSTA_FILTERS.to_vec()
@@ -344,16 +257,11 @@ fn link() -> Result<()> {
.arg("requirements.txt")
.arg("--cache-dir")
.arg(cache_dir.path())
.env("VIRTUAL_ENV", venv.as_os_str())
.env("VIRTUAL_ENV", venv2.as_os_str())
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv2, "import markupsafe", &temp_dir);
Ok(())
}
@@ -364,19 +272,7 @@ fn link() -> Result<()> {
fn add_remove() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -408,12 +304,7 @@ fn add_remove() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import tomli")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import tomli", &temp_dir);
Command::new(venv.join("bin").join("python"))
.arg("-c")
@@ -431,19 +322,7 @@ fn add_remove() -> Result<()> {
fn install_sequential() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -475,12 +354,7 @@ fn install_sequential() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import markupsafe; import tomli")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import markupsafe; import tomli", &cache_dir);
Ok(())
}
@@ -491,19 +365,7 @@ fn install_sequential() -> Result<()> {
fn upgrade() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -535,12 +397,7 @@ fn upgrade() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import tomli")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import tomli", &temp_dir);
Ok(())
}
@@ -550,19 +407,7 @@ fn upgrade() -> Result<()> {
fn install_url() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -582,12 +427,7 @@ fn install_url() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -598,19 +438,7 @@ fn install_url() -> Result<()> {
fn install_git_commit() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -630,12 +458,7 @@ fn install_git_commit() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -646,19 +469,7 @@ fn install_git_commit() -> Result<()> {
fn install_git_tag() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -678,12 +489,7 @@ fn install_git_tag() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -694,19 +500,7 @@ fn install_git_tag() -> Result<()> {
fn install_git_subdirectories() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -726,12 +520,7 @@ fn install_git_subdirectories() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import example_pkg")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import example_pkg", &temp_dir);
Ok(())
}
@@ -741,19 +530,7 @@ fn install_git_subdirectories() -> Result<()> {
fn install_sdist() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -773,12 +550,7 @@ fn install_sdist() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -789,19 +561,7 @@ fn install_sdist() -> Result<()> {
fn install_url_then_install_url() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -831,12 +591,7 @@ fn install_url_then_install_url() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -847,19 +602,7 @@ fn install_url_then_install_url() -> Result<()> {
fn install_url_then_install_version() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -893,12 +636,7 @@ fn install_url_then_install_version() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -909,19 +647,7 @@ fn install_url_then_install_version() -> Result<()> {
fn install_version_then_install_url() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_txt = temp_dir.child("requirements.txt");
requirements_txt.touch()?;
@@ -955,12 +681,7 @@ fn install_version_then_install_url() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import werkzeug")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import werkzeug", &temp_dir);
Ok(())
}
@@ -1002,12 +723,7 @@ fn install_numpy_py38() -> Result<()> {
.current_dir(&temp_dir));
});
Command::new(venv.join("bin").join("python"))
.arg("-c")
.arg("import numpy")
.current_dir(&temp_dir)
.assert()
.success();
check_command(&venv, "import numpy", &temp_dir);
Ok(())
}
@@ -1016,19 +732,7 @@ fn install_numpy_py38() -> Result<()> {
fn warn_on_yanked_version() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
let requirements_in = temp_dir.child("requirements.txt");
requirements_in.touch()?;
@@ -1055,19 +759,7 @@ fn warn_on_yanked_version() -> Result<()> {
fn install_local_wheel() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
// Download a wheel.
let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/36/42/015c23096649b908c809c69388a805a571a3bea44362fe87e33fc3afa01f/flask-3.0.0-py3-none-any.whl")?;
@@ -1102,19 +794,7 @@ fn install_local_wheel() -> Result<()> {
fn install_local_source_distribution() -> Result<()> {
let temp_dir = assert_fs::TempDir::new()?;
let cache_dir = assert_fs::TempDir::new()?;
let venv = temp_dir.child(".venv");
Command::new(get_cargo_bin(BIN_NAME))
.arg("venv")
.arg(venv.as_os_str())
.arg("--cache-dir")
.arg(cache_dir.path())
.arg("--python")
.arg("python3.12")
.current_dir(&temp_dir)
.assert()
.success();
venv.assert(predicates::path::is_dir());
let venv = create_venv_py312(&temp_dir, &cache_dir);
// Download a source distribution.
let response = reqwest::blocking::get("https://files.pythonhosted.org/packages/d8/09/c1a7354d3925a3c6c8cfdebf4245bae67d633ffda1ba415add06ffc839c5/flask-3.0.0.tar.gz")?;