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/doc/requirements.txt b/doc/requirements.txt index c67f31f..9b3e8fc 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,4 +1,3 @@ cloud_sptheme -nose -fedmsg +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 582a204..2469856 100755 --- a/setup.py +++ b/setup.py @@ -24,13 +24,8 @@ long_description = long_description.split('split here', 1)[1] f.close() -setup_requires = [ -] install_requires = [ - 'fedmsg', -] -tests_require = [ - 'nose', + 'fedmsg @ git+https://github.com/fedora-infra/fedmsg.git@develop', ] entry_points = { @@ -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 0e16179..582a32e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,16 +1,23 @@ [tox] -envlist = flake8,py{38,39},docs +envlist = flake8,py312,docs downloadcache = {toxworkdir}/_download/ [testenv] deps = - fedmsg - nose coverage commands = - nosetests {posargs} + coverage run -m unittest {posargs} + coverage report + +[coverage:run] +branch = true + +[coverage:report] +show_missing = true +skip_empty = true [testenv:flake8] +skip_install = true deps= flake8 commands= @@ -19,9 +26,6 @@ commands= [testenv:docs] deps = - cloud_sptheme - nose - fedmsg - mako + -r doc/requirements.txt commands = sphinx-build doc/ htmldocs/