From 9eefc1cd58769209dac91e7167b0eda86c60a7c4 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Wed, 29 Nov 2023 10:10:08 -0800 Subject: [PATCH 1/5] update test environment to Python 3.12 Use fedmsg directly from the "develop" branch of the upstream repo, since Python 3.12 support was added there but has not made it into an official release yet. --- doc/requirements.txt | 2 +- setup.py | 2 +- tox.ini | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index c67f31f..ee9b0a2 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,4 @@ cloud_sptheme nose -fedmsg +fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop mako diff --git a/setup.py b/setup.py index 582a204..f6f0b4b 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ setup_requires = [ ] install_requires = [ - 'fedmsg', + 'fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop', ] tests_require = [ 'nose', diff --git a/tox.ini b/tox.ini index 0e16179..f3f0977 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] -envlist = flake8,py{38,39},docs +envlist = flake8,py312,docs downloadcache = {toxworkdir}/_download/ [testenv] deps = - fedmsg + fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop nose coverage commands = @@ -21,7 +21,7 @@ commands= deps = cloud_sptheme nose - fedmsg + fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop mako commands = sphinx-build doc/ htmldocs/ From c4deb7e0492e9bbd206f9d2ec36427f368a3abc8 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Thu, 30 Nov 2023 15:14:38 -0800 Subject: [PATCH 2/5] replace nose with unittest The nose package is no longer supported, and is not functional under Python 3.12. Replace nose with the built-in unittest package. Remove references to the .context attribute which is generated by nose but is absent from tests loaded by unittest. --- doc/requirements.txt | 1 - fedmsg_meta_umb/doc_utilities.py | 63 ++++++++++++++++++-------------- python-fedmsg-meta-umb.spec | 1 - setup.py | 8 ---- tox.ini | 4 +- 5 files changed, 36 insertions(+), 41 deletions(-) diff --git a/doc/requirements.txt b/doc/requirements.txt index ee9b0a2..9b3e8fc 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,3 @@ cloud_sptheme -nose fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop mako diff --git a/fedmsg_meta_umb/doc_utilities.py b/fedmsg_meta_umb/doc_utilities.py index 70609d6..508eac4 100644 --- a/fedmsg_meta_umb/doc_utilities.py +++ b/fedmsg_meta_umb/doc_utilities.py @@ -2,14 +2,14 @@ This code: -- Uses :mod:`nose` to find all the fedmsg.meta unittests. +- Uses :mod:`unittest` to find all the fedmsg.meta unittests. - Extracts all the metadata and docstrings from those tests. - Uses all that to generate a giant .rst document of all the fedmsg topics and what they are about with example messages. """ -import nose +import unittest import pprint import textwrap import uuid @@ -103,10 +103,20 @@ def datagrepper_link(topic): def load_classes(module): - testdir = os.path.dirname(os.path.abspath(__file__)) + '/tests' - suitelist = map(list, nose.loader.defaultTestLoader().loadTestsFromDir(testdir)) - clslist = [cls for suite in suitelist for cls in suite] - return clslist + suite = unittest.defaultTestLoader.discover( + os.path.dirname(module.__file__), + top_level_dir=os.path.dirname(__file__), + ) + + def _classes(s): + if isinstance(s, unittest.TestCase): + yield s.__class__ + else: + for t in s: + yield from _classes(t) + + return set(_classes(suite)) + def make_topics_doc(output_dir): @@ -117,13 +127,13 @@ def make_topics_doc(output_dir): test_classes = load_classes(source_module) # Strip out the conglomerator tests which are more complicated. - test_classes = [cls for cls in test_classes if hasattr(cls.context, 'msg')] + test_classes = [cls for cls in test_classes if hasattr(cls, 'msg')] write(fname, header) for cls in test_classes: - if cls.context.msg is not Unspecified: - cls.__topic = cls.context.msg['topic'].split('.', 1)[-1] + if cls.msg is not Unspecified: + cls.__topic = cls.msg['topic'].split('.', 1)[-1] else: cls.__topic = None @@ -131,7 +141,7 @@ def make_topics_doc(output_dir): seen = [] for cls in test_classes: - if cls.context.msg is not Unspecified: + if cls.msg is not Unspecified: topic = cls.__topic # You can also exclude a test from the docs with nodoc = True @@ -149,18 +159,15 @@ def make_topics_doc(output_dir): write(fname, "~" * len(topic)) write(fname) - # I would use __doc__ here, but something that nose is doing is - # stripping the __doc__ from my original unit tests. Instead, - # we'll use our own 'doc' attribute which is a little clumsy. - if getattr(cls.context, 'doc', None): - write(fname, textwrap.dedent(" " + cls.context.doc.strip())) + if cls.__doc__: + write(fname, textwrap.dedent(" " + cls.__doc__.strip())) write(fname) - write(fname, datagrepper_link(cls.context.msg['topic'])) + write(fname, datagrepper_link(cls.msg['topic'])) write(fname) write(fname, ".. code-block:: python") - write(fname, '\n ' + pprint.pformat(cls.context.msg, indent=2) + write(fname, '\n ' + pprint.pformat(cls.msg, indent=2) .replace('\n', '\n ')) write(fname) @@ -168,20 +175,20 @@ def make_topics_doc(output_dir): uid = str(uuid.uuid4()) icon_inline = Unspecified secondary_icon_inline = Unspecified - if cls.context.expected_icon is not Unspecified: + if cls.expected_icon is not Unspecified: icon_inline = "|%s-icon|" % uid - if cls.context.expected_secondary_icon is not Unspecified: + if cls.expected_secondary_icon is not Unspecified: secondary_icon_inline = "|%s-secondary_icon|" % uid # A bunch of data for the template. kwargs = dict( - link=cls.context.expected_link, - title=cls.context.expected_title, - subtitle=cls.context.expected_subti, - usernames=cls.context.expected_usernames, - agent=cls.context.expected_agent, - packages=cls.context.expected_packages, - objects=cls.context.expected_objects, + link=cls.expected_link, + title=cls.expected_title, + subtitle=cls.expected_subti, + usernames=cls.expected_usernames, + agent=cls.expected_agent, + packages=cls.expected_packages, + objects=cls.expected_objects, icon_inline=icon_inline, secondary_icon_inline=secondary_icon_inline, ) @@ -194,8 +201,8 @@ def length(value): longest = max([length(value) for value in kwargs.values()]) write(fname, metadata_template.render( - icon=cls.context.expected_icon, - secondary_icon=cls.context.expected_secondary_icon, + icon=cls.expected_icon, + secondary_icon=cls.expected_secondary_icon, Unspecified=Unspecified, longest=longest, **kwargs diff --git a/python-fedmsg-meta-umb.spec b/python-fedmsg-meta-umb.spec index 2ee94d7..e8b3125 100644 --- a/python-fedmsg-meta-umb.spec +++ b/python-fedmsg-meta-umb.spec @@ -12,7 +12,6 @@ Source0: %{srcname}-%{version}.tar.xz BuildArch: noarch BuildRequires: python3-devel -BuildRequires: python3-nose BuildRequires: python3-fedmsg BuildRequires: python3-mako BuildRequires: python3-cloud-sptheme diff --git a/setup.py b/setup.py index f6f0b4b..2469856 100755 --- a/setup.py +++ b/setup.py @@ -24,14 +24,9 @@ long_description = long_description.split('split here', 1)[1] f.close() -setup_requires = [ -] install_requires = [ 'fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop', ] -tests_require = [ - 'nose', -] entry_points = { 'fedmsg.meta': [ @@ -74,10 +69,7 @@ author_email='mikeb@redhat.com', url='https://github.com/release-engineering/fedmsg_meta_umb/', license='LGPLv2+', - setup_requires=setup_requires, install_requires=install_requires, - tests_require=tests_require, - test_suite='nose.collector', packages=find_packages(), include_package_data=True, zip_safe=False, diff --git a/tox.ini b/tox.ini index f3f0977..dcba247 100644 --- a/tox.ini +++ b/tox.ini @@ -5,10 +5,9 @@ downloadcache = {toxworkdir}/_download/ [testenv] deps = fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop - nose coverage commands = - nosetests {posargs} + python -m unittest {posargs} [testenv:flake8] deps= @@ -20,7 +19,6 @@ commands= [testenv:docs] deps = cloud_sptheme - nose fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop mako commands = From 84563ad2fe4951e75513d9238832cd48681c6e62 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Thu, 30 Nov 2023 15:36:48 -0800 Subject: [PATCH 3/5] actually report coverage --- .gitignore | 1 + tox.ini | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index db3f425..adc2d7a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ .eggs *.egg-info .tox +.coverage* htmldocs doc/topics.rst diff --git a/tox.ini b/tox.ini index dcba247..abc2cca 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,15 @@ deps = fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop coverage commands = - python -m unittest {posargs} + coverage run -m unittest {posargs} + coverage report + +[coverage:run] +branch = true + +[coverage:report] +show_missing = true +skip_empty = true [testenv:flake8] deps= From 490a0e29d7db0bd35b5bb335091bbfd7197b0ef9 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Thu, 30 Nov 2023 15:39:13 -0800 Subject: [PATCH 4/5] remove redundant dependency declarations --- tox.ini | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tox.ini b/tox.ini index abc2cca..868acd6 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,6 @@ downloadcache = {toxworkdir}/_download/ [testenv] deps = - fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop coverage commands = coverage run -m unittest {posargs} @@ -26,8 +25,6 @@ commands= [testenv:docs] deps = - cloud_sptheme - fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop - mako + -r doc/requirements.txt commands = sphinx-build doc/ htmldocs/ From 0f49e35f1d4f963ba312e827a01f436e748ebaf1 Mon Sep 17 00:00:00 2001 From: Mike Bonnet Date: Tue, 5 Dec 2023 08:39:08 -0800 Subject: [PATCH 5/5] skip install when running flake8 --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 868acd6..582a32e 100644 --- a/tox.ini +++ b/tox.ini @@ -17,6 +17,7 @@ show_missing = true skip_empty = true [testenv:flake8] +skip_install = true deps= flake8 commands=