Files
heroku-buildpack-python/test/run-versions
T
Ed Morley a98ef91566 Tests: Clean up the Python version unit tests (#1092)
* Fixes the "Installing <version>" assertions so that they don't false
  positive against the "please upgrade to <version>" output.
* Removes modification of test fixtures during tests, since it can lead
  to failures depending on test order, and confusion when debugging.
* Updates the PyPy version warning tests to use a slightly newer (but
  still not latest) PyPy version, which means that the test now passes
  on Cedar-14 and can be unskipped.
* Switches to using an empty requirements file for version tests that
  duplicate the main test, to save spending time installing dependencies
  unnecessarily.
* Switches the NLTK test to using the default buildpack Python version,
  rather than an ancient Python 3.6.
* Skips the Python 3.7/3.8 tests on Cedar-14 rather than asserting
  failure, since we know they'll never pass due to Cedar-14's libssl being
  older than required.
* Removes redundant `testSqliteInstall` test since it duplicates the
  Python version install tests.

Longer term I'll be moving many of the unit tests to Hatchet, however
this at least makes the tests more dependable in the meantime.

Closes @W-8060219@.
Closes @W-8176779@.

[skip changelog]
2020-10-07 15:10:20 +01:00

238 lines
6.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Default Python Versions
# shellcheck source=bin/default_pythons
source "bin/default_pythons"
testPythonVersionUnspecified() {
compile "python_version_unspecified"
assertCaptured "Installing ${DEFAULT_PYTHON_VERSION}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython2_7() {
compile "python2"
assertCaptured "Installing ${LATEST_27}"
assertCaptured "python-2-7-eol-faq";
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 44.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython2_7_warn() {
compile "python2_warn"
assertCaptured "Installing python-2.7.15"
assertCaptured "python-2-7-eol-faq";
assertCaptured "Only the latest version"
assertCaptured "${LATEST_27}"
assertCapturedSuccess
}
testPython3_4() {
compile "python3_4"
assertCaptured "Installing ${LATEST_34}"
assertNotCaptured "security update"
assertCaptured "Installing pip 19.1.1, setuptools 43.0.0 and wheel 0.33.6"
assertCaptured "Installing SQLite3"
# Can't use `assertCapturedSuccess` since Pip outputs a Python 3.4 EOL warning to stderr,
# and the newest Pip that works on Python 3.4 doesn't support `PIP_NO_PYTHON_VERSION_WARNING`.
assertCapturedSuccessWithStdErr
}
testPython3_4_warn() {
compile "python3_4_warn"
assertCaptured "Installing python-3.4.9"
assertCaptured "security update!"
assertCaptured "${LATEST_34}"
# Can't use `assertCapturedSuccess` since Pip outputs a Python 3.4 EOL warning to stderr,
# and the newest Pip that works on Python 3.4 doesn't support `PIP_NO_PYTHON_VERSION_WARNING`.
assertCapturedSuccessWithStdErr
}
testPython3_5() {
compile "python3_5"
assertCaptured "Installing ${LATEST_35}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython3_5_warn() {
compile "python3_5_warn"
assertCaptured "Installing python-3.5.6"
assertCaptured "security update!"
assertCaptured "${LATEST_35}"
assertCapturedSuccess
}
testPython3_6() {
compile "python3_6"
assertCaptured "Installing ${LATEST_36}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython3_6_warn() {
compile "python3_6_warn"
assertCaptured "Installing python-3.6.7"
assertCaptured "security update!"
assertCaptured "${LATEST_36}"
assertCapturedSuccess
}
testPython3_7() {
# Python 3.7+ requires newer libssl than is present on Cedar-14.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
compile "python3_7"
assertCaptured "Installing ${LATEST_37}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython3_7_warn() {
# Python 3.7+ requires newer libssl than is present on Cedar-14.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
compile "python3_7_warn"
assertCaptured "Installing python-3.7.1"
assertCaptured "security update!"
assertCaptured "${LATEST_37}"
assertCapturedSuccess
}
testPython3_8() {
# Python 3.7+ requires newer libssl than is present on Cedar-14.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
compile "python3_8"
assertCaptured "Installing ${LATEST_38}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython3_8_warn() {
# Python 3.7+ requires newer libssl than is present on Cedar-14.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
compile "python3_8_warn"
assertCaptured "Installing python-3.8.0"
assertCaptured "security update!"
assertCaptured "${LATEST_38}"
assertCapturedSuccess
}
testPython3_9() {
# Cedar-14 is EOL, so we're not building new major Python versions for it.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
compile "python3_9"
assertCaptured "Installing ${LATEST_39}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCaptured "Installing SQLite3"
assertCapturedSuccess
}
testPython3_9_warn() {
# Cedar-14 is EOL, so we're not building new major Python versions for it.
if [[ "${STACK}" = "cedar-14" ]]; then
return
fi
# Can't test the version warning until there is at least one old version of Python 3.9.
if [[ "${LATEST_39}" = "python-3.9.0" ]]; then
return
fi
compile "python3_9_warn"
assertCaptured "Installing python-3.9.0"
assertCaptured "security update!"
assertCaptured "${LATEST_39}"
assertCapturedSuccess
}
testPythonVersionInvalid() {
compile "python_version_invalid"
assertCaptured "Requested runtime (python-3.8.99) is not available for this stack"
assertCaptured "Aborting"
assertCapturedError
}
testPypy3_6() {
compile "pypy3_6"
assertCaptured "Installing ${LATEST_PYPY_36}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 47.1.1 and wheel 0.34.2"
assertCapturedSuccess
}
testPypy3_6_warn() {
compile "pypy3_6_warn"
assertCaptured "Installing pypy3.6-7.3.1"
assertCaptured "security update!"
assertCaptured "${LATEST_PYPY_36}"
assertCapturedSuccess
}
testPypy2_7() {
compile "pypy2_7"
assertCaptured "Installing ${LATEST_PYPY_27}"
assertNotCaptured "security update"
assertCaptured "Installing pip 20.1.1, setuptools 44.1.1 and wheel 0.34.2"
assertCapturedSuccess
}
testPypy2_7_warn() {
compile "pypy2_7_warn"
assertCaptured "Installing pypy2.7-7.3.1"
assertCaptured "security update!"
assertCaptured "${LATEST_PYPY_27}"
assertCapturedSuccess
}
testStickyPythonVersion() {
local cache_dir="$(mktmpdir)"
compile "python3_6_warn" "$cache_dir"
assertCaptured "Installing python-3.6.7"
assertCapturedSuccess
compile "python_version_unspecified" "$cache_dir"
assertNotCaptured "Installing python"
assertCaptured "security update!"
assertCapturedSuccess
# Whilst this file seems like an implementation detail (so something that should
# not be tested), we must guarantee the filename remains consistent for backwards
# compatibility across buildpack versions for already-built apps.
assertFile "python-3.6.7" ".heroku/python-version"
}
testPythonVersionChange() {
local cache_dir="$(mktmpdir)"
compile "python3_6_warn" "$cache_dir"
assertCaptured "Installing python-3.6.7"
assertCapturedSuccess
compile "python3_6" "$cache_dir"
assertCaptured "Found python-3.6.7, removing"
assertCapturedSuccess
}
pushd $(dirname 0) >/dev/null
popd >/dev/null
source $(pwd)/test/utils
source $(pwd)/test/shunit2