From 13dc95611e123d36ec394ed5a28ec0b8827ab0d2 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 1 May 2024 12:31:07 +0100 Subject: [PATCH] Cleanup namespace handling in tests (#100) * Cleanup namespace handling in tests When we did a lot of recent Python2-isms cleanup recently it broke some tests when run in an environment where a previous version of paste, or one of the consumers of its namespace package, were already installed. This was probably done to quiet warnings. However, it hides issues with complex environments. In addition to fixing the problem, this change adds a tox test environment that should cause a failure if we introduce the error again. Fixes #99 * remove skipsdist to see if that ensures namespace * update LICENSE per #101 --- .github/workflows/tests.yaml | 2 ++ LICENSE | 1 + MANIFEST.in | 1 + tests/__init__.py | 6 ++++++ tests/cgiapp_data/form.cgi | 11 ++++++++++- tox.ini | 20 +++++++++++++++++--- 6 files changed, 37 insertions(+), 4 deletions(-) create mode 120000 LICENSE diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ac3ceff3..c72b6cae 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,6 +17,8 @@ jobs: env: py310 - python: "3.11" env: py311 + - python: "3.11" + env: py311-namespace - python: "3.12" env: py312 - python: pypy-3.10 diff --git a/LICENSE b/LICENSE new file mode 120000 index 00000000..7ca850b6 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +docs/license.txt \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in index cc3f4ba4..996cd675 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -4,6 +4,7 @@ include docs/conf.py include docs/test_server.ini include regen-docs include tox.ini +include LICENSE recursive-exclude docs/_build/_sources * recursive-include docs/_build *.html recursive-include tests *.txt *.py *.cgi *.html diff --git a/tests/__init__.py b/tests/__init__.py index cafcf8aa..2f101034 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1,7 @@ """Tests for Paste""" +import sys +import os + +sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) + +import pkg_resources diff --git a/tests/cgiapp_data/form.cgi b/tests/cgiapp_data/form.cgi index e751aa04..21dca131 100755 --- a/tests/cgiapp_data/form.cgi +++ b/tests/cgiapp_data/form.cgi @@ -4,11 +4,20 @@ print('Content-type: text/plain') print('') import sys +import warnings from os.path import dirname base_dir = dirname(dirname(dirname(__file__))) sys.path.insert(0, base_dir) +with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=DeprecationWarning) + try: + import pkg_resources + except ImportError: + # Ignore + pass + from paste.util.field_storage import FieldStorage class FormFieldStorage(FieldStorage): @@ -52,7 +61,7 @@ class FormFieldStorage(FieldStorage): return False -form = FieldStorage() +form = FormFieldStorage() print('Filename:', form['up'].filename) print('Name:', form['name'].value) diff --git a/tox.ini b/tox.ini index f58ba414..f6159ad8 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,28 @@ [tox] -envlist = py{36, 37, 38, 39, 310, 311, 312, py} +envlist = py{36, 37, 38, 39, 310, 311, 312, py},py311-namespace + +[base] +deps = + pytest + setuptools [testenv] # For performance, but also for using "source" with coveragepy (https://github.com/nedbat/coveragepy/issues/268). usedevelop = True deps = - pytest + {[base]deps} coverage: coverage coverage: pytest-cov setenv = coverage: PYTEST_ADDOPTS=--cov --cov-report=term-missing commands = - pytest {posargs} + python -m pytest {posargs} + +# Test an environment where paste, pastedeploy and pastescript are already +# installed. +[testenv:py311-namespace] +deps = + {[base]deps} + Paste==3.9.0 + PasteDeploy + pastescript