//! 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 assert_cmd::assert::Assert; use assert_cmd::prelude::*; use common::{venv_to_interpreter, INSTA_FILTERS}; use crate::common::{get_bin, puffin_snapshot, TestContext}; mod common; fn assert_command(venv: &Path, command: &str, temp_dir: &Path) -> Assert { Command::new(venv_to_interpreter(venv)) .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(); } /// Create a `pip install` command with options shared across all scenarios. fn command(context: &TestContext) -> Command { let mut command = Command::new(get_bin()); command .arg("pip") .arg("install") .arg("--extra-index-url") .arg("https://test.pypi.org/simple") .arg("--cache-dir") .arg(context.cache_dir.path()) .env("VIRTUAL_ENV", context.venv.as_os_str()) .env("PUFFIN_NO_WRAP", "1") .current_dir(&context.temp_dir); command } {{#scenarios}} /// {{name}} /// {{#description_lines}} /// {{.}} {{/description_lines}} /// /// ```text /// {{version}} {{#tree}} /// {{.}} {{/tree}} /// ``` #[test] fn {{module_name}}() { let context = TestContext::new("{{environment.python}}"); // In addition to the standard filters, swap out package names for more realistic messages let mut filters = INSTA_FILTERS.to_vec(); {{#packages}} filters.push((r"{{name}}", "{{cute_name}}")); {{/packages}} filters.push((r"-{{version}}", "")); puffin_snapshot!(filters, command(&context) {{#resolver_options.prereleases}} .arg("--prerelease=allow") {{/resolver_options.prereleases}} {{#resolver_options.no_build}} .arg("--only-binary") .arg("{{.}}-{{version}}") {{/resolver_options.no_build}} {{#resolver_options.no_binary}} .arg("--no-binary") .arg("{{.}}-{{version}}") {{/resolver_options.no_binary}} {{#root.requires}} .arg("{{requirement}}") {{/root.requires}}, @r###" "###); {{#expected.explanation_lines}} // {{.}} {{/expected.explanation_lines}} {{#expected.satisfiable}} {{#expected.packages}} assert_installed( &context.venv, "{{module_name}}", "{{version}}", &context.temp_dir ); {{/expected.packages}} {{/expected.satisfiable}} {{^expected.satisfiable}} {{#root.requires}} assert_not_installed(&context.venv, "{{module_name}}", &context.temp_dir); {{/root.requires}} {{/expected.satisfiable}} } {{/scenarios}}