jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/993218?usp=email )
Change subject: [tests] Add setup_tests.py ......................................................................
[tests] Add setup_tests.py
Change-Id: Iebaebe2757ae0797b4347f04efdfdb03c6a32f56 --- M docs/tests_ref/index.rst A docs/tests_ref/setup_tests.rst M setup.py A tests/setup_tests.py 4 files changed, 92 insertions(+), 8 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/docs/tests_ref/index.rst b/docs/tests_ref/index.rst index cfa85bc..7340817 100644 --- a/docs/tests_ref/index.rst +++ b/docs/tests_ref/index.rst @@ -112,6 +112,7 @@ protectbot<./protectbot_tests> pwb<./pwb_tests> script<./script_tests> + setup<./setup_tests> redirect_bot<./redirect_bot_tests> reflinks<./reflinks_tests> replacebot<./replacebot_tests> diff --git a/docs/tests_ref/setup_tests.rst b/docs/tests_ref/setup_tests.rst new file mode 100644 index 0000000..0f91e3d --- /dev/null +++ b/docs/tests_ref/setup_tests.rst @@ -0,0 +1,8 @@ +************************* +tests.setup_tests module +************************* + +.. automodule:: tests.setup_tests + :members: + :undoc-members: + :show-inheritance: diff --git a/setup.py b/setup.py index fd8bd4b..6be3e15 100755 --- a/setup.py +++ b/setup.py @@ -29,6 +29,7 @@ import os import re import sys +from contextlib import suppress
if sys.version_info[:3] >= (3, 9): @@ -135,7 +136,7 @@ """ version = metadata.__version__ if 'sdist' not in sys.argv: - return version # pragma: no cover + return version
# validate version for sdist from contextlib import suppress @@ -146,12 +147,12 @@ try: tags = run(['git', 'tag'], check=True, stdout=PIPE, universal_newlines=True).stdout.splitlines() - except Exception as e: # pragma: no cover + except Exception as e: print(e) sys.exit('Creating source distribution canceled.')
last_tag = None - if tags: # pragma: no cover + if tags: for tag in ('stable', 'python2'): with suppress(ValueError): tags.remove(tag) @@ -161,16 +162,16 @@ warning = '' try: vrsn = Version(version) - except InvalidVersion: # pragma: no cover + except InvalidVersion: warning = f'{version} is not a valid version string following PEP 440.' else: if last_tag and vrsn <= Version(last_tag): - warning = ( # pragma: no cover + warning = ( f'New version {version!r} is not higher than last version ' f'{last_tag!r}.' )
- if warning: # pragma: no cover + if warning: print(__doc__) print('\n\n{warning}') sys.exit('\nBuild of distribution package canceled.') @@ -200,7 +201,7 @@ return ''.join(desc)
-def get_packages(name) -> List[str]: +def get_packages(name: str) -> List[str]: """Find framework packages.""" try: from setuptools import find_namespace_packages @@ -208,10 +209,12 @@ sys.exit( 'setuptools >= 40.1.0 is required to create a new distribution.') packages = find_namespace_packages(include=[name + '.*']) + with suppress(ValueError): + packages.remove(name + '.apicache-py3') return [str(name)] + packages
-def main() -> None: +def main() -> None: # pragma: no cover """Setup entry point.""" from setuptools import setup
diff --git a/tests/setup_tests.py b/tests/setup_tests.py new file mode 100644 index 0000000..d03ede0 --- /dev/null +++ b/tests/setup_tests.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +"""Test setup.py. + +.. versionadded:: 9.0 +""" +# +# (C) Pywikibot team, 2024 +# +# Distributed under the terms of the MIT license. +# +from __future__ import annotations + +import unittest + +import pywikibot +import setup + +from tests.aspects import TestCase + + +class TestSetup(TestCase): + + """Test setup.py functions.""" + + site = False + net = False + + def test_get_validated_version(self): + """Test :func:`setup.get_validated_version` function.""" + self.assertEqual(setup.get_validated_version(), pywikibot.__version__) + + def test_read_desc(self): + """Test :func:`setup.read_desc` function.""" + desc = setup.read_desc('README.rst') + coc = setup.read_desc('CODE_OF_CONDUCT.rst') + self.assertIn(coc, desc) + + def test_get_pywikibot_packages(self): + """Test :func:`setup.get_packages` function for pywikibot.""" + name = 'pywikibot' + packages = setup.get_packages(name) + self.assertEqual(packages[0], name) + self.assertIn(name + '.scripts', packages) + self.assertLength(packages, 14) + + def test_get_tests_packages(self): + """Test :func:`setup.get_packages` function for tests.""" + name = 'tests' + packages = setup.get_packages(name) + self.assertEqual(packages[0], name) + self.assertIn(name + '.data', packages) + self.assertLength(packages, 10) + + def test_get_scripts_packages(self): + """Test :func:`setup.get_packages` function for scripts.""" + name = 'scripts' + packages = setup.get_packages(name) + self.assertEqual(packages[0], name) + self.assertIn(name + '.userscripts', packages) + + +if __name__ == '__main__': # pragma: no cover + unittest.main()
pywikibot-commits@lists.wikimedia.org