Skip to content

Commit

Permalink
test: reorganize integration tests (prefix-dev#2408)
Browse files Browse the repository at this point in the history
- move to a single integration test binary as described in
https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html
- organize test folder
  • Loading branch information
Hofer-Julian authored Nov 5, 2024
1 parent 19aa96d commit 1ee9605
Show file tree
Hide file tree
Showing 192 changed files with 103 additions and 117 deletions.
6 changes: 0 additions & 6 deletions .codespellrc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test_downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ jobs:
run: pixi install -v
- name: Test examples
shell: bash
run: bash tests/test_examples.sh
run: bash tests/scripts/test-examples.sh

# Run integration tests that test the command line
# pixi interface
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ jobs:
run: pixi install -v
- name: Test export
shell: bash
run: bash tests/test_export.sh
run: pixi run test-export
2 changes: 1 addition & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[mypy]
strict = True
exclude = tests/pypi-indexes
exclude = tests/data/pypi-indexes
files = tests,scripts
19 changes: 10 additions & 9 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ build-debug = "cargo build"
bump = "tbump --only-patch $RELEASE_VERSION"
install = "cargo install --path . --locked"
install-as = { cmd = "python scripts/install.py", depends-on = ["build"] }
pypi-proxy = "python ./tests/pypi_proxy.py"
pypi-proxy = "python scripts/pypi-proxy.py"
release = "python scripts/release.py"
run-all-examples = { cmd = "python ./tests/run_all_examples.py --pixi-exec $CARGO_TARGET_DIR/release/pixi", depends-on = [
run-all-examples = { cmd = "python tests/scripts/run-all-examples.py --pixi-exec $CARGO_TARGET_DIR/release/pixi", depends-on = [
"build",
] }
test = "cargo nextest run"
test = "cargo nextest run --workspace"
test-all-fast = { depends-on = ["test", "test-integration-fast"] }
test-export = "python tests/scripts/test-export.sh"
test-workspace = """cargo nextest run --workspace --retries 2 --features slow_integration_tests
--status-level skip --failure-output immediate-final --no-fail-fast --final-status-level slow"""

Expand All @@ -45,18 +46,18 @@ test-common-wheels-ci = { cmd = "pytest --numprocesses=auto --verbose tests/whee
test-common-wheels-dev = { cmd = "pytest --numprocesses=auto tests/wheel_tests/", depends-on = [
"build",
] }
test-integration-ci = "pytest --numprocesses=auto --durations=10 --verbose tests/integration"
test-integration-dev = { cmd = "pytest --numprocesses=auto --durations=10 tests/integration", depends-on = [
test-integration-ci = "pytest --numprocesses=auto --durations=10 --verbose tests/integration_python"
test-integration-dev = { cmd = "pytest --numprocesses=auto --durations=10 tests/integration_python", depends-on = [
"build",
] }
test-integration-fast = { cmd = "pytest -m 'not slow' --pixi-build=debug --numprocesses=auto --durations=10 tests/integration", depends-on = [
test-integration-fast = { cmd = "pytest -m 'not slow' --pixi-build=debug --numprocesses=auto --durations=10 tests/integration_python", depends-on = [
"build-debug",
] }
# pass the file to run as an argument to the task
# you can also pass a specific test function, like this:
# /path/to/test.py::test_function
test-specific-test = { cmd = "pytest", depends-on = ["build"] }
update-integration-test-data = { cmd = "python update-channels.py", cwd = "tests/integration/test_data" }
update-integration-test-channels = { cmd = "python update-channels.py", cwd = "tests/integration/test_data" }

[feature.dev.dependencies]
# Needed for the citation
Expand All @@ -72,7 +73,7 @@ taplo = ">=0.9.1,<0.10"
typos = ">=1.23.1,<2"

[feature.lint.tasks]
check-openssl = "python scripts/check-openssl.py"
check-openssl = "python tests/scripts/check-openssl.py"
lint = "pre-commit run --all-files --hook-stage=manual"
pre-commit-install = "pre-commit install --install-hooks -t=pre-commit -t=pre-push"
pre-commit-install-minimal = "pre-commit install -t=pre-commit"
Expand Down Expand Up @@ -132,7 +133,7 @@ hatchling = ">=1.25.0,<2"
python-build = ">=1.2.2,<2"

[feature.pypi-gen.tasks]
pypi-gen-indexes = "python tests/pypi-indexes/generate-indexes.py"
pypi-gen-indexes = "python tests/data/pypi-indexes/generate-indexes.py"

[environments]
default = { features = [
Expand Down
File renamed without changes.
26 changes: 15 additions & 11 deletions src/lock_file/satisfiability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ mod tests {

#[rstest]
fn test_good_satisfiability(
#[files("tests/satisfiability/*/pixi.toml")] manifest_path: PathBuf,
#[files("tests/data/satisfiability/*/pixi.toml")] manifest_path: PathBuf,
) {
// TODO: skip this test on windows
// Until we can figure out how to handle unix file paths with pep508_rs url
Expand Down Expand Up @@ -1286,16 +1286,20 @@ mod tests {
fn test_failing_satisiability() {
let report_handler = NarratableReportHandler::new().with_cause_chain();

insta::glob!("../../tests/non-satisfiability", "*/pixi.toml", |path| {
let project = Project::from_path(path).unwrap();
let lock_file = LockFile::from_path(&project.lock_file_path()).unwrap();
let err = verify_lockfile_satisfiability(&project, &lock_file)
.expect_err("expected failing satisfiability");

let mut s = String::new();
report_handler.render_report(&mut s, &err).unwrap();
insta::assert_snapshot!(s);
});
insta::glob!(
"../../tests/data/non-satisfiability",
"*/pixi.toml",
|path| {
let project = Project::from_path(path).unwrap();
let lock_file = LockFile::from_path(&project.lock_file_path()).unwrap();
let err = verify_lockfile_satisfiability(&project, &lock_file)
.expect_err("expected failing satisfiability");

let mut s = String::new();
report_handler.render_report(&mut s, &err).unwrap();
insta::assert_snapshot!(s);
}
);
}

#[test]
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions tests/data/mapping_files/compressed_mapping.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 0 additions & 48 deletions tests/integration/conftest.py

This file was deleted.

File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions tests/integration_python/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pathlib import Path

import pytest


def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--pixi-build",
action="store",
default="release",
help="Specify the pixi build type (e.g., release or debug)",
)


@pytest.fixture
def pixi(request: pytest.FixtureRequest) -> Path:
pixi_build = request.config.getoption("--pixi-build")
return Path(__file__).parent.joinpath(f"../../target-pixi/{pixi_build}/pixi")


@pytest.fixture
def channels() -> Path:
return Path(__file__).parent.parent.joinpath("data", "channels", "channels").resolve()


@pytest.fixture
def dummy_channel_1(channels: Path) -> str:
return channels.joinpath("dummy_channel_1").as_uri()


@pytest.fixture
def dummy_channel_2(channels: Path) -> str:
return channels.joinpath("dummy_channel_2").as_uri()


@pytest.fixture
def global_update_channel_1(channels: Path) -> str:
return channels.joinpath("global_update_channel_1").as_uri()


@pytest.fixture
def non_self_expose_channel_1(channels: Path) -> str:
return channels.joinpath("non_self_expose_channel_1").as_uri()


@pytest.fixture
def non_self_expose_channel_2(channels: Path) -> str:
return channels.joinpath("non_self_expose_channel_2").as_uri()
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 0 additions & 2 deletions tests/add_tests.rs → tests/integration_rust/add_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod common;

use std::str::FromStr;

use crate::common::{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions tests/init_tests.rs → tests/integration_rust/init_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod common;

use std::str::FromStr;

use pixi::cli;
Expand Down Expand Up @@ -85,7 +83,7 @@ async fn init_from_existing_pyproject_toml() {
// Copy the pyproject.toml file to the project directory
let project_path = pixi.project_path();
let pyproject_toml = project_path.join("pyproject.toml");
let pyproject_toml_contents = include_str!("pixi_tomls/pyproject_no_pixi.toml");
let pyproject_toml_contents = include_str!("../data/pixi_tomls/pyproject_no_pixi.toml");
std::fs::write(&pyproject_toml, pyproject_toml_contents).unwrap();

// Init a new project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
mod common;

use crate::common::{
builders::{string_from_iter, HasDependencyConfig, HasPrefixUpdateConfig},
package_database::{Package, PackageDatabase},
};
use common::{LockFileExt, PixiControl};
use crate::common::{LockFileExt, PixiControl};
use pixi::cli::cli_config::{PrefixUpdateConfig, ProjectConfig};
use pixi::cli::{run, run::Args, LockFileUsageArgs};
use pixi::environment::LockFileUsage;
Expand Down Expand Up @@ -565,17 +563,18 @@ async fn test_installer_name() {
/// Test full prefix install for an old lock file to see if it still works.
/// Makes sure the lockfile isn't touched and the environment is still installed.
async fn test_old_lock_install() {
let lock_str = std::fs::read_to_string("tests/satisfiability/old_lock_file/pixi.lock").unwrap();
let lock_str =
std::fs::read_to_string("tests/data/satisfiability/old_lock_file/pixi.lock").unwrap();
let project = Project::from_path(Path::new(
"tests/satisfiability/old_lock_file/pyproject.toml",
"tests/data/satisfiability/old_lock_file/pyproject.toml",
))
.unwrap();
pixi::environment::update_prefix(&project.default_environment(), LockFileUsage::Update, false)
.await
.unwrap();
assert_eq!(
lock_str,
std::fs::read_to_string("tests/satisfiability/old_lock_file/pixi.lock").unwrap()
std::fs::read_to_string("tests/data/satisfiability/old_lock_file/pixi.lock").unwrap()
);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/integration_rust/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mod add_tests;
mod common;
mod init_tests;
mod install_tests;
mod project_tests;
mod pypi_tests;
mod solve_group_tests;
mod task_tests;
mod test_activation;
mod update_tests;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod common;

use std::path::PathBuf;

use insta::assert_debug_snapshot;
Expand Down Expand Up @@ -94,7 +92,7 @@ async fn parse_project() {
.collect()
}

let pixi_toml = include_str!("./pixi_tomls/many_targets.toml");
let pixi_toml = include_str!("../data/pixi_tomls/many_targets.toml");
let project = Project::from_str(&PathBuf::from("./many/pixi.toml"), pixi_toml).unwrap();
assert_debug_snapshot!(dependency_names(&project, Platform::Linux64));
assert_debug_snapshot!(dependency_names(&project, Platform::OsxArm64));
Expand Down
4 changes: 1 addition & 3 deletions tests/pypi-tests.rs → tests/integration_rust/pypi_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
mod common;

use std::path::Path;

use crate::common::{LockFileExt, PixiControl};
Expand All @@ -9,7 +7,7 @@ use url::Url;
#[tokio::test]
#[cfg_attr(not(feature = "slow_integration_tests"), ignore)]
async fn test_index_strategy() {
let pypi_indexes = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/pypi-indexes");
let pypi_indexes = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data/pypi-indexes");
let pypi_indexes_url = Url::from_directory_path(pypi_indexes).unwrap();

let pixi = PixiControl::from_manifest(&format!(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: tests/project_tests.rs
source: tests/integration_rust/project_tests.rs
expression: "dependency_names(&project, Platform::OsxArm64)"
---
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: tests/project_tests.rs
source: tests/integration_rust/project_tests.rs
expression: "dependency_names(&project, Platform::Win64)"
---
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
source: tests/project_tests.rs
source: tests/integration_rust/project_tests.rs
expression: "dependency_names(&project, Platform::Linux64)"
---
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ use crate::common::{
LockFileExt, PixiControl,
};

mod common;

#[tokio::test]
async fn conda_solve_group_functionality() {
let mut package_database = PackageDatabase::default();
Expand Down Expand Up @@ -389,7 +387,7 @@ async fn test_we_record_not_present_package_as_purl_for_custom_mapping() {
name = "test-channel-change"
channels = ["conda-forge"]
platforms = ["linux-64"]
conda-pypi-map = { 'conda-forge' = "tests/mapping_files/compressed_mapping.json" }
conda-pypi-map = { 'conda-forge' = "tests/data/mapping_files/compressed_mapping.json" }
"#,
)
.unwrap();
Expand Down Expand Up @@ -475,7 +473,7 @@ async fn test_custom_mapping_channel_with_suffix() {
name = "test-channel-change"
channels = ["conda-forge"]
platforms = ["linux-64"]
conda-pypi-map = { "https://conda.anaconda.org/conda-forge/" = "tests/mapping_files/custom_mapping.json" }
conda-pypi-map = { "https://conda.anaconda.org/conda-forge/" = "tests/data/mapping_files/custom_mapping.json" }
"#,
)
.unwrap();
Expand Down Expand Up @@ -526,7 +524,7 @@ async fn test_repo_data_record_channel_with_suffix() {
name = "test-channel-change"
channels = ["conda-forge"]
platforms = ["linux-64"]
conda-pypi-map = { "https://conda.anaconda.org/conda-forge" = "tests/mapping_files/custom_mapping.json" }
conda-pypi-map = { "https://conda.anaconda.org/conda-forge" = "tests/data/mapping_files/custom_mapping.json" }
"#,
)
.unwrap();
Expand Down Expand Up @@ -577,7 +575,7 @@ async fn test_path_channel() {
name = "test-channel-change"
channels = ["file:///home/user/staged-recipes/build_artifacts"]
platforms = ["linux-64"]
conda-pypi-map = {"file:///home/user/staged-recipes/build_artifacts" = "tests/mapping_files/custom_mapping.json"}
conda-pypi-map = {"file:///home/user/staged-recipes/build_artifacts" = "tests/data/mapping_files/custom_mapping.json"}
"#,
)
.unwrap();
Expand Down
2 changes: 0 additions & 2 deletions tests/task_tests.rs → tests/integration_rust/task_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use rattler_conda_types::Platform;
use std::fs;
use std::path::PathBuf;

mod common;

#[tokio::test]
pub async fn add_remove_task() {
let pixi = PixiControl::new().unwrap();
Expand Down
Loading

0 comments on commit 1ee9605

Please sign in to comment.