From 5e1fe799439a069eb71519d2b1c7788150a657bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Wed, 6 May 2020 09:57:35 -0400 Subject: fix lint check --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 8c36c5f01..756233bd0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,4 +20,4 @@ ignore = *.egg-info/* ignore-default-rules = true ignore-bad-ideas = - tests/pkgs/localeapp/* + tests/pkgs/localeapp/**/*.mo -- cgit v1.2.3 From 400491ca6582bd70f18686b0f954cb32fdee26e0 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:12:53 -0700 Subject: Update coveragerc to add an additional path --- .coveragerc | 1 + 1 file changed, 1 insertion(+) diff --git a/.coveragerc b/.coveragerc index d0a1fd54a..4009892ea 100644 --- a/.coveragerc +++ b/.coveragerc @@ -6,6 +6,7 @@ source = [paths] source = src/pyramid + */src/pyramid */site-packages/pyramid [report] -- cgit v1.2.3 From a4d35b2cd24731036c381248c3f0eb475dcd2f8f Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:13:20 -0700 Subject: Add configuration for pytest --- setup.cfg | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/setup.cfg b/setup.cfg index 756233bd0..a7a5ff4fe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,10 +1,6 @@ [easy_install] zip_ok = false -[nosetests] -match = ^test -nocapture = 1 - [aliases] dev = develop easy_install pyramid[testing] docs = develop easy_install pyramid[docs] @@ -21,3 +17,9 @@ ignore = ignore-default-rules = true ignore-bad-ideas = tests/pkgs/localeapp/**/*.mo + +[tool:pytest] +python_files = test_*.py +testpaths = + tests +addopts = -W always --cov -- cgit v1.2.3 From cb2be5f16dad334e4718852f27c6408c3d2d6d4a Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:13:41 -0700 Subject: Add testing requires for pytest/pytest-cov --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 2487d0952..1a334efe2 100644 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ docs_extras = [ 'sphinxcontrib-autoprogram', ] -testing_extras = tests_require + ['coverage', 'nose'] +testing_extras = tests_require + ['coverage', 'pytest', 'pytest-cov'] branch_version = ".".join(VERSION.split(".")[:2]) -- cgit v1.2.3 From 66fc1ccc27b445dfadf16b09a7e838f6aac21899 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:14:03 -0700 Subject: Update tox.ini to run pytest instead --- tox.ini | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tox.ini b/tox.ini index 74f5cfbbd..45e786684 100644 --- a/tox.ini +++ b/tox.ini @@ -2,16 +2,14 @@ envlist = lint, py35,py36,py37,py38,pypy3, - docs,py36-cover,coverage, + docs,coverage, [testenv] commands = - cover: coverage run \ - {envbindir}/nosetests --with-xunit --xunit-file=nosetests-{envname}.xml {posargs:} + python --version + pytest {posargs:} extras = testing -deps = - cover: coverage setenv = COVERAGE_FILE=.coverage.{envname} -- cgit v1.2.3 From 72eca2f8e82f1af20e433218719d99e7627d5650 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:14:30 -0700 Subject: Fix tests that depend on the test runner --- tests/test_path.py | 4 ++-- tests/test_util.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_path.py b/tests/test_path.py index 384460fb1..c9cfde2b6 100644 --- a/tests/test_path.py +++ b/tests/test_path.py @@ -101,10 +101,10 @@ class TestCallerPackage(unittest.TestCase): self.assertEqual(result, tests) def test_it_level_3(self): - import unittest + import _pytest result = self._callFUT(3) - self.assertEqual(result, unittest) + self.assertEqual(result, _pytest) def test_it_package(self): import tests diff --git a/tests/test_util.py b/tests/test_util.py index 93493c683..f79cdeb85 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -492,8 +492,7 @@ class Test_object_description(unittest.TestCase): def test_method(self): self.assertEqual( self._callFUT(self.test_method), - 'method test_method of class tests.test_util.' - 'Test_object_description', + 'function tests.test_util.test_method', ) def test_class(self): -- cgit v1.2.3 From b6df90d05262dc24a91f7edd1e477cf7e8a9fff6 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 01:03:03 -0700 Subject: Cleanup nosetest mentions in docs Co-authored-by: Steve Piercy --- HACKING.txt | 69 +++++++++++++++++++------------------- docs/typographical-conventions.rst | 9 ++--- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/HACKING.txt b/HACKING.txt index 87c96aef1..7e4969990 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -8,7 +8,7 @@ Using a Development Checkout ---------------------------- You will have to create a development environment to hack on Pyramid, using a -Pyramid checkout. We use `tox` to run tests, run test coverage, and build +Pyramid checkout. We use `tox` to run tests, run test coverage, and build documentation. tox docs: https://tox.readthedocs.io/en/latest/ @@ -25,6 +25,22 @@ tox on PyPI: https://pypi.org/project/tox/ Alternatively, create a writeable fork on GitHub and clone it. +- Make sure that `tox` is installed, either in your path, or locally. Examples + below assume that `tox` was installed with: + + $ pip3 install --user tox + $ export TOX=$(python3 -c 'import site; print(site.USER_BASE + "/bin")')/tox + + Feel free to use whatever is your favorite method for installation. One + popular method uses `pipx` (https://github.com/pipxproject/pipx). + + Before you file a pull request, we recommend that you run your proposed + change through `tox`. `tox` will fully validate that all tests work, all + supported formats of documentation will build and their doctests pass, and + test coverage is 100%, across all supported versions of Python. `tox` will + only run builds for Python versions that you have installed and made + available to `tox`. Setting up that environment is outside the scope of this + document. Adding Features --------------- @@ -51,58 +67,43 @@ Coding Style - Pyramid uses Black (https://pypi.org/project/black/) and isort (https://pypi.org/project/isort/) for code formatting style. To run formatters: - $ tox -e format + $ $TOX -e format Running Tests ------------- -- The `tox.ini` uses `nose` and `coverage`. As such `tox` may be used +- The `tox.ini` uses `pytest` and `coverage`. As such `tox` may be used to run groups of tests or only a specific version of Python. For example, the - following command will run tests on Python 3.7 only without coverage: + following command will run tests on the same version of Python that `tox` is + installed with: - $ tox -e py37 + $ $TOX -e py - This command will run tests on the latest version of Python 3 with coverage. + To run `tox` for Python 3.8 explicitly, you may use: - $ tox -e py36-cover,coverage + $ $TOX -e py38 -- To run individual tests (i.e., during development), you can use `nosetests` +- To run individual tests (i.e., during development), you can use `pytest` syntax as follows, where `$VENV` is an environment variable set to the path to your virtual environment: # run a single test - $ $VENV/bin/nosetests tests.test_module:ClassName.test_mytestname + $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed::test_it_with_default_body_tmpl # run all tests in a class - $ $VENV/bin/nosetests tests.test_module:ClassName - - Optionally you can install a nose plugin `nose-selecttests` to run specific - tests. - https://pypi.org/project/nose-selecttests/ - For example, use a regular expression with the `-t` parameter to run tests. - - # run a single test - $ $VENV/bin/nosetests -t test_mytestname - -- The tests can also be run using `pytest`. - https://docs.pytest.org/en/latest/ - This is intended as a convenience for people who prefer `pytest`. Run the - tests like so: - - $ $VENV/bin/pip install pytest - $ $VENV/bin/pytest --strict pyramid/ tests/ + $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed - To run individual tests (i.e., during development), see "pytest usage - - Specifying tests / selecting tests": +- For more information on how to use pytest, please refer to the pytest + documentation for selecting tests: https://docs.pytest.org/en/latest/usage.html#specifying-tests-selecting-tests Test Coverage ------------- -- The codebase *must* have 100% test statement coverage after each commit. You - can test coverage via `tox -epy3-cover,coverage`. +- The codebase *must* have 100% test statement coverage after each commit. You + can test coverage via `tox -e py38`. Documentation Coverage and Building HTML Documentation @@ -111,11 +112,11 @@ Documentation Coverage and Building HTML Documentation If you fix a bug, and the bug requires an API or behavior modification, all documentation in this package which references that API or behavior must be changed to reflect the bug fix, ideally in the same commit that fixes the bug -or adds the feature. To build and review docs, use the following steps. +or adds the feature. To build and review docs, use the following steps. 1. In the main Pyramid checkout directory, run `tox -e docs`: - $ tox -e docs + $ $TOX -e docs 2. Open the `.tox/docs/html/index.html` file to see the resulting HTML rendering. @@ -125,6 +126,6 @@ Change Log ---------- - Feature additions and bugfixes must be added to the `CHANGES.rst` - file in the prevailing style. Changelog entries should be long and - descriptive, not cryptic. Other developers should be able to know + file in the prevailing style. Changelog entries should be long and + descriptive, not cryptic. Other developers should be able to know what your changelog entry means. diff --git a/docs/typographical-conventions.rst b/docs/typographical-conventions.rst index 7f052cbc8..0a9c194e4 100644 --- a/docs/typographical-conventions.rst +++ b/docs/typographical-conventions.rst @@ -98,10 +98,11 @@ ini: .. code-block:: ini - [nosetests] - match=^test - where=pyramid - nocapture=1 + [tool:pytest] + python_files = test_*.py + testpaths = + tests + addopts = -W always --cov Interactive Python: -- cgit v1.2.3 From 57687face8ec3a912d6d886b8b2bcf27a97c82d0 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 23:23:22 -0700 Subject: Disable coverage by default Use a special py38-cover testenv in tox to re-enable coverage reporting. --- .travis.yml | 4 ++-- setup.cfg | 2 +- tox.ini | 9 ++++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index c762c085b..57c8b935d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,8 @@ matrix: env: TOXENV=py36 - python: pypy3 env: TOXENV=pypy3 - - python: 3.6 - env: TOXENV=py36-cover,coverage + - python: 3.8 + env: TOXENV=py38-cover,coverage - python: 3.6 env: TOXENV=docs - python: 3.6 diff --git a/setup.cfg b/setup.cfg index a7a5ff4fe..83f985f93 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,4 +22,4 @@ ignore-bad-ideas = python_files = test_*.py testpaths = tests -addopts = -W always --cov +addopts = -W always diff --git a/tox.ini b/tox.ini index 45e786684..91baa42db 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,8 @@ envlist = lint, py35,py36,py37,py38,pypy3, - docs,coverage, + py38-cover,coverage, + docs [testenv] commands = @@ -13,6 +14,11 @@ extras = setenv = COVERAGE_FILE=.coverage.{envname} +[testenv:py38-cover] +commands = + python --version + pytest --cov {posargs:} + [testenv:lint] skip_install = true commands = @@ -52,6 +58,7 @@ deps = coverage setenv = COVERAGE_FILE=.coverage +depends = py38-cover [testenv:format] skip_install = true -- cgit v1.2.3 From 2f3e7cd6365f87659aa3787cbecaee38b5a9b1d7 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Wed, 6 May 2020 22:42:46 -0500 Subject: remove some unnecessary flags --- HACKING.txt | 4 ++-- docs/typographical-conventions.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HACKING.txt b/HACKING.txt index 7e4969990..730d08208 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -89,10 +89,10 @@ Running Tests to your virtual environment: # run a single test - $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed::test_it_with_default_body_tmpl + $ $TOX -e py -- tests/test_httpexceptions.py::TestHTTPMethodNotAllowed::test_it_with_default_body_tmpl # run all tests in a class - $ $TOX -e py -- --no-cov tests/test_httpexceptions.py::TestHTTPMethodNotAllowed + $ $TOX -e py -- tests/test_httpexceptions.py::TestHTTPMethodNotAllowed - For more information on how to use pytest, please refer to the pytest documentation for selecting tests: diff --git a/docs/typographical-conventions.rst b/docs/typographical-conventions.rst index 0a9c194e4..9a83a16f1 100644 --- a/docs/typographical-conventions.rst +++ b/docs/typographical-conventions.rst @@ -102,7 +102,7 @@ ini: python_files = test_*.py testpaths = tests - addopts = -W always --cov + addopts = -W always Interactive Python: -- cgit v1.2.3 From 38edc98fb97b5f89745a9626e01023953c4973ef Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:29:25 -0700 Subject: Add github CI workflows --- .gitattributes | 5 +++ .github/workflows/ci-tests.yml | 88 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/workflows/ci-tests.yml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..a446231f1 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Set the default behaviour, in case poeple don't have core.autocrlf set +* text=auto + +# Always lf, this file size is checked in a test +tests/fixtures/static/encoded.html text eol=lf diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml new file mode 100644 index 000000000..366c0ffcf --- /dev/null +++ b/.github/workflows/ci-tests.yml @@ -0,0 +1,88 @@ +name: Build and test + +on: + # Only on pushes to master or one of the release branches we build on push + push: + branches: + - master + - "[0-9].[0-9]+-branch" + tags: + # Build pull requests + pull_request: + +jobs: + test: + strategy: + matrix: + py: + - "3.5" + - "3.6" + - "3.7" + - "3.8" + - "pypy3" + os: + - "ubuntu-latest" + - "windows-latest" + - "macos-latest" + architecture: + - x64 + - x86 + + exclude: + # Linux and macOS don't have x86 python + - os: "ubuntu-latest" + architecture: x86 + - os: "macos-latest" + architecture: x86 + # PyPy3 on Windows doesn't seem to work + - os: "windows-latest" + py: "pypy3" + + name: "Python: ${{ matrix.py }}-${{ matrix.architecture }} on ${{ matrix.os }}" + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.py }} + architecture: ${{ matrix.architecture }} + - run: pip install tox + - name: Running tox + run: tox -e py + coverage: + runs-on: ubuntu-latest + name: Validate coverage + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v1 + with: + python-version: 3.8 + architecture: x64 + - run: pip install tox + - run: tox -e py38,coverage + docs: + runs-on: ubuntu-latest + name: Build the documentation + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + architecture: x64 + - run: pip install tox + - run: tox -e docs + lint: + runs-on: ubuntu-latest + name: Lint the package + steps: + - uses: actions/checkout@v2 + - name: Setup python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + architecture: x64 + - run: pip install tox + - run: tox -e lint -- cgit v1.2.3 From c811e3d0e474c52131879c6e93bcb62f0f62ce84 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 00:49:15 -0700 Subject: Remove Travis and AppVeyor --- .travis.yml | 43 ------------------------------------------- appveyor.yml | 23 ----------------------- 2 files changed, 66 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 57c8b935d..000000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -# Wire up travis -language: python -sudo: false - -matrix: - include: - - python: 3.5 - env: TOXENV=py35 - - python: 3.6 - env: TOXENV=py36 - - python: pypy3 - env: TOXENV=pypy3 - - python: 3.8 - env: TOXENV=py38-cover,coverage - - python: 3.6 - env: TOXENV=docs - - python: 3.6 - env: TOXENV=lint - - python: 3.7 - env: TOXENV=py37 - dist: xenial - sudo: true - - python: 3.8 - env: TOXENV=py38 - dist: xenial - sudo: true - -install: - - travis_retry pip install tox - -script: - - travis_retry tox - -cache: - directories: - - $HOME/.cache/pip - -notifications: - email: - - pyramid-checkins@lists.repoze.org - irc: - channels: - - "chat.freenode.net#pyramid" diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index ba07274f8..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,23 +0,0 @@ -environment: - matrix: - - PYTHON: "C:\\Python35" - TOXENV: "py35" - - PYTHON: "C:\\Python36" - TOXENV: "py36" - - PYTHON: "C:\\Python37" - TOXENV: "py37" - - PYTHON: "C:\\Python38" - TOXENV: "py38" - -cache: - - '%LOCALAPPDATA%\pip\Cache' - -version: '{branch}.{build}' - -install: - - "%PYTHON%\\python.exe -m pip install tox" - -build: off - -test_script: - - "%PYTHON%\\Scripts\\tox.exe" -- cgit v1.2.3 From 559aa50281b48634b4cb4df1f4adf322be102f0c Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 01:08:02 -0700 Subject: ignore .gitattributes --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index 83f985f93..a9e760853 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,6 +11,7 @@ license_file = LICENSE.txt [check-manifest] ignore = .gitignore + .gitattributes PKG-INFO *.egg-info *.egg-info/* -- cgit v1.2.3 From 87040469b30f01c3409bd4fdd8e94d3ed24e805d Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Mon, 4 May 2020 23:39:09 -0700 Subject: Enable coverage on CPython test runs --- .github/workflows/ci-tests.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml index 366c0ffcf..a16421a0b 100644 --- a/.github/workflows/ci-tests.yml +++ b/.github/workflows/ci-tests.yml @@ -1,6 +1,6 @@ name: Build and test -on: +on: # Only on pushes to master or one of the release branches we build on push push: branches: @@ -28,6 +28,14 @@ jobs: - x64 - x86 + include: + # Only run coverage on ubuntu-latest, except on pypy3 + - os: "ubuntu-latest" + pytest-args: "--cov" + - os: "ubuntu-latest" + py: "pypy3" + pytest-args: "" + exclude: # Linux and macOS don't have x86 python - os: "ubuntu-latest" @@ -49,7 +57,7 @@ jobs: architecture: ${{ matrix.architecture }} - run: pip install tox - name: Running tox - run: tox -e py + run: tox -e py -- ${{ matrix.pytest-args }} coverage: runs-on: ubuntu-latest name: Validate coverage @@ -61,7 +69,7 @@ jobs: python-version: 3.8 architecture: x64 - run: pip install tox - - run: tox -e py38,coverage + - run: tox -e py38-cover,coverage docs: runs-on: ubuntu-latest name: Build the documentation -- cgit v1.2.3 From 6d52dd4123c1585dd14a628a8789904fd2f5842f Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Wed, 6 May 2020 20:53:56 -0700 Subject: Update build status badge --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 41da33fcb..82f171f89 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ Pyramid ======= -.. image:: https://travis-ci.org/Pylons/pyramid.png?branch=master - :target: https://travis-ci.org/Pylons/pyramid +.. image:: https://github.com/Pylons/Pyramid/workflows/Build%20and%20test/badge.svg?branch=master + :target: https://github.com/Pylons/Pyramid/actions?query=workflow%3A%22Build+and+test%22 :alt: master Travis CI Status .. image:: https://readthedocs.org/projects/pyramid/badge/?version=master -- cgit v1.2.3 From 66b88e8ca86660cbcc63770b29d7c8a370594753 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Wed, 6 May 2020 22:58:26 -0700 Subject: set() -> {} --- src/pyramid/config/adapters.py | 2 +- src/pyramid/config/views.py | 2 +- src/pyramid/csrf.py | 2 +- src/pyramid/predicates.py | 2 +- src/pyramid/scripts/proutes.py | 2 +- src/pyramid/static.py | 4 ++-- src/pyramid/urldispatch.py | 2 +- src/pyramid/viewderivers.py | 6 ++---- tests/test_config/test_views.py | 2 +- tests/test_scripts/test_pserve.py | 12 +++++------- tests/test_util.py | 2 +- 11 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/pyramid/config/adapters.py b/src/pyramid/config/adapters.py index 6a8a0aa32..5035651cb 100644 --- a/src/pyramid/config/adapters.py +++ b/src/pyramid/config/adapters.py @@ -121,7 +121,7 @@ class AdaptersConfiguratorMixin: # with all args, the eventonly hack would not have been required. # At this point, though, using .subscriptions and manual execution # is not possible without badly breaking backwards compatibility. - if all((predicate(*arg) for predicate in predicates)): + if all(predicate(*arg) for predicate in predicates): return derived_subscriber(*arg) if hasattr(subscriber, '__name__'): diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py index 466c31f94..a680eafb3 100644 --- a/src/pyramid/config/views.py +++ b/src/pyramid/config/views.py @@ -196,7 +196,7 @@ def predicated_view(view, info): return view(context, request) def checker(context, request): - return all((predicate(context, request) for predicate in preds)) + return all(predicate(context, request) for predicate in preds) predicate_wrapper.__predicated__ = checker predicate_wrapper.__predicates__ = preds diff --git a/src/pyramid/csrf.py b/src/pyramid/csrf.py index 75ad1b734..8e711c9a7 100644 --- a/src/pyramid/csrf.py +++ b/src/pyramid/csrf.py @@ -335,7 +335,7 @@ def check_csrf_origin( request.registry.settings.get("pyramid.csrf_trusted_origins", []) ) - if request.host_port not in set(["80", "443"]): + if request.host_port not in {"80", "443"}: trusted_origins.append("{0.domain}:{0.host_port}".format(request)) else: trusted_origins.append(request.domain) diff --git a/src/pyramid/predicates.py b/src/pyramid/predicates.py index f51ea3b21..8b443e79b 100644 --- a/src/pyramid/predicates.py +++ b/src/pyramid/predicates.py @@ -271,7 +271,7 @@ class EffectivePrincipalsPredicate: if is_nonstr_iter(val): self.val = set(val) else: - self.val = set((val,)) + self.val = {val} def text(self): return 'effective_principals = %s' % sorted(list(self.val)) diff --git a/src/pyramid/scripts/proutes.py b/src/pyramid/scripts/proutes.py index 75db52182..64cd37727 100644 --- a/src/pyramid/scripts/proutes.py +++ b/src/pyramid/scripts/proutes.py @@ -82,7 +82,7 @@ def _get_request_methods(route_request_methods, view_request_methods): if has_methods and not request_methods: request_methods = '' elif request_methods: - if excludes and request_methods == set([ANY_KEY]): + if excludes and request_methods == {ANY_KEY}: for exclude in excludes: request_methods.add('!%s' % exclude) diff --git a/src/pyramid/static.py b/src/pyramid/static.py index bf843f385..61baa0316 100644 --- a/src/pyramid/static.py +++ b/src/pyramid/static.py @@ -260,7 +260,7 @@ def _add_vary(response, option): response.vary = vary -_seps = set(['/', os.sep]) +_seps = {'/', os.sep} def _contains_slash(item): @@ -269,7 +269,7 @@ def _contains_slash(item): return True -_has_insecure_pathelement = set(['..', '.', '']).intersection +_has_insecure_pathelement = {'..', '.', ''}.intersection @lru_cache(1000) diff --git a/src/pyramid/urldispatch.py b/src/pyramid/urldispatch.py index 37bc70962..7aea1146b 100644 --- a/src/pyramid/urldispatch.py +++ b/src/pyramid/urldispatch.py @@ -85,7 +85,7 @@ class RoutesMapper: if match is not None: preds = route.predicates info = {'match': match, 'route': route} - if preds and not all((p(info, request) for p in preds)): + if preds and not all(p(info, request) for p in preds): continue return info diff --git a/src/pyramid/viewderivers.py b/src/pyramid/viewderivers.py index 7f15559b1..6461c4829 100644 --- a/src/pyramid/viewderivers.py +++ b/src/pyramid/viewderivers.py @@ -46,10 +46,8 @@ class DefaultViewMapper: def __call__(self, view): if is_unbound_method(view) and self.attr is None: raise ConfigurationError( - ( - 'Unbound method calls are not supported, please set the ' - 'class as your `view` and the method as your `attr`' - ) + 'Unbound method calls are not supported, please set the ' + 'class as your `view` and the method as your `attr`' ) if inspect.isclass(view): diff --git a/tests/test_config/test_views.py b/tests/test_config/test_views.py index 6b34f1bd4..2a55ad45d 100644 --- a/tests/test_config/test_views.py +++ b/tests/test_config/test_views.py @@ -3099,7 +3099,7 @@ class TestMultiView(unittest.TestCase): ) mv.add('view5', 100, accept='text/xml') self.assertEqual(mv.media_views['text/xml'], [(100, 'view5', None)]) - self.assertEqual(set(mv.accepts), set(['text/xml', 'text/html'])) + self.assertEqual(set(mv.accepts), {'text/xml', 'text/html'}) self.assertEqual(mv.views, [(99, 'view2', None), (100, 'view', None)]) def test_add_with_phash(self): diff --git a/tests/test_scripts/test_pserve.py b/tests/test_scripts/test_pserve.py index 2feecf3e0..5e5c28c7b 100644 --- a/tests/test_scripts/test_pserve.py +++ b/tests/test_scripts/test_pserve.py @@ -89,13 +89,11 @@ class TestPServeCommand(unittest.TestCase): self.assertEqual(loader.calls[0]['defaults'], {'a': '1'}) self.assertEqual( inst.watch_files, - set( - [ - os.path.abspath('/base/foo'), - os.path.abspath('/baz'), - os.path.abspath(os.path.join(here, '*.py')), - ] - ), + { + os.path.abspath('/base/foo'), + os.path.abspath('/baz'), + os.path.abspath(os.path.join(here, '*.py')), + }, ) def test_config_file_finds_open_url(self): diff --git a/tests/test_util.py b/tests/test_util.py index f79cdeb85..8ed082ee4 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -472,7 +472,7 @@ class Test_object_description(unittest.TestCase): self.assertEqual(self._callFUT(('a', 'b')), "('a', 'b')") def test_set(self): - self.assertEqual(self._callFUT(set(['a'])), "{'a'}") + self.assertEqual(self._callFUT({'a'}), "{'a'}") def test_list(self): self.assertEqual(self._callFUT(['a']), "['a']") -- cgit v1.2.3 From 6ec614df4b8045874a2d93e7dec3f4af594e51e2 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Wed, 6 May 2020 22:58:49 -0700 Subject: Remove object from class --- src/pyramid/i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyramid/i18n.py b/src/pyramid/i18n.py index da8068f35..8c7d01d39 100644 --- a/src/pyramid/i18n.py +++ b/src/pyramid/i18n.py @@ -220,7 +220,7 @@ def get_localizer(request): return request.localizer -class Translations(gettext.GNUTranslations, object): +class Translations(gettext.GNUTranslations): """An extended translation catalog class (ripped off from Babel) """ DEFAULT_DOMAIN = 'messages' -- cgit v1.2.3 From 61fcb53d39b5443007cc7ddbf2305df09276bb40 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Wed, 6 May 2020 22:59:11 -0700 Subject: Remove unnecessary coding lines --- src/pyramid/static.py | 1 - tests/test_i18n.py | 1 - tests/test_integration.py | 1 - tests/test_traversal.py | 1 - 4 files changed, 4 deletions(-) diff --git a/src/pyramid/static.py b/src/pyramid/static.py index 61baa0316..ccd6404da 100644 --- a/src/pyramid/static.py +++ b/src/pyramid/static.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from functools import lru_cache import json import mimetypes diff --git a/tests/test_i18n.py b/tests/test_i18n.py index b5500af37..b8b11830e 100644 --- a/tests/test_i18n.py +++ b/tests/test_i18n.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import os import unittest diff --git a/tests/test_integration.py b/tests/test_integration.py index 9a690a8d3..638ddb2c5 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import datetime import gc import locale diff --git a/tests/test_traversal.py b/tests/test_traversal.py index ec61fa5b8..b99862ba0 100644 --- a/tests/test_traversal.py +++ b/tests/test_traversal.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import unittest from urllib.parse import quote -- cgit v1.2.3 From 26308141eb87300ad49134b977692ebcf50e66c7 Mon Sep 17 00:00:00 2001 From: Bert JW Regeer Date: Wed, 6 May 2020 22:59:30 -0700 Subject: Cleanup string formatting --- src/pyramid/config/actions.py | 4 ++-- src/pyramid/config/routes.py | 2 +- src/pyramid/config/views.py | 4 ++-- src/pyramid/csrf.py | 2 +- src/pyramid/renderers.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pyramid/config/actions.py b/src/pyramid/config/actions.py index 4003a6e3f..b19f35b9b 100644 --- a/src/pyramid/config/actions.py +++ b/src/pyramid/config/actions.py @@ -398,8 +398,8 @@ def resolveConflicts(actions, state=None): # error out if we went backward in order if state.min_order is not None and order < state.min_order: r = [ - 'Actions were added to order={0} after execution had moved ' - 'on to order={1}. Conflicting actions: '.format( + 'Actions were added to order={} after execution had moved ' + 'on to order={}. Conflicting actions: '.format( order, state.min_order ) ] diff --git a/src/pyramid/config/routes.py b/src/pyramid/config/routes.py index 7c78fbfa7..9452a05ab 100644 --- a/src/pyramid/config/routes.py +++ b/src/pyramid/config/routes.py @@ -388,7 +388,7 @@ class RoutesConfiguratorMixin: scheme = parsed.scheme else: scheme = request.scheme - kw['_app_url'] = '{0}://{1}'.format(scheme, parsed.netloc) + kw['_app_url'] = '{}://{}'.format(scheme, parsed.netloc) if original_pregenerator: elements, kw = original_pregenerator(request, elements, kw) diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py index a680eafb3..6faa29d20 100644 --- a/src/pyramid/config/views.py +++ b/src/pyramid/config/views.py @@ -2320,7 +2320,7 @@ class StaticURLInfo: rawspec = None if pkg_name is not None: - pathspec = '{0}:{1}{2}'.format(pkg_name, pkg_subpath, subpath) + pathspec = '{}:{}{}'.format(pkg_name, pkg_subpath, subpath) overrides = registry.queryUtility(IPackageOverrides, name=pkg_name) if overrides is not None: resource_name = posixpath.join(pkg_subpath, subpath) @@ -2328,7 +2328,7 @@ class StaticURLInfo: for source, filtered_path in sources: rawspec = source.get_path(filtered_path) if hasattr(source, 'pkg_name'): - rawspec = '{0}:{1}'.format(source.pkg_name, rawspec) + rawspec = '{}:{}'.format(source.pkg_name, rawspec) break else: diff --git a/src/pyramid/csrf.py b/src/pyramid/csrf.py index 8e711c9a7..4c3689714 100644 --- a/src/pyramid/csrf.py +++ b/src/pyramid/csrf.py @@ -360,6 +360,6 @@ def check_csrf_origin( if not any( is_same_domain(originp.netloc, host) for host in trusted_origins ): - return _fail("{0} does not match any trusted origins.".format(origin)) + return _fail("{} does not match any trusted origins.".format(origin)) return True diff --git a/src/pyramid/renderers.py b/src/pyramid/renderers.py index b17c7d64d..8da6270c3 100644 --- a/src/pyramid/renderers.py +++ b/src/pyramid/renderers.py @@ -387,7 +387,7 @@ class JSONP(JSON): ) ct = 'application/javascript' - body = '/**/{0}({1});'.format(callback, val) + body = '/**/{}({});'.format(callback, val) response = request.response if response.content_type == response.default_content_type: response.content_type = ct -- cgit v1.2.3