//! DO NOT EDIT //! //! Generated with {{generated_with}} //! Scenarios from <{{generated_from}}> //! #![cfg(all(feature = "python", feature = "pypi"))] use std::path::Path; use std::process::Command; use anyhow::Result; use assert_cmd::assert::Assert; use assert_cmd::prelude::*; use insta_cmd::_macro_support::insta; use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; use common::{create_venv, BIN_NAME, INSTA_FILTERS}; mod common; fn assert_command(venv: &Path, command: &str, temp_dir: &Path) -> Assert { Command::new(venv.join("bin").join("python")) .arg("-c") .arg(command) .current_dir(temp_dir) .assert() } fn assert_installed( venv: &Path, package: &'static str, version: &'static str, temp_dir: &Path, ) { assert_command( venv, format!( "import {package} as package; print(package.__version__, end='')" ) .as_str(), temp_dir, ) .success() .stdout(version); } fn assert_not_installed(venv: &Path, package: &'static str, temp_dir: &Path) { assert_command(venv, format!("import {package}").as_str(), temp_dir).failure(); } {{#scenarios}} /// {{name}} /// {{#description_lines}} /// {{.}} {{/description_lines}} /// /// {{prefix}} {{#tree}} /// {{.}} {{/tree}} #[test] fn {{normalized_name}}() -> Result<()> { let temp_dir = assert_fs::TempDir::new()?; let cache_dir = assert_fs::TempDir::new()?; let venv = create_venv(&temp_dir, &cache_dir, "python{{environment.python}}"); // In addition to the standard filters, remove the scenario prefix let mut filters = INSTA_FILTERS.to_vec(); filters.push((r"{{prefix}}-", "")); insta::with_settings!({ filters => filters }, { assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .arg("pip") .arg("install") {{#root.requires}} .arg("{{prefix}}-{{.}}") {{/root.requires}} {{#environment.prereleases}} .arg("--prerelease=allow") {{/environment.prereleases}} .arg("--extra-index-url") .arg("https://test.pypi.org/simple") .arg("--cache-dir") .arg(cache_dir.path()) .env("VIRTUAL_ENV", venv.as_os_str()) .env("PUFFIN_NO_WRAP", "1") .current_dir(&temp_dir), @r###" "###); }); {{#expected.explanation_lines}} // {{.}} {{/expected.explanation_lines}} {{#expected.satisfiable}} {{#expected.packages_list}} assert_installed( &venv, "{{prefix_module}}_{{package_module}}", "{{version}}", &temp_dir ); {{/expected.packages_list}} {{/expected.satisfiable}} {{^expected.satisfiable}} {{#root.requires_packages}} assert_not_installed(&venv, "{{prefix_module}}_{{package_module}}", &temp_dir); {{/root.requires_packages}} {{/expected.satisfiable}} Ok(()) } {{/scenarios}}