Skip to content

Commit

Permalink
Improve pip package manager tests (#256)
Browse files Browse the repository at this point in the history
Whilst writing the tests for the upcoming Poetry support, I made a few
changes to the overall package manager testing strategy (such as using
a testing buildpack to verify that at build time the tools and env vars
are configured correctly) - which I've split out of the later PRs for
easier review.

In particular, the new testing buildpack added here is what helped me
debug and locate this upstream lifecycle build time env vars bug (which
would have broken apps when we switch to venvs shortly):
buildpacks/lifecycle#1393

GUS-W-16617242.
  • Loading branch information
edmorley committed Aug 30, 2024
1 parent e988580 commit f005cd3
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 147 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/pip_basic/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This package has been picked since it has no dependencies and is small/fast to install.
typing-extensions==4.7.1
typing-extensions==4.12.2
2 changes: 1 addition & 1 deletion tests/fixtures/pip_editable_git_compiled/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# The URL to the package is specified via env var, to test that user-provided env vars
# are propagated to pip for use by its env var interpolation feature.

-e git+${WHEEL_PACKAGE_URL}@0.40.0#egg=extension.dist&subdirectory=tests/testdata/extension.dist
-e git+${WHEEL_PACKAGE_URL}@0.44.0#egg=extension.dist&subdirectory=tests/testdata/extension.dist
24 changes: 24 additions & 0 deletions tests/fixtures/testing_buildpack/bin/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

# Check that:
# - The correct env vars are set for later buildpacks.
# - Python's sys.path is correct.
# - The correct version of pip was installed.
# - Both the package manager and Python can find the typing-extensions package.
# - The system site-packages directory is protected against running 'pip install'
# without having passed '--user'.
# - The typing-extensions package was installed into a separate dependencies layer.

set -euo pipefail

echo
echo "## Testing buildpack ##"

printenv | sort | grep -vE '^(_|CNB_.+|HOME|HOSTNAME|OLDPWD|PWD|SHLVL)='
echo
python -c 'import pprint, sys; pprint.pp(sys.path)'
echo
pip --version
pip list
pip install --dry-run typing-extensions
python -c 'import typing_extensions; print(typing_extensions)'
3 changes: 3 additions & 0 deletions tests/fixtures/testing_buildpack/bin/detect
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

exit 0
6 changes: 6 additions & 0 deletions tests/fixtures/testing_buildpack/buildpack.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
api = "0.11"

[buildpack]
id = "testing-buildpack"
version = "0.0.0"
clear-env = true
8 changes: 4 additions & 4 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
//! These tests are not run via automatic integration test discovery, but instead are
//! imported in main.rs so that they have access to private APIs (see comment in main.rs).

use libcnb_test::BuildConfig;
use std::env;
use std::path::Path;

mod detect_test;
mod django_test;
mod package_manager_test;
mod pip_test;
mod python_version_test;

use libcnb_test::BuildConfig;
use std::env;
use std::path::Path;

const LATEST_PYTHON_3_7: &str = "3.7.17";
const LATEST_PYTHON_3_8: &str = "3.8.19";
const LATEST_PYTHON_3_9: &str = "3.9.19";
Expand Down
300 changes: 159 additions & 141 deletions tests/pip_test.rs

Large diffs are not rendered by default.

0 comments on commit f005cd3

Please sign in to comment.