From 94fd4cbf24fad0c98f4450bfea58b2e0365e470e Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 15:45:34 +0200 Subject: [PATCH 01/13] - update package configurations from latest meta/config templates --- .github/workflows/pre-commit.yml | 33 +++++++++++++ .github/workflows/tests.yml | 81 ++++---------------------------- .meta.toml | 2 +- .pre-commit-config.yaml | 28 +++++++++++ MANIFEST.in | 1 + tox.ini | 19 ++------ 6 files changed, 76 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..325ae0ea --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,33 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/c-code +name: pre-commit + +on: + pull_request: + push: + branches: + - master + # Allow to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + FORCE_COLOR: 1 + +jobs: + pre-commit: + name: linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() + with: + msg: Apply pre-commit code formatting diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e2572525..7bee49be 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ # Original comment follows. ### ### -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# This workflow will install Python dependencies, run tests with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions ### @@ -81,7 +81,7 @@ jobs: # other people to test/debug), the strategy is to divide the process # into several different jobs. The first builds and saves the binary # wheels. It has dependent jobs that download and install the wheel - # to run tests, build docs, and perform linting. Building the + # to run tests, and build docs. Building the # manylinux wheels is an independent set of jobs. # # This division is time-saving for projects that take awhile to @@ -156,12 +156,12 @@ jobs: if: matrix.python-version == '3.13' run: | pip install -U pip - pip install -U "setuptools<69" wheel twine + pip install -U "setuptools <74" wheel twine - name: Install Build Dependencies if: matrix.python-version != '3.13' run: | pip install -U pip - pip install -U "setuptools<69" wheel twine + pip install -U "setuptools <74" wheel twine - name: Build zope.interface (macOS x86_64) if: > @@ -371,7 +371,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.9"] + python-version: ["3.11"] os: [ubuntu-latest] steps: @@ -435,80 +435,13 @@ jobs: sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest - lint: - needs: build-package - runs-on: ${{ matrix.os }} - strategy: - matrix: - python-version: ["3.9"] - os: [ubuntu-latest] - - steps: - - name: checkout - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - ### - # Caching. - # This actually *restores* a cache and schedules a cleanup action - # to save the cache. So it must come before the thing we want to use - # the cache. - ### - - name: Get pip cache dir (default) - id: pip-cache-default - if: ${{ !startsWith(runner.os, 'Windows') }} - run: | - echo "dir=$(pip cache dir)" >>$GITHUB_OUTPUT - - - name: Get pip cache dir (Windows) - id: pip-cache-windows - if: ${{ startsWith(runner.os, 'Windows') }} - run: | - echo "dir=$(pip cache dir)" >> $Env:GITHUB_OUTPUT - - - name: pip cache (default) - uses: actions/cache@v4 - if: ${{ !startsWith(runner.os, 'Windows') }} - with: - path: ${{ steps.pip-cache-default.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: pip cache (Windows) - uses: actions/cache@v4 - if: ${{ startsWith(runner.os, 'Windows') }} - with: - path: ${{ steps.pip-cache-windows.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Download zope.interface wheel - uses: actions/download-artifact@v4 - with: - name: zope.interface-${{ runner.os }}-${{ matrix.python-version }}.whl - path: dist/ - - name: Install zope.interface - run: | - pip install -U pip - pip install -U wheel - pip install -U `ls dist/zope.interface-*`[test] - - name: Lint - run: | - pip install -U tox - tox -e lint - manylinux: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name # We use a regular Python matrix entry to share as much code as possible. strategy: matrix: - python-version: ["3.9"] + python-version: ["3.11"] image: [manylinux2014_x86_64, manylinux2014_i686, manylinux2014_aarch64] steps: @@ -589,6 +522,8 @@ jobs: name: manylinux_${{ matrix.image }}_wheels.zip - name: Restore pip cache permissions run: sudo chown -R $(whoami) ${{ steps.pip-cache-default.outputs.dir }} + - name: Prevent publishing wheels for unreleased Python versions + run: VER=$(echo '3.13' | tr -d .) && ls -al wheelhouse && sudo rm -f wheelhouse/*-cp${VER}*.whl && ls -al wheelhouse - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 if: > diff --git a/.meta.toml b/.meta.toml index cf22c3a7..d99ebfa6 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,7 +2,7 @@ # https://github.com/zopefoundation/meta/tree/master/config/c-code [meta] template = "c-code" -commit-id = "8d837c89" +commit-id = "acd39fc2" [python] with-pypy = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..b5d6386b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/c-code +minimum_pre_commit_version: '3.6' +repos: + - repo: https://github.com/pycqa/isort + rev: "5.13.2" + hooks: + - id: isort + - repo: https://github.com/hhatto/autopep8 + rev: "v2.3.1" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 + hooks: + - id: pyupgrade + args: [--py38-plus] + - repo: https://github.com/isidentical/teyit + rev: 0.4.3 + hooks: + - id: teyit + - repo: https://github.com/PyCQA/flake8 + rev: "7.1.1" + hooks: + - id: flake8 + additional_dependencies: + - flake8-debugger == 4.1.2 diff --git a/MANIFEST.in b/MANIFEST.in index e5c916bb..6eece7ff 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,7 @@ include *.rst include *.txt include buildout.cfg include tox.ini +include .pre-commit-config.yaml include .coveragerc recursive-include docs *.py diff --git a/tox.ini b/tox.ini index 89118283..9cf1b5c7 100644 --- a/tox.ini +++ b/tox.ini @@ -15,10 +15,9 @@ envlist = coverage [testenv] -usedevelop = true pip_pre = py313: true deps = - setuptools < 69 + setuptools <74 py37: urllib3 < 2 Sphinx setenv = @@ -50,6 +49,7 @@ commands = coverage report -i -m --fail-under=99 depends = py37,py37-pure,py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,pypy,pypy3,docs parallel_show_output = true + [testenv:release-check] description = ensure that the distribution is ready to release basepython = python3 @@ -68,23 +68,14 @@ commands = twine check dist/* [testenv:lint] +description = This env runs all linters configured in .pre-commit-config.yaml basepython = python3 skip_install = true deps = - isort - flake8 -commands = - isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py - flake8 src setup.py - -[testenv:isort-apply] -basepython = python3 -skip_install = true + pre-commit commands_pre = -deps = - isort commands = - isort {toxinidir}/src {toxinidir}/setup.py [] + pre-commit run --all-files --show-diff-on-failure [testenv:docs] basepython = python3 From ae0f403acbedd9d8d4a1e3c83a56a4eb72166721 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 15:47:18 +0200 Subject: [PATCH 02/13] - changes from running isort via pre-commit --- benchmarks/micro.py | 1 + docs/conf.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/benchmarks/micro.py b/benchmarks/micro.py index dce40cee..1653cf8d 100644 --- a/benchmarks/micro.py +++ b/benchmarks/micro.py @@ -6,6 +6,7 @@ from zope.interface.interface import InterfaceClass from zope.interface.registry import Components + # Long, mostly similar names are a worst case for equality # comparisons. ifaces = [ diff --git a/docs/conf.py b/docs/conf.py index e4821412..3b00d8d0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -8,13 +8,15 @@ # Note that not all possible configuration values are present in this # autogenerated file. # -import sys, os +import os +import sys + +import pkg_resources + + # All configuration values have a default; values that are commented out # serve to show the default. -import sys -import os -import pkg_resources sys.path.append(os.path.abspath('../src')) rqmt = pkg_resources.require('zope.interface')[0] # Import and document the pure-python versions of things; they tend to have better From fc79fce8992354a5d8eb6f1cd31f9f5861047827 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 15:59:14 +0200 Subject: [PATCH 03/13] - changes from running autopep8 via pre-commit --- benchmarks/micro.py | 47 ++++++--- docs/conf.py | 123 ++++++++++++------------ setup.py | 1 + src/zope/interface/common/interfaces.py | 72 ++++++++++++++ src/zope/interface/declarations.py | 2 + src/zope/interface/interface.py | 4 +- src/zope/interface/interfaces.py | 1 + 7 files changed, 174 insertions(+), 76 deletions(-) diff --git a/benchmarks/micro.py b/benchmarks/micro.py index 1653cf8d..d069a7ab 100644 --- a/benchmarks/micro.py +++ b/benchmarks/micro.py @@ -14,15 +14,20 @@ for i in range(100) ] + class IWideInheritance(*ifaces): """ Inherits from 100 unrelated interfaces. """ + class WideInheritance(object): pass + + classImplements(WideInheritance, IWideInheritance) + def make_deep_inheritance(): children = [] base = Interface @@ -32,10 +37,14 @@ def make_deep_inheritance(): children.append(child) return children + deep_ifaces = make_deep_inheritance() + class DeepestInheritance(object): pass + + classImplements(DeepestInheritance, deep_ifaces[-1]) @@ -58,6 +67,7 @@ def make_implementer(iface): classImplements(c, iface) return c + implementers = [ make_implementer(iface) for iface in ifaces @@ -70,6 +80,7 @@ def make_implementer(iface): INNER = 100 + def bench_in(loops, o): t0 = pyperf.perf_counter() for _ in range(loops): @@ -78,6 +89,7 @@ def bench_in(loops, o): return pyperf.perf_counter() - t0 + def bench_sort(loops, objs): import random rand = random.Random(8675309) @@ -92,6 +104,7 @@ def bench_sort(loops, objs): return pyperf.perf_counter() - t0 + def bench_query_adapter(loops, components, objs=providers): components_queryAdapter = components.queryAdapter # One time through to prime the caches @@ -111,16 +124,16 @@ def bench_getattr(loops, name, get=getattr): t0 = pyperf.perf_counter() for _ in range(loops): for _ in range(INNER): - get(Interface, name) # 1 - get(Interface, name) # 2 - get(Interface, name) # 3 - get(Interface, name) # 4 - get(Interface, name) # 5 - get(Interface, name) # 6 - get(Interface, name) # 7 - get(Interface, name) # 8 - get(Interface, name) # 9 - get(Interface, name) # 10 + get(Interface, name) # 1 + get(Interface, name) # 2 + get(Interface, name) # 3 + get(Interface, name) # 4 + get(Interface, name) # 5 + get(Interface, name) # 6 + get(Interface, name) # 7 + get(Interface, name) # 8 + get(Interface, name) # 9 + get(Interface, name) # 10 return pyperf.perf_counter() - t0 @@ -168,6 +181,7 @@ def bench_iface_call_w_conform_return_non_none_not_provided(loops): iface(inst) return pyperf.perf_counter() - t0 + def _bench_iface_call_simple(loops, inst): t0 = pyperf.perf_counter() for _ in range(loops): @@ -224,28 +238,28 @@ def bench_iface_call_no_conform_provided_deep(loops): ) runner.bench_time_func( - 'read __module__', # stored in C, accessed through __getattribute__ + 'read __module__', # stored in C, accessed through __getattribute__ bench_getattr, '__module__', inner_loops=INNER * 10 ) runner.bench_time_func( - 'read __name__', # stored in C, accessed through PyMemberDef + 'read __name__', # stored in C, accessed through PyMemberDef bench_getattr, '__name__', inner_loops=INNER * 10 ) runner.bench_time_func( - 'read __doc__', # stored in Python instance dictionary directly + 'read __doc__', # stored in Python instance dictionary directly bench_getattr, '__doc__', inner_loops=INNER * 10 ) runner.bench_time_func( - 'read providedBy', # from the class, wrapped into a method object. + 'read providedBy', # from the class, wrapped into a method object. bench_getattr, 'providedBy', inner_loops=INNER * 10 @@ -258,6 +272,7 @@ def bench_iface_call_no_conform_provided_deep(loops): inner_loops=1 ) + def populate_components(): def factory(o): return 42 @@ -265,10 +280,12 @@ def factory(o): pop_components = Components() for iface in ifaces: for other_iface in ifaces: - pop_components.registerAdapter(factory, (iface,), other_iface, event=False) + pop_components.registerAdapter( + factory, (iface,), other_iface, event=False) return pop_components + runner.bench_time_func( 'query adapter (all trivial registrations)', bench_query_adapter, diff --git a/docs/conf.py b/docs/conf.py index 3b00d8d0..9ca509bc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -3,7 +3,7 @@ # zope.interface documentation build configuration file, created by # sphinx-quickstart on Mon Mar 26 16:31:31 2012. # -# This file is execfile()d with the current directory set to its containing dir. +# This file is execfile()d with the current directory set to its containing dir # # Note that not all possible configuration values are present in this # autogenerated file. @@ -19,20 +19,20 @@ sys.path.append(os.path.abspath('../src')) rqmt = pkg_resources.require('zope.interface')[0] -# Import and document the pure-python versions of things; they tend to have better +# Import and document pure-python versions of things; they tend to have better # docstrings and signatures. os.environ['PURE_PYTHON'] = '1' # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) -# -- General configuration ----------------------------------------------------- +# -- General configuration ----------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' -# Add any Sphinx extension module names here, as strings. They can be extensions +# Add any Sphinx extension module names here as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', @@ -51,7 +51,7 @@ source_suffix = '.rst' # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' @@ -71,40 +71,41 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] -# The reST default role (used for this markup: `text`) to use for all documents. +# The reST default role (used for this markup: `text`) to use for all +# documents. default_role = 'obj' # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] -# -- Options for HTML output --------------------------------------------------- +# -- Options for HTML output --------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. @@ -113,26 +114,26 @@ # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, @@ -141,60 +142,60 @@ # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a <link> tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'zopeinterfacedoc' -# -- Options for LaTeX output -------------------------------------------------- +# -- Options for LaTeX output -------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', } # pdflatex can't handle Cyrillic out of the box, but xetext/lualatex should be @@ -202,34 +203,34 @@ latex_engine = 'lualatex' # Grouping the document tree into LaTeX files. List of tuples -# (source start file, target name, title, author, documentclass [howto/manual]). +# (source start file, target name, title, author, documentclass [howto/manual]) latex_documents = [ - ('index', 'zopeinterface.tex', 'zope.interface Documentation', - 'Zope Foundation contributors', 'manual'), + ('index', 'zopeinterface.tex', 'zope.interface Documentation', + 'Zope Foundation contributors', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True -# -- Options for manual page output -------------------------------------------- +# -- Options for manual page output -------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). @@ -239,28 +240,32 @@ ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False -# -- Options for Texinfo output ------------------------------------------------ +# -- Options for Texinfo output ------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'zopeinterface', 'zope.interface Documentation', - 'Zope Foundation contributors', 'zopeinterface', 'One line description of project.', - 'Miscellaneous'), + ('index', + 'zopeinterface', + 'zope.interface Documentation', + 'Zope Foundation contributors', + 'zopeinterface', + 'One line description of project.', + 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # Example configuration for intersphinx: refer to the Python standard library. diff --git a/setup.py b/setup.py index f3227222..e282b642 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ class optional_build_ext(build_ext): """This class subclasses build_ext and allows the building of C extensions to fail. """ + def run(self): try: build_ext.run(self) diff --git a/src/zope/interface/common/interfaces.py b/src/zope/interface/common/interfaces.py index 74386de0..90757958 100644 --- a/src/zope/interface/common/interfaces.py +++ b/src/zope/interface/common/interfaces.py @@ -19,6 +19,8 @@ class IException(Interface): "Interface for `Exception`" + + classImplements(Exception, IException) # noqa E305 @@ -28,116 +30,162 @@ class IStandardError(IException): class IWarning(IException): "Interface for `Warning`" + + classImplements(Warning, IWarning) # noqa E305 class ISyntaxError(IStandardError): "Interface for `SyntaxError`" + + classImplements(SyntaxError, ISyntaxError) # noqa E305 class ILookupError(IStandardError): "Interface for `LookupError`" + + classImplements(LookupError, ILookupError) # noqa E305 class IValueError(IStandardError): "Interface for `ValueError`" + + classImplements(ValueError, IValueError) # noqa E305 class IRuntimeError(IStandardError): "Interface for `RuntimeError`" + + classImplements(RuntimeError, IRuntimeError) # noqa E305 class IArithmeticError(IStandardError): "Interface for `ArithmeticError`" + + classImplements(ArithmeticError, IArithmeticError) # noqa E305 class IAssertionError(IStandardError): "Interface for `AssertionError`" + + classImplements(AssertionError, IAssertionError) # noqa E305 class IAttributeError(IStandardError): "Interface for `AttributeError`" + + classImplements(AttributeError, IAttributeError) # noqa E305 class IDeprecationWarning(IWarning): "Interface for `DeprecationWarning`" + + classImplements(DeprecationWarning, IDeprecationWarning) # noqa E305 class IEOFError(IStandardError): "Interface for `EOFError`" + + classImplements(EOFError, IEOFError) # noqa E305 class IEnvironmentError(IStandardError): "Interface for `EnvironmentError`" + + classImplements(EnvironmentError, IEnvironmentError) # noqa E305 class IFloatingPointError(IArithmeticError): "Interface for `FloatingPointError`" + + classImplements(FloatingPointError, IFloatingPointError) # noqa E305 class IIOError(IEnvironmentError): "Interface for `IOError`" + + classImplements(IOError, IIOError) # noqa E305 class IImportError(IStandardError): "Interface for `ImportError`" + + classImplements(ImportError, IImportError) # noqa E305 class IIndentationError(ISyntaxError): "Interface for `IndentationError`" + + classImplements(IndentationError, IIndentationError) # noqa E305 class IIndexError(ILookupError): "Interface for `IndexError`" + + classImplements(IndexError, IIndexError) # noqa E305 class IKeyError(ILookupError): "Interface for `KeyError`" + + classImplements(KeyError, IKeyError) # noqa E305 class IKeyboardInterrupt(IStandardError): "Interface for `KeyboardInterrupt`" + + classImplements(KeyboardInterrupt, IKeyboardInterrupt) # noqa E305 class IMemoryError(IStandardError): "Interface for `MemoryError`" + + classImplements(MemoryError, IMemoryError) # noqa E305 class INameError(IStandardError): "Interface for `NameError`" + + classImplements(NameError, INameError) # noqa E305 class INotImplementedError(IRuntimeError): "Interface for `NotImplementedError`" + + classImplements(NotImplementedError, INotImplementedError) # noqa E305 class IOSError(IEnvironmentError): "Interface for `OSError`" + + classImplements(OSError, IOSError) # noqa E305 class IOverflowError(IArithmeticError): "Interface for `ArithmeticError`" + + classImplements(OverflowError, IOverflowError) # noqa E305 @@ -151,59 +199,83 @@ class IOverflowWarning(IWarning): class IReferenceError(IStandardError): "Interface for `ReferenceError`" + + classImplements(ReferenceError, IReferenceError) # noqa E305 class IRuntimeWarning(IWarning): "Interface for `RuntimeWarning`" + + classImplements(RuntimeWarning, IRuntimeWarning) # noqa E305 class IStopIteration(IException): "Interface for `StopIteration`" + + classImplements(StopIteration, IStopIteration) # noqa E305 class ISyntaxWarning(IWarning): "Interface for `SyntaxWarning`" + + classImplements(SyntaxWarning, ISyntaxWarning) # noqa E305 class ISystemError(IStandardError): "Interface for `SystemError`" + + classImplements(SystemError, ISystemError) # noqa E305 class ISystemExit(IException): "Interface for `SystemExit`" + + classImplements(SystemExit, ISystemExit) # noqa E305 class ITabError(IIndentationError): "Interface for `TabError`" + + classImplements(TabError, ITabError) # noqa E305 class ITypeError(IStandardError): "Interface for `TypeError`" + + classImplements(TypeError, ITypeError) # noqa E305 class IUnboundLocalError(INameError): "Interface for `UnboundLocalError`" + + classImplements(UnboundLocalError, IUnboundLocalError) # noqa E305 class IUnicodeError(IValueError): "Interface for `UnicodeError`" + + classImplements(UnicodeError, IUnicodeError) # noqa E305 class IUserWarning(IWarning): "Interface for `UserWarning`" + + classImplements(UserWarning, IUserWarning) # noqa E305 class IZeroDivisionError(IArithmeticError): "Interface for `ZeroDivisionError`" + + classImplements(ZeroDivisionError, IZeroDivisionError) # noqa E305 diff --git a/src/zope/interface/declarations.py b/src/zope/interface/declarations.py index a9b983da..825c5789 100644 --- a/src/zope/interface/declarations.py +++ b/src/zope/interface/declarations.py @@ -953,6 +953,7 @@ def __reduce__(self): __get__ = ClassProvidesBase.__get__ +# autopep8: off (it breaks the statements in the "if") def directlyProvidedBy(object): # pylint:disable=redefined-builtin """Return the interfaces directly provided by the given object @@ -970,6 +971,7 @@ def directlyProvidedBy(object): # pylint:disable=redefined-builtin # Strip off the class part of the spec: return Declaration(provides.__bases__[:-1]) +# autopep8: on class provider: diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py index 575b6381..e5dddb88 100644 --- a/src/zope/interface/interface.py +++ b/src/zope/interface/interface.py @@ -825,8 +825,8 @@ def update_value(aname, aval): # __firstlineno__: Python 3.13b1+ # https://github.com/python/cpython/pull/118475 '__firstlineno__', - ) - and aval is not _decorator_non_return # noqa W503 + ) and + aval is not _decorator_non_return # noqa W503 } def interfaces(self): diff --git a/src/zope/interface/interfaces.py b/src/zope/interface/interfaces.py index 454fee89..9bafeb58 100644 --- a/src/zope/interface/interfaces.py +++ b/src/zope/interface/interfaces.py @@ -1156,6 +1156,7 @@ class IRegistrationEvent(IObjectEvent): class RegistrationEvent(ObjectEvent): """There has been a change in a registration """ + def __repr__(self): return f"{self.__class__.__name__} event:\n{self.object!r}" From bdac8102c2d80512d2cdf6311d0001c97aa11da2 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 16:01:01 +0200 Subject: [PATCH 04/13] - changes from running pyupgrade via pre-commit --- benchmarks/micro.py | 10 +++++----- docs/conf.py | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/benchmarks/micro.py b/benchmarks/micro.py index d069a7ab..5aed1b50 100644 --- a/benchmarks/micro.py +++ b/benchmarks/micro.py @@ -21,7 +21,7 @@ class IWideInheritance(*ifaces): """ -class WideInheritance(object): +class WideInheritance: pass @@ -41,23 +41,23 @@ def make_deep_inheritance(): deep_ifaces = make_deep_inheritance() -class DeepestInheritance(object): +class DeepestInheritance: pass classImplements(DeepestInheritance, deep_ifaces[-1]) -class ImplementsNothing(object): +class ImplementsNothing: pass -class HasConformReturnNone(object): +class HasConformReturnNone: def __conform__(self, iface): return None -class HasConformReturnObject(object): +class HasConformReturnObject: def __conform__(self, iface): return self diff --git a/docs/conf.py b/docs/conf.py index 9ca509bc..b2b659d7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # zope.interface documentation build configuration file, created by # sphinx-quickstart on Mon Mar 26 16:31:31 2012. From aa99873a1089732eaddf374a6a572457e04d0771 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 16:10:05 +0200 Subject: [PATCH 05/13] - changes made by teyit through pre-commit --- .../interface/common/tests/basemapping.py | 2 +- src/zope/interface/tests/test_advice.py | 12 +- src/zope/interface/tests/test_declarations.py | 72 +-- src/zope/interface/tests/test_interface.py | 182 +++--- src/zope/interface/tests/test_interfaces.py | 2 +- .../interface/tests/test_odd_declarations.py | 32 +- src/zope/interface/tests/test_registry.py | 572 +++++++++--------- 7 files changed, 444 insertions(+), 430 deletions(-) diff --git a/src/zope/interface/common/tests/basemapping.py b/src/zope/interface/common/tests/basemapping.py index f60ec7cc..f58e32a6 100644 --- a/src/zope/interface/common/tests/basemapping.py +++ b/src/zope/interface/common/tests/basemapping.py @@ -20,7 +20,7 @@ def testIReadMapping(self, inst, state, absent): for key in state: self.assertEqual(inst[key], state[key]) self.assertEqual(inst.get(key, None), state[key]) - self.assertTrue(key in inst) + self.assertIn(key, inst) for key in absent: self.assertEqual(inst.get(key, None), None) diff --git a/src/zope/interface/tests/test_advice.py b/src/zope/interface/tests/test_advice.py index 4d484e04..9612b6f7 100644 --- a/src/zope/interface/tests/test_advice.py +++ b/src/zope/interface/tests/test_advice.py @@ -37,7 +37,7 @@ def test_w_module(self): f_locals, f_globals) = advisory_testing.moduleLevelFrameInfo self.assertEqual(kind, "module") for d in module.__dict__, f_locals, f_globals: - self.assertTrue(d is advisory_testing.my_globals) + self.assertIs(d, advisory_testing.my_globals) def test_w_class(self): from zope.interface.tests import advisory_testing @@ -48,7 +48,7 @@ def test_w_class(self): self.assertEqual(kind, "class") for d in module.__dict__, f_globals: - self.assertTrue(d is advisory_testing.my_globals) + self.assertIs(d, advisory_testing.my_globals) def test_inside_function_call(self): from zope.interface.advice import getFrameInfo @@ -60,7 +60,7 @@ def test_inside_function_call(self): self.assertEqual(f_locals, locals()) for d in module.__dict__, f_globals: - self.assertTrue(d is globals()) + self.assertIs(d, globals()) def test_inside_exec(self): from zope.interface.advice import getFrameInfo @@ -68,9 +68,9 @@ def test_inside_exec(self): _locals = {} exec(_FUNKY_EXEC, _globals, _locals) self.assertEqual(_locals['kind'], "exec") - self.assertTrue(_locals['f_locals'] is _locals) - self.assertTrue(_locals['module'] is None) - self.assertTrue(_locals['f_globals'] is _globals) + self.assertIs(_locals['f_locals'], _locals) + self.assertIsNone(_locals['module']) + self.assertIs(_locals['f_globals'], _globals) _FUNKY_EXEC = """\ diff --git a/src/zope/interface/tests/test_declarations.py b/src/zope/interface/tests/test_declarations.py index 3adbc024..f6bdfde4 100644 --- a/src/zope/interface/tests/test_declarations.py +++ b/src/zope/interface/tests/test_declarations.py @@ -457,15 +457,16 @@ class B: self.assertEqual(implementedBy(A), implementedBy(A)) self.assertEqual(hash(implementedBy(A)), hash(implementedBy(A))) - self.assertTrue(implementedBy(A) < None) - self.assertTrue( - None > implementedBy(A) - ) # pylint:disable=misplaced-comparison-constant - self.assertTrue(implementedBy(A) < implementedBy(B)) - self.assertTrue(implementedBy(A) > IFoo) - self.assertTrue(implementedBy(A) <= implementedBy(B)) - self.assertTrue(implementedBy(A) >= IFoo) - self.assertTrue(implementedBy(A) != IFoo) + self.assertLess(implementedBy(A), None) + self.assertGreater( + None, + implementedBy(A) + ) + self.assertLess(implementedBy(A), implementedBy(B)) + self.assertGreater(implementedBy(A), IFoo) + self.assertLessEqual(implementedBy(A), implementedBy(B)) + self.assertGreaterEqual(implementedBy(A), IFoo) + self.assertNotEqual(implementedBy(A), IFoo) def test_proxy_equality(self): # https://github.com/zopefoundation/zope.interface/issues/55 @@ -496,19 +497,20 @@ class B: # The order of arguments to the operators matters, # test both - self.assertTrue( - implementedByA == implementedByA - ) # pylint:disable=comparison-with-itself - self.assertTrue(implementedByA != implementedByB) - self.assertTrue(implementedByB != implementedByA) + self.assertEqual( + implementedByA, + implementedByA + ) + self.assertNotEqual(implementedByA, implementedByB) + self.assertNotEqual(implementedByB, implementedByA) - self.assertTrue(proxy == implementedByA) - self.assertTrue(implementedByA == proxy) - self.assertFalse(proxy != implementedByA) - self.assertFalse(implementedByA != proxy) + self.assertEqual(proxy, implementedByA) + self.assertEqual(implementedByA, proxy) + self.assertEqual(proxy, implementedByA) + self.assertEqual(implementedByA, proxy) - self.assertTrue(proxy != implementedByB) - self.assertTrue(implementedByB != proxy) + self.assertNotEqual(proxy, implementedByB) + self.assertNotEqual(implementedByB, proxy) def test_changed_deletes_super_cache(self): impl = self._makeOne() @@ -581,7 +583,7 @@ class Foo: with _MonkeyDict(declarations, 'BuiltinImplementationSpecifications') as specs: specs[foo] = reg - self.assertTrue(self._callFUT(foo) is reg) + self.assertIs(self._callFUT(foo), reg) def test_dictless_w_existing_Implements(self): from zope.interface.declarations import Implements @@ -592,7 +594,7 @@ class Foo: foo = Foo() foo.__implemented__ = impl - self.assertTrue(self._callFUT(foo) is impl) + self.assertIs(self._callFUT(foo), impl) def test_dictless_w_existing_not_Implements(self): from zope.interface.interface import InterfaceClass @@ -612,7 +614,7 @@ def test_w_existing_attr_as_Implements(self): class Foo: __implemented__ = impl - self.assertTrue(self._callFUT(Foo) is impl) + self.assertIs(self._callFUT(Foo), impl) def test_builtins_added_to_cache(self): from zope.interface import declarations @@ -637,9 +639,9 @@ def test_builtins_w_existing_cache(self): specs[tuple] = t_spec specs[list] = l_spec specs[dict] = d_spec - self.assertTrue(self._callFUT(tuple) is t_spec) - self.assertTrue(self._callFUT(list) is l_spec) - self.assertTrue(self._callFUT(dict) is d_spec) + self.assertIs(self._callFUT(tuple), t_spec) + self.assertIs(self._callFUT(list), l_spec) + self.assertIs(self._callFUT(dict), d_spec) def test_oldstyle_class_no_assertions(self): # TODO: Figure out P3 story @@ -714,7 +716,7 @@ def test_w_existing_Implements(self): class Foo: __implemented__ = impl - self.assertTrue(self._callFUT(Foo) is impl) + self.assertIs(self._callFUT(Foo), impl) def test_super_when_base_implements_interface(self): from zope.interface import Interface @@ -963,7 +965,7 @@ class Foo: impl.inherit = Foo self._callFUT(Foo, IBar) # Same spec, now different values - self.assertTrue(Foo.__implemented__ is impl) + self.assertIs(Foo.__implemented__, impl) self.assertEqual(impl.inherit, None) self.assertEqual(impl.declared, (IBar,)) @@ -1172,7 +1174,7 @@ class Foo: foo = Foo() decorator = self._makeOne(IFoo) returned = decorator(foo) - self.assertTrue(returned is foo) + self.assertIs(returned, foo) spec = foo.__implemented__ # pylint:disable=no-member self.assertEqual( spec.__name__, 'zope.interface.tests.test_declarations.?' @@ -1564,7 +1566,7 @@ class Foo: with _Monkey(declarations, InstanceDeclarations=cache): spec = self._callFUT(Foo, IFoo) self.assertEqual(list(spec), [IFoo]) - self.assertTrue(cache[(Foo, IFoo)] is spec) + self.assertIs(cache[(Foo, IFoo)], spec) def test_w_cached_spec(self): from zope.interface import declarations @@ -1578,7 +1580,7 @@ class Foo: cache = {(Foo, IFoo): prior} with _Monkey(declarations, InstanceDeclarations=cache): spec = self._callFUT(Foo, IFoo) - self.assertTrue(spec is prior) + self.assertIs(spec, prior) class Test_directlyProvides(unittest.TestCase): @@ -1775,7 +1777,7 @@ class Foo: pass cpbp = Foo.__provides__ = self._makeOne(Foo, IFoo) - self.assertTrue(Foo.__provides__ is cpbp) + self.assertIs(Foo.__provides__, cpbp) def test_w_same_class_via_instance(self): from zope.interface.interface import InterfaceClass @@ -1841,7 +1843,7 @@ class Foo: pass cp = Foo.__provides__ = self._makeOne(Foo, type(Foo), IBar) - self.assertTrue(Foo.__provides__ is cp) + self.assertIs(Foo.__provides__, cp) self.assertEqual(list(Foo().__provides__), [IFoo]) def test___reduce__(self): @@ -2323,7 +2325,7 @@ class Foo: foo.__providedBy__ = object() expected = foo.__provides__ = object() spec = self._callFUT(foo) - self.assertTrue(spec is expected) + self.assertIs(spec, expected) def test_w_providedBy_invalid_spec_w_provides_diff_provides_on_class(self): @@ -2335,7 +2337,7 @@ class Foo: expected = foo.__provides__ = object() Foo.__provides__ = object() spec = self._callFUT(foo) - self.assertTrue(spec is expected) + self.assertIs(spec, expected) def test_w_providedBy_invalid_spec_w_provides_same_provides_on_class(self): from zope.interface.declarations import implementer diff --git a/src/zope/interface/tests/test_interface.py b/src/zope/interface/tests/test_interface.py index 9b868b7f..60f7cea5 100644 --- a/src/zope/interface/tests/test_interface.py +++ b/src/zope/interface/tests/test_interface.py @@ -505,8 +505,8 @@ def test_ctor(self): spec = self._makeOne() self.assertEqual(spec.__bases__, ()) self.assertEqual(len(spec._implied), 2) - self.assertTrue(spec in spec._implied) - self.assertTrue(Interface in spec._implied) + self.assertIn(spec, spec._implied) + self.assertIn(Interface, spec._implied) self.assertEqual(len(spec.dependents), 0) def test_subscribe_first_time(self): @@ -536,7 +536,7 @@ def test_unsubscribe(self): spec.unsubscribe(dep) self.assertEqual(spec.dependents[dep], 1) spec.unsubscribe(dep) - self.assertFalse(dep in spec.dependents) + self.assertNotIn(dep, spec.dependents) def test___setBases_subscribes_bases_and_notifies_dependents(self): from zope.interface.interface import Interface @@ -568,7 +568,7 @@ class IFoo(Interface): spec._implied[IFoo] = () spec.changed(spec) self.assertIsNone(spec._v_attrs) - self.assertFalse(IFoo in spec._implied) + self.assertNotIn(IFoo, spec._implied) def test_interfaces_skips_already_seen(self): from zope.interface.interface import Interface @@ -600,7 +600,7 @@ def test_get_hit_w__v_attrs(self): spec = self._makeOne() foo = object() spec._v_attrs = {'foo': foo} - self.assertTrue(spec.get('foo') is foo) + self.assertIs(spec.get('foo'), foo) def test_get_hit_from_base_wo__v_attrs(self): from zope.interface.interface import Attribute @@ -613,8 +613,8 @@ class IBar(Interface): bar = Attribute('bar') spec = self._makeOne([IFoo, IBar]) - self.assertTrue(spec.get('foo') is IFoo.get('foo')) - self.assertTrue(spec.get('bar') is IBar.get('bar')) + self.assertIs(spec.get('foo'), IFoo.get('foo')) + self.assertIs(spec.get('bar'), IBar.get('bar')) def test_multiple_inheritance_no_interfaces(self): # If we extend an object that implements interfaces, @@ -998,7 +998,7 @@ def _bar(): def test___contains___miss(self): one = self._makeOne() - self.assertFalse('nonesuch' in one) + self.assertNotIn('nonesuch', one) def test___contains___hit(self): from zope.interface.interface import Attribute @@ -1012,8 +1012,8 @@ def _bar(): 'bar': fromFunction(_bar), } one = self._makeOne(attrs=ATTRS) - self.assertTrue('foo' in one) - self.assertTrue('bar' in one) + self.assertIn('foo', one) + self.assertIn('bar', one) def test_direct_miss(self): one = self._makeOne() @@ -1102,7 +1102,7 @@ def _fail(*args, **kw): self.assertRaises(Invalid, iface.validateInvariants, obj, _errors) self.assertEqual(_fail_called_with, [((obj,), {})]) self.assertEqual(len(_errors), 1) - self.assertTrue(isinstance(_errors[0], Invalid)) + self.assertIsInstance(_errors[0], Invalid) def test_validateInvariants_fail_in_base_wo_errors_passed(self): from zope.interface.exceptions import Invalid @@ -1151,7 +1151,7 @@ def _fail(*args, **kw): self.assertEqual(_passable_called_with, [((obj,), {})]) self.assertEqual(_fail_called_with, [((obj,), {})]) self.assertEqual(len(_errors), 1) - self.assertTrue(isinstance(_errors[0], Invalid)) + self.assertIsInstance(_errors[0], Invalid) def test_validateInvariants_inherited_not_called_multiple_times(self): _passable_called_with = [] @@ -1191,29 +1191,29 @@ def __init__(self): # pylint:disable=super-init-not-called def test_comparison_with_None(self): # pylint:disable=singleton-comparison,misplaced-comparison-constant iface = self._makeOne() - self.assertTrue(iface < None) # noqa E711 - self.assertTrue(iface <= None) # noqa E711 - self.assertFalse(iface == None) # noqa E711 - self.assertTrue(iface != None) # noqa E711 + self.assertLess(iface, None) # noqa E711 + self.assertLessEqual(iface, None) # noqa E711 + self.assertNotEqual(iface, None) # noqa E711 + self.assertNotEqual(iface, None) # noqa E711 self.assertFalse(iface >= None) # noqa E711 self.assertFalse(iface > None) # noqa E711 self.assertFalse(None < iface) # noqa E711 self.assertFalse(None <= iface) # noqa E711 - self.assertFalse(None == iface) # noqa E711 - self.assertTrue(None != iface) # noqa E711 - self.assertTrue(None >= iface) # noqa E711 - self.assertTrue(None > iface) # noqa E711 + self.assertNotEqual(None, iface) # noqa E711 + self.assertNotEqual(None, iface) # noqa E711 + self.assertGreaterEqual(None, iface) # noqa E711 + self.assertGreater(None, iface) # noqa E711 def test_comparison_with_same_instance(self): # pylint:disable=comparison-with-itself iface = self._makeOne() self.assertFalse(iface < iface) - self.assertTrue(iface <= iface) - self.assertTrue(iface == iface) - self.assertFalse(iface != iface) - self.assertTrue(iface >= iface) + self.assertLessEqual(iface, iface) + self.assertEqual(iface, iface) + self.assertEqual(iface, iface) + self.assertGreaterEqual(iface, iface) self.assertFalse(iface > iface) def test_comparison_with_same_named_instance_in_other_module(self): @@ -1221,18 +1221,18 @@ def test_comparison_with_same_named_instance_in_other_module(self): one = self._makeOne('IName', __module__='zope.interface.tests.one') other = self._makeOne('IName', __module__='zope.interface.tests.other') - self.assertTrue(one < other) + self.assertLess(one, other) self.assertFalse(other < one) - self.assertTrue(one <= other) + self.assertLessEqual(one, other) self.assertFalse(other <= one) - self.assertFalse(one == other) - self.assertFalse(other == one) - self.assertTrue(one != other) - self.assertTrue(other != one) + self.assertNotEqual(one, other) + self.assertNotEqual(other, one) + self.assertNotEqual(one, other) + self.assertNotEqual(other, one) self.assertFalse(one >= other) - self.assertTrue(other >= one) + self.assertGreaterEqual(other, one) self.assertFalse(one > other) - self.assertTrue(other > one) + self.assertGreater(other, one) def test_assignment_to__class__(self): # https://github.com/zopefoundation/zope.interface/issues/6 @@ -1299,7 +1299,7 @@ def test_attributes_link_to_interface(self): class I1(Interface): attr = Attribute("My attr") - self.assertTrue(I1['attr'].interface is I1) + self.assertIs(I1['attr'].interface, I1) def test_methods_link_to_interface(self): from zope.interface import Interface @@ -1308,7 +1308,7 @@ class I1(Interface): def method(foo, bar, bingo): "A method" - self.assertTrue(I1['method'].interface is I1) + self.assertIs(I1['method'].interface, I1) def test_classImplements_simple(self): from zope.interface import Interface @@ -1339,10 +1339,10 @@ def method2(self, a, b): self.assertTrue(ICurrent.implementedBy(Current)) self.assertFalse(IOther.implementedBy(Current)) self.assertEqual(ICurrent, ICurrent) - self.assertTrue(ICurrent in implementedBy(Current)) - self.assertFalse(IOther in implementedBy(Current)) - self.assertTrue(ICurrent in providedBy(current)) - self.assertFalse(IOther in providedBy(current)) + self.assertIn(ICurrent, implementedBy(Current)) + self.assertNotIn(IOther, implementedBy(Current)) + self.assertIn(ICurrent, providedBy(current)) + self.assertNotIn(IOther, providedBy(current)) def test_classImplements_base_not_derived(self): from zope.interface import Interface @@ -1366,10 +1366,10 @@ def method(self): self.assertTrue(IBase.implementedBy(Current)) self.assertFalse(IDerived.implementedBy(Current)) - self.assertTrue(IBase in implementedBy(Current)) - self.assertFalse(IDerived in implementedBy(Current)) - self.assertTrue(IBase in providedBy(current)) - self.assertFalse(IDerived in providedBy(current)) + self.assertIn(IBase, implementedBy(Current)) + self.assertNotIn(IDerived, implementedBy(Current)) + self.assertIn(IBase, providedBy(current)) + self.assertNotIn(IDerived, providedBy(current)) def test_classImplements_base_and_derived(self): from zope.interface import Interface @@ -1393,12 +1393,12 @@ def method(self): self.assertTrue(IBase.implementedBy(Current)) self.assertTrue(IDerived.implementedBy(Current)) - self.assertFalse(IBase in implementedBy(Current)) - self.assertTrue(IBase in implementedBy(Current).flattened()) - self.assertTrue(IDerived in implementedBy(Current)) - self.assertFalse(IBase in providedBy(current)) - self.assertTrue(IBase in providedBy(current).flattened()) - self.assertTrue(IDerived in providedBy(current)) + self.assertNotIn(IBase, implementedBy(Current)) + self.assertIn(IBase, implementedBy(Current).flattened()) + self.assertIn(IDerived, implementedBy(Current)) + self.assertNotIn(IBase, providedBy(current)) + self.assertIn(IBase, providedBy(current).flattened()) + self.assertIn(IDerived, providedBy(current)) def test_classImplements_multiple(self): from zope.interface import Interface @@ -1428,10 +1428,10 @@ class Ambi(Left, Right): self.assertTrue(ILeft.implementedBy(Ambi)) self.assertTrue(IRight.implementedBy(Ambi)) - self.assertTrue(ILeft in implementedBy(Ambi)) - self.assertTrue(IRight in implementedBy(Ambi)) - self.assertTrue(ILeft in providedBy(ambi)) - self.assertTrue(IRight in providedBy(ambi)) + self.assertIn(ILeft, implementedBy(Ambi)) + self.assertIn(IRight, implementedBy(Ambi)) + self.assertIn(ILeft, providedBy(ambi)) + self.assertIn(IRight, providedBy(ambi)) def test_classImplements_multiple_w_explict_implements(self): from zope.interface import Interface @@ -1469,12 +1469,12 @@ class Mixed(Left, Right): self.assertTrue(ILeft.implementedBy(Mixed)) self.assertFalse(IRight.implementedBy(Mixed)) self.assertTrue(IOther.implementedBy(Mixed)) - self.assertTrue(ILeft in implementedBy(Mixed)) - self.assertFalse(IRight in implementedBy(Mixed)) - self.assertTrue(IOther in implementedBy(Mixed)) - self.assertTrue(ILeft in providedBy(mixed)) - self.assertFalse(IRight in providedBy(mixed)) - self.assertTrue(IOther in providedBy(mixed)) + self.assertIn(ILeft, implementedBy(Mixed)) + self.assertNotIn(IRight, implementedBy(Mixed)) + self.assertIn(IOther, implementedBy(Mixed)) + self.assertIn(ILeft, providedBy(mixed)) + self.assertNotIn(IRight, providedBy(mixed)) + self.assertIn(IOther, providedBy(mixed)) def testInterfaceExtendsInterface(self): from zope.interface import Interface @@ -1594,11 +1594,11 @@ def method(): self.assertEqual(len(name_values), 2) self.assertEqual(name_values[0][0], 'attr') - self.assertTrue(isinstance(name_values[0][1], Attribute)) + self.assertIsInstance(name_values[0][1], Attribute) self.assertEqual(name_values[0][1].__name__, 'attr') self.assertEqual(name_values[0][1].__doc__, 'My attr') self.assertEqual(name_values[1][0], 'method') - self.assertTrue(isinstance(name_values[1][1], Method)) + self.assertIsInstance(name_values[1][1], Method) self.assertEqual(name_values[1][1].__name__, 'method') self.assertEqual(name_values[1][1].__doc__, 'My method') @@ -1626,15 +1626,15 @@ def method2(): self.assertEqual(len(name_values), 3) self.assertEqual(name_values[0][0], 'attr2') - self.assertTrue(isinstance(name_values[0][1], Attribute)) + self.assertIsInstance(name_values[0][1], Attribute) self.assertEqual(name_values[0][1].__name__, 'attr2') self.assertEqual(name_values[0][1].__doc__, 'My attr2') self.assertEqual(name_values[1][0], 'method') - self.assertTrue(isinstance(name_values[1][1], Method)) + self.assertIsInstance(name_values[1][1], Method) self.assertEqual(name_values[1][1].__name__, 'method') self.assertEqual(name_values[1][1].__doc__, 'My method, overridden') self.assertEqual(name_values[2][0], 'method2') - self.assertTrue(isinstance(name_values[2][1], Method)) + self.assertIsInstance(name_values[2][1], Method) self.assertEqual(name_values[2][1].__name__, 'method2') self.assertEqual(name_values[2][1].__doc__, 'My method2') @@ -1642,19 +1642,19 @@ def method2(): self.assertEqual(len(name_values), 4) self.assertEqual(name_values[0][0], 'attr') - self.assertTrue(isinstance(name_values[0][1], Attribute)) + self.assertIsInstance(name_values[0][1], Attribute) self.assertEqual(name_values[0][1].__name__, 'attr') self.assertEqual(name_values[0][1].__doc__, 'My attr') self.assertEqual(name_values[1][0], 'attr2') - self.assertTrue(isinstance(name_values[1][1], Attribute)) + self.assertIsInstance(name_values[1][1], Attribute) self.assertEqual(name_values[1][1].__name__, 'attr2') self.assertEqual(name_values[1][1].__doc__, 'My attr2') self.assertEqual(name_values[2][0], 'method') - self.assertTrue(isinstance(name_values[2][1], Method)) + self.assertIsInstance(name_values[2][1], Method) self.assertEqual(name_values[2][1].__name__, 'method') self.assertEqual(name_values[2][1].__doc__, 'My method, overridden') self.assertEqual(name_values[3][0], 'method2') - self.assertTrue(isinstance(name_values[3][1], Method)) + self.assertIsInstance(name_values[3][1], Method) self.assertEqual(name_values[3][1].__name__, 'method2') self.assertEqual(name_values[3][1].__doc__, 'My method2') @@ -1678,12 +1678,12 @@ def method(): "My method" a_desc = ISimple.getDescriptionFor('attr') - self.assertTrue(isinstance(a_desc, Attribute)) + self.assertIsInstance(a_desc, Attribute) self.assertEqual(a_desc.__name__, 'attr') self.assertEqual(a_desc.__doc__, 'My attr') m_desc = ISimple.getDescriptionFor('method') - self.assertTrue(isinstance(m_desc, Method)) + self.assertIsInstance(m_desc, Method) self.assertEqual(m_desc.__name__, 'method') self.assertEqual(m_desc.__doc__, 'My method') @@ -1708,22 +1708,22 @@ def method2(): "My method2" a_desc = IDerived.getDescriptionFor('attr') - self.assertTrue(isinstance(a_desc, Attribute)) + self.assertIsInstance(a_desc, Attribute) self.assertEqual(a_desc.__name__, 'attr') self.assertEqual(a_desc.__doc__, 'My attr') m_desc = IDerived.getDescriptionFor('method') - self.assertTrue(isinstance(m_desc, Method)) + self.assertIsInstance(m_desc, Method) self.assertEqual(m_desc.__name__, 'method') self.assertEqual(m_desc.__doc__, 'My method, overridden') a2_desc = IDerived.getDescriptionFor('attr2') - self.assertTrue(isinstance(a2_desc, Attribute)) + self.assertIsInstance(a2_desc, Attribute) self.assertEqual(a2_desc.__name__, 'attr2') self.assertEqual(a2_desc.__doc__, 'My attr2') m2_desc = IDerived.getDescriptionFor('method2') - self.assertTrue(isinstance(m2_desc, Method)) + self.assertIsInstance(m2_desc, Method) self.assertEqual(m2_desc.__name__, 'method2') self.assertEqual(m2_desc.__doc__, 'My method2') @@ -1747,12 +1747,12 @@ def method(): "My method" a_desc = ISimple['attr'] - self.assertTrue(isinstance(a_desc, Attribute)) + self.assertIsInstance(a_desc, Attribute) self.assertEqual(a_desc.__name__, 'attr') self.assertEqual(a_desc.__doc__, 'My attr') m_desc = ISimple['method'] - self.assertTrue(isinstance(m_desc, Method)) + self.assertIsInstance(m_desc, Method) self.assertEqual(m_desc.__name__, 'method') self.assertEqual(m_desc.__doc__, 'My method') @@ -1777,22 +1777,22 @@ def method2(): "My method2" a_desc = IDerived['attr'] - self.assertTrue(isinstance(a_desc, Attribute)) + self.assertIsInstance(a_desc, Attribute) self.assertEqual(a_desc.__name__, 'attr') self.assertEqual(a_desc.__doc__, 'My attr') m_desc = IDerived['method'] - self.assertTrue(isinstance(m_desc, Method)) + self.assertIsInstance(m_desc, Method) self.assertEqual(m_desc.__name__, 'method') self.assertEqual(m_desc.__doc__, 'My method, overridden') a2_desc = IDerived['attr2'] - self.assertTrue(isinstance(a2_desc, Attribute)) + self.assertIsInstance(a2_desc, Attribute) self.assertEqual(a2_desc.__name__, 'attr2') self.assertEqual(a2_desc.__doc__, 'My attr2') m2_desc = IDerived['method2'] - self.assertTrue(isinstance(m2_desc, Method)) + self.assertIsInstance(m2_desc, Method) self.assertEqual(m2_desc.__name__, 'method2') self.assertEqual(m2_desc.__doc__, 'My method2') @@ -1802,7 +1802,7 @@ def test___contains__nonesuch(self): class IEmpty(Interface): pass - self.assertFalse('nonesuch' in IEmpty) + self.assertNotIn('nonesuch', IEmpty) def test___contains__simple(self): from zope.interface import Attribute @@ -1814,8 +1814,8 @@ class ISimple(Interface): def method(): "My method" - self.assertTrue('attr' in ISimple) - self.assertTrue('method' in ISimple) + self.assertIn('attr', ISimple) + self.assertIn('method', ISimple) def test___contains__derived(self): from zope.interface import Attribute @@ -1836,10 +1836,10 @@ def method(): def method2(): "My method2" - self.assertTrue('attr' in IDerived) - self.assertTrue('method' in IDerived) - self.assertTrue('attr2' in IDerived) - self.assertTrue('method2' in IDerived) + self.assertIn('attr', IDerived) + self.assertIn('method', IDerived) + self.assertIn('attr2', IDerived) + self.assertIn('method2', IDerived) def test___iter__empty(self): from zope.interface import Interface @@ -2223,10 +2223,10 @@ class I2(I1): class I3(I2): pass - self.assertTrue(I3.get('a') is I1.get('a')) + self.assertIs(I3.get('a'), I1.get('a')) I2.__bases__ = (Interface,) - self.assertTrue(I3.get('a') is None) + self.assertIsNone(I3.get('a')) def test___call___defers_to___conform___(self): from zope.interface import Interface @@ -2254,7 +2254,7 @@ class C: pass c = C() - self.assertTrue(IFoo(c) is c) + self.assertIs(IFoo(c), c) def test___call___miss_wo_alternate(self): from zope.interface import Interface @@ -2278,7 +2278,7 @@ class C: pass c = C() - self.assertTrue(IFoo(c, self) is self) + self.assertIs(IFoo(c, self), self) def test___call___w_adapter_hook(self): from zope.interface import Interface @@ -2301,7 +2301,7 @@ class C: old_adapter_hooks = adapter_hooks[:] adapter_hooks[:] = [_miss, _hit] try: - self.assertTrue(IFoo(c) is self) + self.assertIs(IFoo(c), self) finally: adapter_hooks[:] = old_adapter_hooks diff --git a/src/zope/interface/tests/test_interfaces.py b/src/zope/interface/tests/test_interfaces.py index 6c41d494..a1006493 100644 --- a/src/zope/interface/tests/test_interfaces.py +++ b/src/zope/interface/tests/test_interfaces.py @@ -41,7 +41,7 @@ def _getTargetClass(self): def test_ctor(self): target = object() event = self._makeOne(target) - self.assertTrue(event.object is target) + self.assertIs(event.object, target) class RegistrationEventTests(unittest.TestCase, diff --git a/src/zope/interface/tests/test_odd_declarations.py b/src/zope/interface/tests/test_odd_declarations.py index c1e7df0d..09a8de85 100644 --- a/src/zope/interface/tests/test_odd_declarations.py +++ b/src/zope/interface/tests/test_odd_declarations.py @@ -94,8 +94,8 @@ def test_ObjectSpecification(self): self.assertEqual([i.getName() for i in providedBy(c).flattened()], ['I4', 'I31', 'I3', 'I1', 'I2', 'Interface'] ) - self.assertTrue(I1 in providedBy(c)) - self.assertFalse(I3 in providedBy(c)) + self.assertIn(I1, providedBy(c)) + self.assertNotIn(I3, providedBy(c)) self.assertTrue(providedBy(c).extends(I3)) self.assertTrue(providedBy(c).extends(I31)) self.assertFalse(providedBy(c).extends(I5)) @@ -116,8 +116,8 @@ class D(COnly): ['I4', 'I5', 'I31']) self.assertEqual([i.getName() for i in providedBy(c).flattened()], ['I4', 'I5', 'I31', 'I3', 'Interface']) - self.assertFalse(I1 in providedBy(c)) - self.assertFalse(I3 in providedBy(c)) + self.assertNotIn(I1, providedBy(c)) + self.assertNotIn(I3, providedBy(c)) self.assertTrue(providedBy(c).extends(I3)) self.assertFalse(providedBy(c).extends(I1)) self.assertTrue(providedBy(c).extends(I31)) @@ -138,8 +138,8 @@ class D(COnly): ['I4', 'I5', 'I31']) self.assertEqual([i.getName() for i in providedBy(c).flattened()], ['I4', 'I5', 'I31', 'I3', 'Interface']) - self.assertFalse(I1 in providedBy(c)) - self.assertFalse(I3 in providedBy(c)) + self.assertNotIn(I1, providedBy(c)) + self.assertNotIn(I3, providedBy(c)) self.assertTrue(providedBy(c).extends(I3)) self.assertFalse(providedBy(c).extends(I1)) self.assertTrue(providedBy(c).extends(I31)) @@ -211,19 +211,19 @@ class C(A, B): ob = C() directlyProvides(ob, I1, I2) - self.assertTrue(I1 in providedBy(ob)) - self.assertTrue(I2 in providedBy(ob)) - self.assertTrue(IA1 in providedBy(ob)) - self.assertTrue(IA2 in providedBy(ob)) - self.assertTrue(IB in providedBy(ob)) - self.assertTrue(IC in providedBy(ob)) + self.assertIn(I1, providedBy(ob)) + self.assertIn(I2, providedBy(ob)) + self.assertIn(IA1, providedBy(ob)) + self.assertIn(IA2, providedBy(ob)) + self.assertIn(IB, providedBy(ob)) + self.assertIn(IC, providedBy(ob)) directlyProvides(ob, directlyProvidedBy(ob) - I2) - self.assertTrue(I1 in providedBy(ob)) - self.assertFalse(I2 in providedBy(ob)) - self.assertFalse(I2 in providedBy(ob)) + self.assertIn(I1, providedBy(ob)) + self.assertNotIn(I2, providedBy(ob)) + self.assertNotIn(I2, providedBy(ob)) directlyProvides(ob, directlyProvidedBy(ob), I2) - self.assertTrue(I2 in providedBy(ob)) + self.assertIn(I2, providedBy(ob)) # see above # def TODO_test_classProvides_fails_for_odd_class(self): diff --git a/src/zope/interface/tests/test_registry.py b/src/zope/interface/tests/test_registry.py index fbe1ed2b..0da200eb 100644 --- a/src/zope/interface/tests/test_registry.py +++ b/src/zope/interface/tests/test_registry.py @@ -43,8 +43,8 @@ def test_ctor_no_bases(self): comp = self._makeOne('testing') self.assertEqual(comp.__name__, 'testing') self.assertEqual(comp.__bases__, ()) - self.assertTrue(isinstance(comp.adapters, AdapterRegistry)) - self.assertTrue(isinstance(comp.utilities, AdapterRegistry)) + self.assertIsInstance(comp.adapters, AdapterRegistry) + self.assertIsInstance(comp.utilities, AdapterRegistry) self.assertEqual(comp.adapters.__bases__, ()) self.assertEqual(comp.utilities.__bases__, ()) self.assertEqual(comp._utility_registrations, {}) @@ -123,7 +123,7 @@ class IFoo(InterfaceClass): _monkey, _events = self._wrapEvents() with _monkey: comp.registerUtility(_to_reg, ifoo, _name, _info) - self.assertTrue(comp.utilities._adapters[0][ifoo][_name] is _to_reg) + self.assertIs(comp.utilities._adapters[0][ifoo][_name], _to_reg) self.assertEqual(comp._utility_registrations[ifoo, _name], (_to_reg, _info, None)) self.assertEqual(comp.utilities._subscribers[0][ifoo][''], (_to_reg,)) @@ -131,14 +131,14 @@ class IFoo(InterfaceClass): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) def test_registerUtility_w_factory(self): from zope.interface.declarations import InterfaceClass @@ -164,14 +164,14 @@ def _factory(): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _factory) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _factory) def test_registerUtility_no_provided_available(self): @@ -210,14 +210,14 @@ class Foo: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) def test_registerUtility_duplicates_existing_reg(self): from zope.interface.declarations import InterfaceClass @@ -305,25 +305,25 @@ class IFoo(InterfaceClass): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _before) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _before) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) args, kw = _events[1] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _after) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _after) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) def test_registerUtility_w_existing_subscr(self): from zope.interface.declarations import InterfaceClass @@ -463,19 +463,19 @@ class IFoo(InterfaceClass): unreg = comp.unregisterUtility(_to_reg, ifoo, _name) self.assertTrue(unreg) self.assertFalse(comp.utilities._adapters) # all erased - self.assertFalse((ifoo, _name) in comp._utility_registrations) + self.assertNotIn((ifoo, _name), comp._utility_registrations) self.assertFalse(comp.utilities._subscribers) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIsNone(event.object.factory) def test_unregisterUtility_w_factory(self): from zope.interface.declarations import InterfaceClass @@ -503,13 +503,13 @@ def _factory(): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.factory is _factory) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.factory, _factory) def test_unregisterUtility_wo_explicit_provided(self): from zope.interface.declarations import InterfaceClass @@ -538,14 +538,14 @@ class Foo: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) def test_unregisterUtility_wo_component_or_factory(self): from zope.interface.declarations import InterfaceClass @@ -575,14 +575,14 @@ class Foo: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, UtilityRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.component is _to_reg) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is None) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, UtilityRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.component, _to_reg) + self.assertIs(event.object.info, _info) + self.assertIsNone(event.object.factory) def test_unregisterUtility_w_existing_subscr(self): from zope.interface.declarations import InterfaceClass @@ -738,20 +738,20 @@ class IFoo(InterfaceClass): comp.registerUtility(_to_reg, ifoo, _name2, _info) reg = sorted(comp.registeredUtilities(), key=lambda r: r.name) self.assertEqual(len(reg), 2) - self.assertTrue(isinstance(reg[0], UtilityRegistration)) - self.assertTrue(reg[0].registry is comp) - self.assertTrue(reg[0].provided is ifoo) - self.assertTrue(reg[0].name is _name1) - self.assertTrue(reg[0].component is _to_reg) - self.assertTrue(reg[0].info is _info) - self.assertTrue(reg[0].factory is None) - self.assertTrue(isinstance(reg[1], UtilityRegistration)) - self.assertTrue(reg[1].registry is comp) - self.assertTrue(reg[1].provided is ifoo) - self.assertTrue(reg[1].name is _name2) - self.assertTrue(reg[1].component is _to_reg) - self.assertTrue(reg[1].info is _info) - self.assertTrue(reg[1].factory is None) + self.assertIsInstance(reg[0], UtilityRegistration) + self.assertIs(reg[0].registry, comp) + self.assertIs(reg[0].provided, ifoo) + self.assertIs(reg[0].name, _name1) + self.assertIs(reg[0].component, _to_reg) + self.assertIs(reg[0].info, _info) + self.assertIsNone(reg[0].factory) + self.assertIsInstance(reg[1], UtilityRegistration) + self.assertIs(reg[1].registry, comp) + self.assertIs(reg[1].provided, ifoo) + self.assertIs(reg[1].name, _name2) + self.assertIs(reg[1].component, _to_reg) + self.assertIs(reg[1].info, _info) + self.assertIsNone(reg[1].factory) def test_queryUtility_miss_no_default(self): from zope.interface.declarations import InterfaceClass @@ -761,7 +761,7 @@ class IFoo(InterfaceClass): ifoo = IFoo('IFoo') comp = self._makeOne() - self.assertTrue(comp.queryUtility(ifoo) is None) + self.assertIsNone(comp.queryUtility(ifoo)) def test_queryUtility_miss_w_default(self): from zope.interface.declarations import InterfaceClass @@ -772,7 +772,7 @@ class IFoo(InterfaceClass): ifoo = IFoo('IFoo') comp = self._makeOne() _default = object() - self.assertTrue(comp.queryUtility(ifoo, default=_default) is _default) + self.assertIs(comp.queryUtility(ifoo, default=_default), _default) def test_queryUtility_hit(self): from zope.interface.declarations import InterfaceClass @@ -784,7 +784,7 @@ class IFoo(InterfaceClass): _to_reg = object() comp = self._makeOne() comp.registerUtility(_to_reg, ifoo) - self.assertTrue(comp.queryUtility(ifoo) is _to_reg) + self.assertIs(comp.queryUtility(ifoo), _to_reg) def test_getUtility_miss(self): from zope.interface.declarations import InterfaceClass @@ -807,7 +807,7 @@ class IFoo(InterfaceClass): _to_reg = object() comp = self._makeOne() comp.registerUtility(_to_reg, ifoo) - self.assertTrue(comp.getUtility(ifoo) is _to_reg) + self.assertIs(comp.getUtility(ifoo), _to_reg) def test_getUtilitiesFor_miss(self): from zope.interface.declarations import InterfaceClass @@ -902,22 +902,24 @@ def _factory(context): _monkey, _events = self._wrapEvents() with _monkey: comp.registerAdapter(_factory, (ibar,), ifoo, _name, _info) - self.assertTrue(comp.adapters._adapters[1][ibar][ifoo][_name] - is _factory) + self.assertIs( + comp.adapters._adapters[1][ibar][ifoo][_name], + _factory + ) self.assertEqual(comp._adapter_registrations[(ibar,), ifoo, _name], (_factory, _info)) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _factory) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _factory) def test_registerAdapter_no_provided_available(self): from zope.interface.declarations import InterfaceClass @@ -958,22 +960,24 @@ class _Factory: _monkey, _events = self._wrapEvents() with _monkey: comp.registerAdapter(_Factory, (ibar,), name=_name, info=_info) - self.assertTrue(comp.adapters._adapters[1][ibar][ifoo][_name] - is _Factory) + self.assertIs( + comp.adapters._adapters[1][ibar][ifoo][_name], + _Factory + ) self.assertEqual(comp._adapter_registrations[(ibar,), ifoo, _name], (_Factory, _info)) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerAdapter_no_required_available(self): from zope.interface.declarations import InterfaceClass @@ -1032,8 +1036,9 @@ class _Factory: with _monkey: comp.registerAdapter(_Factory, [None], provided=ifoo, name=_name, info=_info) - self.assertTrue( - comp.adapters._adapters[1][Interface][ifoo][_name] is _Factory + self.assertIs( + comp.adapters._adapters[1][Interface][ifoo][_name], + _Factory ) self.assertEqual( comp._adapter_registrations[(Interface,), ifoo, _name], @@ -1043,14 +1048,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (Interface,)) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerAdapter_w_required_containing_class(self): from zope.interface.declarations import InterfaceClass @@ -1080,8 +1085,9 @@ class _Context: with _monkey: comp.registerAdapter(_Factory, [_Context], provided=ifoo, name=_name, info=_info) - self.assertTrue( - comp.adapters._adapters[1][_ctx_impl][ifoo][_name] is _Factory + self.assertIs( + comp.adapters._adapters[1][_ctx_impl][ifoo][_name], + _Factory ) self.assertEqual( comp._adapter_registrations[(_ctx_impl,), ifoo, _name], @@ -1091,14 +1097,14 @@ class _Context: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (_ctx_impl,)) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerAdapter_w_required_containing_junk(self): from zope.interface.declarations import InterfaceClass @@ -1141,22 +1147,24 @@ class _Factory: with _monkey: comp.registerAdapter(_Factory, provided=ifoo, name=_name, info=_info) - self.assertTrue(comp.adapters._adapters[1][ibar][ifoo][_name] - is _Factory) + self.assertIs( + comp.adapters._adapters[1][ibar][ifoo][_name], + _Factory + ) self.assertEqual(comp._adapter_registrations[(ibar,), ifoo, _name], (_Factory, _info)) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) - self.assertTrue(event.object.name is _name) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.name, _name) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerAdapter_wo_event(self): from zope.interface.declarations import InterfaceClass @@ -1238,14 +1246,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_unregisterAdapter_wo_explicit_provided(self): from zope.interface.declarations import InterfaceClass @@ -1273,14 +1281,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_unregisterAdapter_wo_explicit_required(self): from zope.interface.declarations import InterfaceClass @@ -1306,14 +1314,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, AdapterRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, AdapterRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_registeredAdapters_empty(self): comp = self._makeOne() @@ -1340,20 +1348,20 @@ class _Factory: comp.registerAdapter(_Factory, (ibar,), ifoo, _name2, _info) reg = sorted(comp.registeredAdapters(), key=lambda r: r.name) self.assertEqual(len(reg), 2) - self.assertTrue(isinstance(reg[0], AdapterRegistration)) - self.assertTrue(reg[0].registry is comp) - self.assertTrue(reg[0].provided is ifoo) + self.assertIsInstance(reg[0], AdapterRegistration) + self.assertIs(reg[0].registry, comp) + self.assertIs(reg[0].provided, ifoo) self.assertEqual(reg[0].required, (ibar,)) - self.assertTrue(reg[0].name is _name1) - self.assertTrue(reg[0].info is _info) - self.assertTrue(reg[0].factory is _Factory) - self.assertTrue(isinstance(reg[1], AdapterRegistration)) - self.assertTrue(reg[1].registry is comp) - self.assertTrue(reg[1].provided is ifoo) + self.assertIs(reg[0].name, _name1) + self.assertIs(reg[0].info, _info) + self.assertIs(reg[0].factory, _Factory) + self.assertIsInstance(reg[1], AdapterRegistration) + self.assertIs(reg[1].registry, comp) + self.assertIs(reg[1].provided, ifoo) self.assertEqual(reg[1].required, (ibar,)) - self.assertTrue(reg[1].name is _name2) - self.assertTrue(reg[1].info is _info) - self.assertTrue(reg[1].factory is _Factory) + self.assertIs(reg[1].name, _name2) + self.assertIs(reg[1].info, _info) + self.assertIs(reg[1].factory, _Factory) def test_queryAdapter_miss_no_default(self): from zope.interface.declarations import InterfaceClass @@ -1364,7 +1372,7 @@ class IFoo(InterfaceClass): ifoo = IFoo('IFoo') comp = self._makeOne() _context = object() - self.assertTrue(comp.queryAdapter(_context, ifoo) is None) + self.assertIsNone(comp.queryAdapter(_context, ifoo)) def test_queryAdapter_miss_w_default(self): from zope.interface.declarations import InterfaceClass @@ -1376,8 +1384,10 @@ class IFoo(InterfaceClass): comp = self._makeOne() _context = object() _default = object() - self.assertTrue( - comp.queryAdapter(_context, ifoo, default=_default) is _default) + self.assertIs( + comp.queryAdapter(_context, ifoo, default=_default), + _default + ) def test_queryAdapter_hit(self): from zope.interface.declarations import InterfaceClass @@ -1401,8 +1411,8 @@ class _Context: comp = self._makeOne() comp.registerAdapter(_Factory, (ibar,), ifoo) adapter = comp.queryAdapter(_context, ifoo) - self.assertTrue(isinstance(adapter, _Factory)) - self.assertTrue(adapter.context is _context) + self.assertIsInstance(adapter, _Factory) + self.assertIs(adapter.context, _context) def test_getAdapter_miss(self): from zope.interface.declarations import InterfaceClass @@ -1590,9 +1600,11 @@ class _Context2: _context2 = _Context2() _default = object() comp = self._makeOne() - self.assertTrue( + self.assertIs( comp.queryMultiAdapter((_context1, _context2), ifoo, - default=_default) is _default) + default=_default), + _default + ) def test_queryMultiAdapter_hit(self): from zope.interface.declarations import InterfaceClass @@ -1623,7 +1635,7 @@ def __init__(self, context1, context2): comp = self._makeOne() comp.registerAdapter(_Factory, (ibar, ibaz), ifoo) adapter = comp.queryMultiAdapter((_context1, _context2), ifoo) - self.assertTrue(isinstance(adapter, _Factory)) + self.assertIsInstance(adapter, _Factory) self.assertEqual(adapter.context, (_context1, _context2)) def test_getMultiAdapter_miss(self): @@ -1681,7 +1693,7 @@ def __init__(self, context1, context2): comp = self._makeOne() comp.registerAdapter(_Factory, (ibar, ibaz), ifoo) adapter = comp.getMultiAdapter((_context1, _context2), ifoo) - self.assertTrue(isinstance(adapter, _Factory)) + self.assertIsInstance(adapter, _Factory) self.assertEqual(adapter.context, (_context1, _context2)) def _should_not_change(self, comp): @@ -1837,9 +1849,9 @@ def __init__(self, context1, context2): found = sorted(comp.getAdapters((_context1, _context2), ifoo)) self.assertEqual(len(found), 2) self.assertEqual(found[0][0], _name1) - self.assertTrue(isinstance(found[0][1], _Factory1)) + self.assertIsInstance(found[0][1], _Factory1) self.assertEqual(found[1][0], _name2) - self.assertTrue(isinstance(found[1][1], _Factory2)) + self.assertIsInstance(found[1][1], _Factory2) def test_registerSubscriptionAdapter_w_nonblank_name(self): from zope.interface.declarations import InterfaceClass @@ -1882,21 +1894,21 @@ def _factory(context): info=_info) reg = comp.adapters._subscribers[1][ibar][ifoo][_blank] self.assertEqual(len(reg), 1) - self.assertTrue(reg[0] is _factory) + self.assertIs(reg[0], _factory) self.assertEqual(comp._subscription_registrations, [((ibar,), ifoo, _blank, _factory, _info)]) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, _blank) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _factory) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _factory) def test_registerSubscriptionAdapter_wo_explicit_provided(self): from zope.interface.declarations import InterfaceClass @@ -1922,21 +1934,21 @@ class _Factory: comp.registerSubscriptionAdapter(_Factory, (ibar,), info=_info) reg = comp.adapters._subscribers[1][ibar][ifoo][_blank] self.assertEqual(len(reg), 1) - self.assertTrue(reg[0] is _Factory) + self.assertIs(reg[0], _Factory) self.assertEqual(comp._subscription_registrations, [((ibar,), ifoo, _blank, _Factory, _info)]) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, _blank) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerSubscriptionAdapter_wo_explicit_required(self): from zope.interface.declarations import InterfaceClass @@ -1962,21 +1974,21 @@ class _Factory: ) reg = comp.adapters._subscribers[1][ibar][ifoo][_blank] self.assertEqual(len(reg), 1) - self.assertTrue(reg[0] is _Factory) + self.assertIs(reg[0], _Factory) self.assertEqual(comp._subscription_registrations, [((ibar,), ifoo, _blank, _Factory, _info)]) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, _blank) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _Factory) def test_registerSubscriptionAdapter_wo_event(self): from zope.interface.declarations import InterfaceClass @@ -2022,20 +2034,20 @@ class _Factory: comp.registerSubscriptionAdapter(_Factory, (ibar,), ifoo, info=_info) reg = list(comp.registeredSubscriptionAdapters()) self.assertEqual(len(reg), 2) - self.assertTrue(isinstance(reg[0], SubscriptionRegistration)) - self.assertTrue(reg[0].registry is comp) - self.assertTrue(reg[0].provided is ifoo) + self.assertIsInstance(reg[0], SubscriptionRegistration) + self.assertIs(reg[0].registry, comp) + self.assertIs(reg[0].provided, ifoo) self.assertEqual(reg[0].required, (ibar,)) self.assertEqual(reg[0].name, _blank) - self.assertTrue(reg[0].info is _info) - self.assertTrue(reg[0].factory is _Factory) - self.assertTrue(isinstance(reg[1], SubscriptionRegistration)) - self.assertTrue(reg[1].registry is comp) - self.assertTrue(reg[1].provided is ifoo) + self.assertIs(reg[0].info, _info) + self.assertIs(reg[0].factory, _Factory) + self.assertIsInstance(reg[1], SubscriptionRegistration) + self.assertIs(reg[1].registry, comp) + self.assertIs(reg[1].provided, ifoo) self.assertEqual(reg[1].required, (ibar,)) self.assertEqual(reg[1].name, _blank) - self.assertTrue(reg[1].info is _info) - self.assertTrue(reg[1].factory is _Factory) + self.assertIs(reg[1].info, _info) + self.assertIs(reg[1].factory, _Factory) def test_unregisterSubscriptionAdapter_w_nonblank_name(self): from zope.interface.declarations import InterfaceClass @@ -2111,14 +2123,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is None) + self.assertIsNone(event.object.factory) def test_unregisterSubscriptionAdapter_hit_w_factory(self): from zope.interface.declarations import InterfaceClass @@ -2146,14 +2158,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_unregisterSubscriptionAdapter_wo_explicit_provided(self): from zope.interface.declarations import InterfaceClass @@ -2181,14 +2193,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_unregisterSubscriptionAdapter_wo_explicit_required(self): from zope.interface.declarations import InterfaceClass @@ -2214,14 +2226,14 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, SubscriptionRegistration)) - self.assertTrue(event.object.registry is comp) - self.assertTrue(event.object.provided is ifoo) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, SubscriptionRegistration) + self.assertIs(event.object.registry, comp) + self.assertIs(event.object.provided, ifoo) self.assertEqual(event.object.required, (ibar,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_subscribers_empty(self): from zope.interface.declarations import InterfaceClass @@ -2276,8 +2288,8 @@ def _klassname(x): subscribers = sorted(subscribers, key=_klassname) self.assertEqual(len(subscribers), 2) - self.assertTrue(isinstance(subscribers[0], _Derived)) - self.assertTrue(isinstance(subscribers[1], _Factory)) + self.assertIsInstance(subscribers[0], _Derived) + self.assertIsInstance(subscribers[1], _Factory) def test_registerHandler_w_nonblank_name(self): from zope.interface.declarations import InterfaceClass @@ -2316,20 +2328,20 @@ def _factory(context): comp.registerHandler(_factory, (ifoo,), info=_info) reg = comp.adapters._subscribers[1][ifoo][None][_blank] self.assertEqual(len(reg), 1) - self.assertTrue(reg[0] is _factory) + self.assertIs(reg[0], _factory) self.assertEqual(comp._handler_registrations, [((ifoo,), _blank, _factory, _info)]) self.assertEqual(len(_events), 1) args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Registered)) - self.assertTrue(isinstance(event.object, HandlerRegistration)) - self.assertTrue(event.object.registry is comp) + self.assertIsInstance(event, Registered) + self.assertIsInstance(event.object, HandlerRegistration) + self.assertIs(event.object.registry, comp) self.assertEqual(event.object.required, (ifoo,)) self.assertEqual(event.object.name, _blank) - self.assertTrue(event.object.info is _info) - self.assertTrue(event.object.factory is _factory) + self.assertIs(event.object.info, _info) + self.assertIs(event.object.factory, _factory) def test_registerHandler_wo_explicit_required_no_event(self): from zope.interface.declarations import InterfaceClass @@ -2351,7 +2363,7 @@ class _Factory: comp.registerHandler(_Factory, info=_info, event=False) reg = comp.adapters._subscribers[1][ifoo][None][_blank] self.assertEqual(len(reg), 1) - self.assertTrue(reg[0] is _Factory) + self.assertIs(reg[0], _Factory) self.assertEqual(comp._handler_registrations, [((ifoo,), _blank, _Factory, _info)]) self.assertEqual(len(_events), 0) @@ -2384,12 +2396,12 @@ def _factory_name(x): subscribers = sorted(comp.registeredHandlers(), key=_factory_name) self.assertEqual(len(subscribers), 2) - self.assertTrue(isinstance(subscribers[0], HandlerRegistration)) + self.assertIsInstance(subscribers[0], HandlerRegistration) self.assertEqual(subscribers[0].required, (ifoo,)) self.assertEqual(subscribers[0].name, '') self.assertEqual(subscribers[0].factory, _factory1) self.assertEqual(subscribers[0].info, '') - self.assertTrue(isinstance(subscribers[1], HandlerRegistration)) + self.assertIsInstance(subscribers[1], HandlerRegistration) self.assertEqual(subscribers[1].required, (ifoo,)) self.assertEqual(subscribers[1].name, '') self.assertEqual(subscribers[1].factory, _factory2) @@ -2446,12 +2458,12 @@ def _factory(context): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, HandlerRegistration)) - self.assertTrue(event.object.registry is comp) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, HandlerRegistration) + self.assertIs(event.object.registry, comp) self.assertEqual(event.object.required, (ifoo,)) self.assertEqual(event.object.name, '') - self.assertTrue(event.object.factory is _factory) + self.assertIs(event.object.factory, _factory) def test_unregisterHandler_hit_w_only_explicit_provided(self): from zope.interface.declarations import InterfaceClass @@ -2477,12 +2489,12 @@ def _factory(context): args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, HandlerRegistration)) - self.assertTrue(event.object.registry is comp) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, HandlerRegistration) + self.assertIs(event.object.registry, comp) self.assertEqual(event.object.required, (ifoo,)) self.assertEqual(event.object.name, '') - self.assertTrue(event.object.factory is None) + self.assertIsNone(event.object.factory) def test_unregisterHandler_wo_explicit_required(self): from zope.interface.declarations import InterfaceClass @@ -2507,13 +2519,13 @@ class _Factory: args, kw = _events[0] event, = args self.assertEqual(kw, {}) - self.assertTrue(isinstance(event, Unregistered)) - self.assertTrue(isinstance(event.object, HandlerRegistration)) - self.assertTrue(event.object.registry is comp) + self.assertIsInstance(event, Unregistered) + self.assertIsInstance(event.object, HandlerRegistration) + self.assertIs(event.object.registry, comp) self.assertEqual(event.object.required, (ifoo,)) self.assertEqual(event.object.name, '') self.assertEqual(event.object.info, '') - self.assertTrue(event.object.factory is _Factory) + self.assertIs(event.object.factory, _Factory) def test_handle_empty(self): from zope.interface.declarations import InterfaceClass @@ -2802,38 +2814,38 @@ def test___hash__(self): def test___eq___identity(self): _component = object() ur, _registry, _name = self._makeOne(_component) - self.assertTrue(ur == ur) + self.assertEqual(ur, ur) def test___eq___hit(self): _component = object() ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component) - self.assertTrue(ur == ur2) + self.assertEqual(ur, ur2) def test___eq___miss(self): _component = object() _component2 = object() ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component2) - self.assertFalse(ur == ur2) + self.assertNotEqual(ur, ur2) def test___ne___identity(self): _component = object() ur, _registry, _name = self._makeOne(_component) - self.assertFalse(ur != ur) + self.assertEqual(ur, ur) def test___ne___hit(self): _component = object() ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component) - self.assertFalse(ur != ur2) + self.assertEqual(ur, ur2) def test___ne___miss(self): _component = object() _component2 = object() ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component2) - self.assertTrue(ur != ur2) + self.assertNotEqual(ur, ur2) def test___lt___identity(self): _component = object() @@ -2852,18 +2864,18 @@ def test___lt___miss(self): ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component2) ur2.name = _name + '2' - self.assertTrue(ur < ur2) + self.assertLess(ur, ur2) def test___le___identity(self): _component = object() ur, _registry, _name = self._makeOne(_component) - self.assertTrue(ur <= ur) + self.assertLessEqual(ur, ur) def test___le___hit(self): _component = object() ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component) - self.assertTrue(ur <= ur2) + self.assertLessEqual(ur, ur2) def test___le___miss(self): _component = object() @@ -2871,7 +2883,7 @@ def test___le___miss(self): ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component2) ur2.name = _name + '2' - self.assertTrue(ur <= ur2) + self.assertLessEqual(ur, ur2) def test___gt___identity(self): _component = object() @@ -2884,7 +2896,7 @@ def test___gt___hit(self): ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component2) ur2.name = _name + '2' - self.assertTrue(ur2 > ur) + self.assertGreater(ur2, ur) def test___gt___miss(self): _component = object() @@ -2895,7 +2907,7 @@ def test___gt___miss(self): def test___ge___identity(self): _component = object() ur, _registry, _name = self._makeOne(_component) - self.assertTrue(ur >= ur) + self.assertGreaterEqual(ur, ur) def test___ge___miss(self): _component = object() @@ -2910,7 +2922,7 @@ def test___ge___hit(self): ur, _registry, _name = self._makeOne(_component) ur2, _, _ = self._makeOne(_component) ur2.name = _name + '2' - self.assertTrue(ur2 >= ur) + self.assertGreaterEqual(ur2, ur) class AdapterRegistrationTests(unittest.TestCase): @@ -3007,38 +3019,38 @@ def test___hash__(self): def test___eq___identity(self): _component = object() ar, _registry, _name = self._makeOne(_component) - self.assertTrue(ar == ar) + self.assertEqual(ar, ar) def test___eq___hit(self): _component = object() ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component) - self.assertTrue(ar == ar2) + self.assertEqual(ar, ar2) def test___eq___miss(self): _component = object() _component2 = object() ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) - self.assertFalse(ar == ar2) + self.assertNotEqual(ar, ar2) def test___ne___identity(self): _component = object() ar, _registry, _name = self._makeOne(_component) - self.assertFalse(ar != ar) + self.assertEqual(ar, ar) def test___ne___miss(self): _component = object() ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component) - self.assertFalse(ar != ar2) + self.assertEqual(ar, ar2) def test___ne___hit_component(self): _component = object() _component2 = object() ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) - self.assertTrue(ar != ar2) + self.assertNotEqual(ar, ar2) def test___ne___hit_provided(self): from zope.interface.declarations import InterfaceClass @@ -3051,7 +3063,7 @@ class IFoo(InterfaceClass): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component) ar2.provided = ibaz - self.assertTrue(ar != ar2) + self.assertNotEqual(ar, ar2) def test___ne___hit_required(self): from zope.interface.declarations import InterfaceClass @@ -3065,7 +3077,7 @@ class IFoo(InterfaceClass): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) ar2.required = (ibaz,) - self.assertTrue(ar != ar2) + self.assertNotEqual(ar, ar2) def test___lt___identity(self): _component = object() @@ -3084,18 +3096,18 @@ def test___lt___miss(self): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) ar2.name = _name + '2' - self.assertTrue(ar < ar2) + self.assertLess(ar, ar2) def test___le___identity(self): _component = object() ar, _registry, _name = self._makeOne(_component) - self.assertTrue(ar <= ar) + self.assertLessEqual(ar, ar) def test___le___hit(self): _component = object() ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component) - self.assertTrue(ar <= ar2) + self.assertLessEqual(ar, ar2) def test___le___miss(self): _component = object() @@ -3103,7 +3115,7 @@ def test___le___miss(self): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) ar2.name = _name + '2' - self.assertTrue(ar <= ar2) + self.assertLessEqual(ar, ar2) def test___gt___identity(self): _component = object() @@ -3116,7 +3128,7 @@ def test___gt___hit(self): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component2) ar2.name = _name + '2' - self.assertTrue(ar2 > ar) + self.assertGreater(ar2, ar) def test___gt___miss(self): _component = object() @@ -3127,7 +3139,7 @@ def test___gt___miss(self): def test___ge___identity(self): _component = object() ar, _registry, _name = self._makeOne(_component) - self.assertTrue(ar >= ar) + self.assertGreaterEqual(ar, ar) def test___ge___miss(self): _component = object() @@ -3142,7 +3154,7 @@ def test___ge___hit(self): ar, _registry, _name = self._makeOne(_component) ar2, _, _ = self._makeOne(_component) ar2.name = _name + '2' - self.assertTrue(ar2 >= ar) + self.assertGreaterEqual(ar2, ar) class SubscriptionRegistrationTests(unittest.TestCase): @@ -3229,9 +3241,9 @@ def test_properties(self): def _factory(context): raise NotImplementedError() hr, _, _ = self._makeOne(_factory) - self.assertTrue(hr.handler is _factory) - self.assertTrue(hr.factory is hr.handler) - self.assertTrue(hr.provided is None) + self.assertIs(hr.handler, _factory) + self.assertIs(hr.factory, hr.handler) + self.assertIsNone(hr.provided) def test___repr___factory_w_name(self): From 56963f3193b644c9378c973d5b433f9ed6f6d9dd Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 16:11:30 +0200 Subject: [PATCH 06/13] - changes made by autopep8 to changes made by teyit --- src/zope/interface/tests/test_interface.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zope/interface/tests/test_interface.py b/src/zope/interface/tests/test_interface.py index 60f7cea5..164add14 100644 --- a/src/zope/interface/tests/test_interface.py +++ b/src/zope/interface/tests/test_interface.py @@ -1191,19 +1191,19 @@ def __init__(self): # pylint:disable=super-init-not-called def test_comparison_with_None(self): # pylint:disable=singleton-comparison,misplaced-comparison-constant iface = self._makeOne() - self.assertLess(iface, None) # noqa E711 - self.assertLessEqual(iface, None) # noqa E711 - self.assertNotEqual(iface, None) # noqa E711 - self.assertNotEqual(iface, None) # noqa E711 + self.assertLess(iface, None) # noqa E711 + self.assertLessEqual(iface, None) # noqa E711 + self.assertNotEqual(iface, None) # noqa E711 + self.assertNotEqual(iface, None) # noqa E711 self.assertFalse(iface >= None) # noqa E711 self.assertFalse(iface > None) # noqa E711 self.assertFalse(None < iface) # noqa E711 self.assertFalse(None <= iface) # noqa E711 - self.assertNotEqual(None, iface) # noqa E711 - self.assertNotEqual(None, iface) # noqa E711 - self.assertGreaterEqual(None, iface) # noqa E711 - self.assertGreater(None, iface) # noqa E711 + self.assertNotEqual(None, iface) # noqa E711 + self.assertNotEqual(None, iface) # noqa E711 + self.assertGreaterEqual(None, iface) # noqa E711 + self.assertGreater(None, iface) # noqa E711 def test_comparison_with_same_instance(self): # pylint:disable=comparison-with-itself From 8e68d9a0b4338c4ed5e1ced754a0b3f260ed3d7e Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Mon, 2 Sep 2024 16:36:39 +0200 Subject: [PATCH 07/13] - must use editable package due to the way tests are discovered and run --- .meta.toml | 4 ++++ tox.ini | 2 ++ 2 files changed, 6 insertions(+) diff --git a/.meta.toml b/.meta.toml index d99ebfa6..600b0413 100644 --- a/.meta.toml +++ b/.meta.toml @@ -23,6 +23,10 @@ testenv-deps = [ testenv-setenv = [ "ZOPE_INTERFACE_STRICT_IRO=1", ] +testenv-additional = [ + "# Must use editable package due to the way tests are discovered and run", + "usedevelop = true", + ] coverage-command = "coverage combine" coverage-additional = [ "depends = py37,py37-pure,py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,pypy,pypy3,docs", diff --git a/tox.ini b/tox.ini index 9cf1b5c7..519c2029 100644 --- a/tox.ini +++ b/tox.ini @@ -32,6 +32,8 @@ commands = extras = test docs +# Must use editable package due to the way tests are discovered and run +usedevelop = true [testenv:coverage] basepython = python3 From 95ba43e5c9af4839d7e76de1d22f5ca60b916d28 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Tue, 3 Sep 2024 16:28:33 +0200 Subject: [PATCH 08/13] - remove workaround so the actual error shows --- .meta.toml | 4 ---- tox.ini | 2 -- 2 files changed, 6 deletions(-) diff --git a/.meta.toml b/.meta.toml index 600b0413..d99ebfa6 100644 --- a/.meta.toml +++ b/.meta.toml @@ -23,10 +23,6 @@ testenv-deps = [ testenv-setenv = [ "ZOPE_INTERFACE_STRICT_IRO=1", ] -testenv-additional = [ - "# Must use editable package due to the way tests are discovered and run", - "usedevelop = true", - ] coverage-command = "coverage combine" coverage-additional = [ "depends = py37,py37-pure,py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,pypy,pypy3,docs", diff --git a/tox.ini b/tox.ini index 519c2029..9cf1b5c7 100644 --- a/tox.ini +++ b/tox.ini @@ -32,8 +32,6 @@ commands = extras = test docs -# Must use editable package due to the way tests are discovered and run -usedevelop = true [testenv:coverage] basepython = python3 From 64e4d166e056097f717dbe00f274b0074ea8e489 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Sat, 7 Sep 2024 10:19:46 +0200 Subject: [PATCH 09/13] - remove some Python 3.7 references --- .meta.toml | 5 +---- tox.ini | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.meta.toml b/.meta.toml index d99ebfa6..b7958df9 100644 --- a/.meta.toml +++ b/.meta.toml @@ -17,15 +17,12 @@ use-flake8 = true testenv-commands = [ "coverage run -p -m unittest discover -s src {posargs}", ] -testenv-deps = [ - "py37: urllib3 < 2", - ] testenv-setenv = [ "ZOPE_INTERFACE_STRICT_IRO=1", ] coverage-command = "coverage combine" coverage-additional = [ - "depends = py37,py37-pure,py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,pypy,pypy3,docs", + "depends = py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,py312,py312-pure,py313,py313-pure,pypy3,docs", "parallel_show_output = true", ] diff --git a/tox.ini b/tox.ini index 9cf1b5c7..ddfdbb0c 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,6 @@ envlist = pip_pre = py313: true deps = setuptools <74 - py37: urllib3 < 2 Sphinx setenv = pure: PURE_PYTHON=1 @@ -39,7 +38,6 @@ allowlist_externals = mkdir deps = coverage - py37: urllib3 < 2 setenv = PURE_PYTHON=1 commands = @@ -47,7 +45,7 @@ commands = coverage combine coverage html -i coverage report -i -m --fail-under=99 -depends = py37,py37-pure,py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,pypy,pypy3,docs +depends = py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,py312,py312-pure,py313,py313-pure,pypy3,docs parallel_show_output = true [testenv:release-check] From a6fc65ebfba44a69de6c2aeb88863b3753cd8818 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Tue, 17 Sep 2024 11:19:38 +0200 Subject: [PATCH 10/13] - use the latest meta/config templates --- .coveragerc | 30 ------------------------------ .github/workflows/tests.yml | 19 +------------------ .manylinux-install.sh | 19 +++++++------------ .meta.toml | 4 ++-- MANIFEST.in | 1 - pyproject.toml | 25 +++++++++++++++++++++++++ tox.ini | 16 +++++++++------- 7 files changed, 44 insertions(+), 70 deletions(-) delete mode 100644 .coveragerc create mode 100644 pyproject.toml diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index b620b736..00000000 --- a/.coveragerc +++ /dev/null @@ -1,30 +0,0 @@ -# Generated from: -# https://github.com/zopefoundation/meta/tree/master/config/c-code -[run] -source = zope.interface -# New in 5.0; required for the GHA coveralls submission. -relative_files = True -branch = true - -[paths] -source = - src/ - .tox/*/lib/python*/site-packages/ - .tox/pypy*/site-packages/ - -[report] -show_missing = true -precision = 2 -ignore_errors = True -exclude_lines = - except ImportError: - if __name__ == '__main__': - pragma: no cover - pragma: nocover - raise AssertionError - raise NotImplementedError - raise unittest.Skip - self.fail\( - -[html] -directory = parts/htmlcov diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7bee49be..9c6ef543 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -152,13 +152,7 @@ jobs: restore-keys: | ${{ runner.os }}-pip- - - name: Install Build Dependencies (3.13) - if: matrix.python-version == '3.13' - run: | - pip install -U pip - pip install -U "setuptools <74" wheel twine - name: Install Build Dependencies - if: matrix.python-version != '3.13' run: | pip install -U pip pip install -U "setuptools <74" wheel twine @@ -199,15 +193,7 @@ jobs: python setup.py build_ext -i python setup.py bdist_wheel - - name: Install zope.interface and dependencies (3.13) - if: matrix.python-version == '3.13' - run: | - # Install to collect dependencies into the (pip) cache. - # Use "--pre" here because dependencies with support for this future - # Python release may only be available as pre-releases - pip install --pre .[test] - name: Install zope.interface and dependencies - if: matrix.python-version != '3.13' run: | # Install to collect dependencies into the (pip) cache. pip install .[test] @@ -250,7 +236,6 @@ jobs: && startsWith(github.ref, 'refs/tags') && !startsWith(runner.os, 'Linux') && !startsWith(matrix.python-version, 'pypy') - && !startsWith(matrix.python-version, '3.13') env: TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} run: | @@ -426,7 +411,7 @@ jobs: - name: Install zope.interface run: | pip install -U wheel - pip install -U coverage + pip install -U coverage[toml] pip install -U "`ls dist/zope.interface-*.whl`[docs]" - name: Build docs env: @@ -522,8 +507,6 @@ jobs: name: manylinux_${{ matrix.image }}_wheels.zip - name: Restore pip cache permissions run: sudo chown -R $(whoami) ${{ steps.pip-cache-default.outputs.dir }} - - name: Prevent publishing wheels for unreleased Python versions - run: VER=$(echo '3.13' | tr -d .) && ls -al wheelhouse && sudo rm -f wheelhouse/*-cp${VER}*.whl && ls -al wheelhouse - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 if: > diff --git a/.manylinux-install.sh b/.manylinux-install.sh index 39697d5e..7efbd2ed 100755 --- a/.manylinux-install.sh +++ b/.manylinux-install.sh @@ -28,12 +28,12 @@ yum -y install libffi-devel tox_env_map() { case $1 in - *"cp313"*) echo 'py313';; *"cp38"*) echo 'py38';; *"cp39"*) echo 'py39';; *"cp310"*) echo 'py310';; *"cp311"*) echo 'py311';; *"cp312"*) echo 'py312';; + *"cp313"*) echo 'py313';; *) echo 'py';; esac } @@ -41,19 +41,14 @@ tox_env_map() { # Compile wheels for PYBIN in /opt/python/*/bin; do if \ - [[ "${PYBIN}" == *"cp313/"* ]] || \ - [[ "${PYBIN}" == *"cp311/"* ]] || \ - [[ "${PYBIN}" == *"cp312/"* ]] || \ [[ "${PYBIN}" == *"cp38/"* ]] || \ [[ "${PYBIN}" == *"cp39/"* ]] || \ - [[ "${PYBIN}" == *"cp310/"* ]] ; then - if [[ "${PYBIN}" == *"cp313/"* ]] ; then - "${PYBIN}/pip" install --pre -e /io/ - "${PYBIN}/pip" wheel /io/ --pre -w wheelhouse/ - else - "${PYBIN}/pip" install -e /io/ - "${PYBIN}/pip" wheel /io/ -w wheelhouse/ - fi + [[ "${PYBIN}" == *"cp310/"* ]] || \ + [[ "${PYBIN}" == *"cp311/"* ]] || \ + [[ "${PYBIN}" == *"cp312/"* ]] || \ + [[ "${PYBIN}" == *"cp313/"* ]] ; then + "${PYBIN}/pip" install -e /io/ + "${PYBIN}/pip" wheel /io/ -w wheelhouse/ if [ `uname -m` == 'aarch64' ]; then cd /io/ ${PYBIN}/pip install tox diff --git a/.meta.toml b/.meta.toml index b7958df9..2d8b3641 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,13 +2,13 @@ # https://github.com/zopefoundation/meta/tree/master/config/c-code [meta] template = "c-code" -commit-id = "acd39fc2" +commit-id = "32ea0a11" [python] with-pypy = true with-sphinx-doctests = true with-windows = true -with-future-python = true +with-future-python = false with-docs = true with-macos = false diff --git a/MANIFEST.in b/MANIFEST.in index 6eece7ff..8ecf1c24 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,7 +6,6 @@ include *.txt include buildout.cfg include tox.ini include .pre-commit-config.yaml -include .coveragerc recursive-include docs *.py recursive-include docs *.rst diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..10279c48 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,25 @@ +# +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/c-code + +[build-system] +requires = ["setuptools<74"] +build-backend = "setuptools.build_meta" + +[tool.coverage.run] +branch = true +source = ["zope.interface"] +relative_files = true + +[tool.coverage.report] +fail_under = 99 +precision = 2 +ignore_errors = true +show_missing = true +exclude_lines = ["pragma: no cover", "pragma: nocover", "except ImportError:", "raise NotImplementedError", "if __name__ == '__main__':", "self.fail", "raise AssertionError", "raise unittest.Skip"] + +[tool.coverage.html] +directory = "parts/htmlcov" + +[tool.coverage.paths] +source = ["src/", ".tox/*/lib/python*/site-packages/", ".tox/pypy*/site-packages/"] diff --git a/tox.ini b/tox.ini index ddfdbb0c..3788f549 100644 --- a/tox.ini +++ b/tox.ini @@ -15,16 +15,12 @@ envlist = coverage [testenv] -pip_pre = py313: true deps = setuptools <74 - Sphinx setenv = pure: PURE_PYTHON=1 !pure-!pypy3: PURE_PYTHON=0 ZOPE_INTERFACE_STRICT_IRO=1 - py312: VIRTUALENV_PIP=23.1.2 - py312: PIP_REQUIRE_VIRTUALENV=0 commands = coverage run -p -m unittest discover -s src {posargs} sphinx-build -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest @@ -32,19 +28,24 @@ extras = test docs +[testenv:setuptools-latest] +basepython = python3 +deps = + git+https://github.com/pypa/setuptools.git\#egg=setuptools + [testenv:coverage] basepython = python3 allowlist_externals = mkdir deps = - coverage + coverage[toml] setenv = PURE_PYTHON=1 commands = mkdir -p {toxinidir}/parts/htmlcov coverage combine - coverage html -i - coverage report -i -m --fail-under=99 + coverage html + coverage report depends = py38,py38-pure,py39,py39-pure,py310,py310-pure,py311,py311-pure,py312,py312-pure,py313,py313-pure,pypy3,docs parallel_show_output = true @@ -53,6 +54,7 @@ description = ensure that the distribution is ready to release basepython = python3 skip_install = true deps = + setuptools <74 twine build check-manifest From 0babe45121ab73febf166cf553d58d9ce18a98b6 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Tue, 17 Sep 2024 11:32:53 +0200 Subject: [PATCH 11/13] - fix coverage install --- .github/workflows/tests.yml | 2 +- .meta.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9c6ef543..dccee042 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -316,7 +316,7 @@ jobs: # works fine with non-editable installs.) run: | pip install -U wheel - pip install -U --no-binary :all: coverage + pip install -U --no-binary :all: coverage[toml] # Unzip into src/ so that testrunner can find the .so files # when we ask it to load tests from that directory. This # might also save some build time? diff --git a/.meta.toml b/.meta.toml index 2d8b3641..5a406b5d 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,7 +2,7 @@ # https://github.com/zopefoundation/meta/tree/master/config/c-code [meta] template = "c-code" -commit-id = "32ea0a11" +commit-id = "a8ae60f1" [python] with-pypy = true @@ -70,7 +70,7 @@ additional-install = [ " # works fine with non-editable installs.)", " run: |", " pip install -U wheel", - " pip install -U --no-binary :all: coverage", + " pip install -U --no-binary :all: coverage[toml]", " # Unzip into src/ so that testrunner can find the .so files", " # when we ask it to load tests from that directory. This", " # might also save some build time?", From f10b66412b8b05804db21466baabaaa57c1b93db Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Tue, 17 Sep 2024 11:40:28 +0200 Subject: [PATCH 12/13] - dial down coverage a tiny bit --- .meta.toml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.meta.toml b/.meta.toml index 5a406b5d..d9cfeaff 100644 --- a/.meta.toml +++ b/.meta.toml @@ -38,7 +38,7 @@ additional-config = [ ] [coverage] -fail-under = 99 +fail-under = 98 [manifest] additional-rules = [ diff --git a/pyproject.toml b/pyproject.toml index 10279c48..17da486f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ source = ["zope.interface"] relative_files = true [tool.coverage.report] -fail_under = 99 +fail_under = 98 precision = 2 ignore_errors = true show_missing = true From 59833b79b60f2129e611324a9d0472d05019b983 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl <jens@plyp.com> Date: Thu, 19 Sep 2024 09:15:58 +0200 Subject: [PATCH 13/13] - force-install package just like on GHA to make tests run locally --- .meta.toml | 4 ++-- MANIFEST.in | 1 - setup.py | 2 +- tox.ini | 1 + 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.meta.toml b/.meta.toml index d9cfeaff..ba98066f 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,7 +2,7 @@ # https://github.com/zopefoundation/meta/tree/master/config/c-code [meta] template = "c-code" -commit-id = "a8ae60f1" +commit-id = "85622de1" [python] with-pypy = true @@ -15,6 +15,7 @@ with-macos = false [tox] use-flake8 = true testenv-commands = [ + "pip install -U -e .[test]", "coverage run -p -m unittest discover -s src {posargs}", ] testenv-setenv = [ @@ -46,7 +47,6 @@ additional-rules = [ "include *.cmd", "include *.sh", "include *.yml", - "include .coveragerc", "recursive-include benchmarks *.py", "recursive-include docs *.bat", "recursive-include docs *.py", diff --git a/MANIFEST.in b/MANIFEST.in index 8ecf1c24..1aef3e93 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -17,7 +17,6 @@ include *.yaml include *.cmd include *.sh include *.yml -include .coveragerc recursive-include benchmarks *.py recursive-include docs *.bat recursive-include docs *.py diff --git a/setup.py b/setup.py index e282b642..ad31a0c8 100644 --- a/setup.py +++ b/setup.py @@ -82,7 +82,7 @@ def _unavailable(self, e): tests_require = [ # The test dependencies should NOT have direct or transitive # dependencies on zope.interface. - 'coverage >= 5.0.3', + 'coverage[toml]', 'zope.event', 'zope.testing', ] diff --git a/tox.ini b/tox.ini index 3788f549..ed7830b5 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ setenv = !pure-!pypy3: PURE_PYTHON=0 ZOPE_INTERFACE_STRICT_IRO=1 commands = + pip install -U -e .[test] coverage run -p -m unittest discover -s src {posargs} sphinx-build -b doctest -d {envdir}/.cache/doctrees docs {envdir}/.cache/doctest extras =