Skip to content

Commit

Permalink
Add support for Python 3.11. (#99)
Browse files Browse the repository at this point in the history
Work around python/cpython#90113 which strikes on Python 3.11.
Fix GHA: ubuntu-latest no longer contains Python 2.7 up to 3.6
  • Loading branch information
Michael Howitz committed Dec 20, 2022
1 parent 91c8463 commit 9cb3064
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 41 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu
- ["ubuntu", "ubuntu-20.04"]
config:
# [Python version, tox env]
- ["3.9", "lint"]
Expand All @@ -28,22 +28,23 @@ jobs:
- ["3.8", "py38"]
- ["3.9", "py39"]
- ["3.10", "py310"]
- ["3.11", "py311"]
- ["pypy-2.7", "pypy"]
- ["pypy-3.7", "pypy3"]
- ["3.9", "docs"]
- ["3.9", "coverage"]

runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os[1] }}
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
name: ${{ matrix.config[1] }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.config[0] }}
- name: Pip cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.config[0] }}-${{ hashFiles('setup.*', 'tox.ini') }}
Expand Down
3 changes: 2 additions & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/zopefoundation/meta/tree/master/config/pure-python
[meta]
template = "pure-python"
commit-id = "d5b6c610d0ec7f0b8f6bbba49353eb89288f62b1"
commit-id = "200573eb414d2228d463da3de7d71a6d6335a704"

[python]
with-windows = false
Expand All @@ -11,6 +11,7 @@ with-future-python = false
with-legacy-python = true
with-docs = true
with-sphinx-doctests = true
with-macos = false

[tox]
use-flake8 = true
Expand Down
6 changes: 4 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
CHANGES
=======

5.6.2 (unreleased)
------------------
5.7 (unreleased)
----------------

- Add support for Python 3.11.

- Do not break in ``mechRepr`` when using ``<input type="date">``.

Expand Down
16 changes: 12 additions & 4 deletions docs/narrative.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1679,12 +1679,21 @@ Handling Errors
Often WSGI middleware or the application itself gracefully handle application
errors, such as invalid URLs:

**Caution:** Because of https://github.com/python/cpython/issues/90113 we
currently are not able to demonstrate this feature here as it breaks on Python
3.11.

.. doctest::

>>> # Work around https://github.com/python/cpython/issues/90113
>>> browser.raiseHttpErrors = False

>>> # Without the workaround we would see a traceback for the next call:
>>> browser.open('http://localhost/invalid')
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found
>>> browser.headers['status']
'404 Not Found'
>>> # Reset work around:
>>> browser.raiseHttpErrors = True

Note that the above error was thrown by ``mechanize`` and not by the
application. For debugging purposes, however, it can be very useful to see the
Expand Down Expand Up @@ -1802,4 +1811,3 @@ correctly on the request:
'https'

see http://www.python.org/dev/peps/pep-3333/ for details.

3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

setup(
name='zope.testbrowser',
version='5.6.2.dev0',
version='5.7.dev0',
url='https://github.com/zopefoundation/zope.testbrowser',
license='ZPL 2.1',
project_urls={
Expand All @@ -52,6 +52,7 @@
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Testing',
Expand Down
32 changes: 14 additions & 18 deletions src/zope/testbrowser/fixed-bugs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ The problem is that e.g. a simple 403 status raises an exception.
This is how it works with a simple open():

>>> browser.handleErrors = False
>>> # Work around https://github.com/python/cpython/issues/90113
>>> browser.raiseHttpErrors = False

>>> browser.open('http://localhost/set_status.html')
>>> print(browser.contents)
Everything fine

>>> browser.open('http://localhost/set_status.html?status=403')
Traceback (most recent call last):
...
HTTPError: HTTP Error 403: Forbidden
>>> browser.headers['status']
'403 Forbidden'

>>> print(browser.contents)
Just set a status of 403
Expand All @@ -135,9 +136,8 @@ A link:
<html>...

>>> browser.getLink('403').click()
Traceback (most recent call last):
...
HTTPError: HTTP Error 403: Forbidden
>>> browser.headers['status']
'403 Forbidden'

>>> print(browser.contents)
Just set a status of 403
Expand All @@ -150,9 +150,8 @@ A submit button:

>>> browser.getControl(name='status').value = '404'
>>> browser.getControl('Submit This').click()
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found
>>> browser.headers['status']
'404 Not Found'

>>> print(browser.contents)
Just set a status of 404
Expand All @@ -165,9 +164,8 @@ A submit image control:

>>> browser.getControl(name='status').value = '403'
>>> browser.getControl(name='image-value').click()
Traceback (most recent call last):
...
HTTPError: HTTP Error 403: Forbidden
>>> browser.headers['status']
'403 Forbidden'

>>> print(browser.contents)
Just set a status of 403
Expand All @@ -180,9 +178,8 @@ A javascript-ish form submit:

>>> browser.getControl(name='status').value = '404'
>>> browser.getForm(name='theform').submit()
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found
>>> browser.headers['status']
'404 Not Found'

>>> print(browser.contents)
Just set a status of 404
Expand All @@ -195,9 +192,8 @@ A non-javascript-ish form submit:

>>> browser.getControl(name='status').value = '403'
>>> browser.getForm(name='theform').submit(name='submit-value')
Traceback (most recent call last):
...
HTTPError: HTTP Error 403: Forbidden
>>> browser.headers['status']
'403 Forbidden'

>>> print(browser.contents)
Just set a status of 403
12 changes: 4 additions & 8 deletions src/zope/testbrowser/over_the_wire.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ on zope.i18n locale-based formatting or a similar approach.

The browser can `open` web pages:

>>> # This is tricky, since in Germany I am forwarded to google.de usually;
>>> # The `ncr` forces to really go to google.com.
>>> browser.open('http://google.com/ncr')
Traceback (most recent call last):
...
RobotExclusionError: HTTP Error 403: request disallowed by robots.txt

Oops! Google doesn't let robots use their search engine. Oh well.
>>> browser.open('https://www.w3.org')
>>> print(browser.contents)
<!DOCTYPE html ...
...The World Wide Web Consortium (W3C) is an international community...
6 changes: 4 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ envlist =
py38
py39
py310
py311
pypy
pypy3
docs
Expand Down Expand Up @@ -45,6 +46,7 @@ deps =

[testenv:isort-apply]
basepython = python3
skip_install = true
commands_pre =
deps =
isort
Expand All @@ -70,8 +72,8 @@ commands =
mkdir -p {toxinidir}/parts/htmlcov
coverage run -m zope.testrunner --test-path=src {posargs:-vc}
coverage run -a -m sphinx -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest
coverage html
coverage report -m --fail-under=70
coverage html --ignore-errors
coverage report --ignore-errors --show-missing --fail-under=70

[coverage:run]
branch = True
Expand Down

0 comments on commit 9cb3064

Please sign in to comment.