Skip to content

Commit

Permalink
Add --no-index test cases to pip sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Feb 3, 2024
1 parent fff6730 commit 2f90628
Showing 1 changed file with 93 additions and 0 deletions.
93 changes: 93 additions & 0 deletions crates/puffin/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ fn command(context: &TestContext) -> Command {
command
}

/// Create a `pip uninstall` command with options shared across scenarios.
fn uninstall_command(context: &TestContext) -> Command {
let mut command = Command::new(get_bin());
command
.arg("pip")
.arg("uninstall")
.arg("--cache-dir")
.arg(context.cache_dir.path())
.env("VIRTUAL_ENV", context.venv.as_os_str())
.current_dir(&context.temp_dir);
command
}

#[test]
fn missing_requirements_txt() {
let context = TestContext::new("3.12");
Expand Down Expand Up @@ -802,6 +815,86 @@ fn install_no_binary() -> Result<()> {
Ok(())
}

/// Attempt to install a package without using a remote index.
#[test]
fn install_no_index() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("MarkupSafe==2.1.3")?;

puffin_snapshot!(command(&context)
.arg("requirements.txt")
.arg("--no-index")
.arg("--strict"), @r###"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: markupsafe isn't available locally, but making network requests to registries was banned.
"###
);

context.assert_command("import markupsafe").failure();

Ok(())
}

/// Attempt to install a package without using a remote index
/// after a previous successful installation.
#[test]
fn install_no_index_cached() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_txt = context.temp_dir.child("requirements.txt");
requirements_txt.touch()?;
requirements_txt.write_str("MarkupSafe==2.1.3")?;

puffin_snapshot!(command(&context)
.arg("requirements.txt")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ markupsafe==2.1.3
"###
);

context.assert_command("import markupsafe").success();

uninstall_command(&context)
.arg("markupsafe")
.assert()
.success();

puffin_snapshot!(command(&context)
.arg("requirements.txt")
.arg("--no-index")
.arg("--strict"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
Downloaded 1 package in [TIME]
Installed 1 package in [TIME]
+ markupsafe==2.1.3
"###
);

context.assert_command("import markupsafe").success();

Ok(())
}

#[test]
fn warn_on_yanked_version() -> Result<()> {
let context = TestContext::new("3.12");
Expand Down

0 comments on commit 2f90628

Please sign in to comment.