Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/832746 )
Change subject: [tests] Add make_dist_tests.py to the framework ......................................................................
[tests] Add make_dist_tests.py to the framework
Change-Id: I6d61fd113b77e039ed5ee17cee7c6991cd7f82f2 --- M .codecov.yml M docs/tests_ref/index.rst A docs/tests_ref/make_dist_tests.rst M make_dist.py M tests/__init__.py A tests/make_dist_tests.py M tox.ini 7 files changed, 74 insertions(+), 7 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Verified; Looks good to me, approved
diff --git a/.codecov.yml b/.codecov.yml index af8ecaf..22f8396 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -18,7 +18,6 @@ enabled: yes
ignore: - - make_dist.py - pywikibot/backports.py - pywikibot/daemonize.py - pywikibot/families/__init__.py diff --git a/docs/tests_ref/index.rst b/docs/tests_ref/index.rst index 9f92532..c1eac79 100644 --- a/docs/tests_ref/index.rst +++ b/docs/tests_ref/index.rst @@ -106,6 +106,7 @@ generate_user_files<./generate_user_files_tests> harvest_template<./harvest_template_tests> interwikidata<./interwikidata_tests> + make_dist<./make_dist_tests> noreferences<./noreferences_tests> patrolbot<./patrolbot_tests> protectbot<./protectbot_tests> diff --git a/docs/tests_ref/make_dist_tests.rst b/docs/tests_ref/make_dist_tests.rst new file mode 100644 index 0000000..1cff28c --- /dev/null +++ b/docs/tests_ref/make_dist_tests.rst @@ -0,0 +1,7 @@ +tests.make_dist_tests module +============================== + +.. automodule:: tests.make_dist_tests + :members: + :undoc-members: + :show-inheritance: diff --git a/make_dist.py b/make_dist.py index 5b8af77..116e656 100644 --- a/make_dist.py +++ b/make_dist.py @@ -51,7 +51,7 @@ import setup
-def clear_old_dist() -> None: +def clear_old_dist() -> None: # pragma: no cover """Delete old dist folders.
.. versionadded:: 7.5 @@ -64,7 +64,7 @@ info('done')
-def copy_files() -> None: +def copy_files() -> None: # pragma: no cover """Copy code entry point and i18n files to pywikibot.scripts folder.
pwb.py wrapper script is a console script entry point for the @@ -92,7 +92,7 @@ info('done')
-def cleanup() -> None: +def cleanup() -> None: # pragma: no cover """Remove all files which were copied to the pywikibot scripts folder.""" info('Remove copied files... ', newline=False) folder = Path().resolve() @@ -103,7 +103,7 @@ info('done')
-def handle_args() -> Tuple[bool, bool]: +def handle_args() -> Tuple[bool, bool, bool, bool, bool]: """Handle arguments and print documentation if requested.
Read arguments from `sys.argv` and adjust it passing `sdist` to @@ -134,7 +134,7 @@ return local, remote, clear, upgrade, nodist
-def main() -> None: +def main() -> None: # pragma: no cover """Script entry point.""" local, remote, clear, upgrade, nodist = handle_args()
@@ -167,5 +167,5 @@ check_call('twine upload dist/*', shell=True)
-if __name__ == '__main__': +if __name__ == '__main__': # pragma: no cover main() diff --git a/tests/__init__.py b/tests/__init__.py index 87b0452..987ba55 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -153,6 +153,7 @@ 'harvest_template', 'interwikidata', 'l10n', + 'make_dist', 'patrolbot', 'protectbot', 'pwb', diff --git a/tests/make_dist_tests.py b/tests/make_dist_tests.py new file mode 100644 index 0000000..430cb9d --- /dev/null +++ b/tests/make_dist_tests.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +"""Tests for fixes module.""" +# +# (C) Pywikibot team, 2022 +# +# Distributed under the terms of the MIT license. +# +import os +import sys +import unittest + +from pywikibot import __version__ +from make_dist import handle_args + +from tests.aspects import TestCase + + +class TestMakeDist(TestCase): + + """Test the make_dist script.""" + + net = False + + def _test_argv(self): + """Test argv.""" + if os.environ.get('PYWIKIBOT_TEST_RUNNING', '0') != '1': + self.assertEqual(__file__, sys.argv[0]) + self.assertIn('sdist', sys.argv) + self.assertIn('bdist_wheel', sys.argv) + + def test_handle_args_empty(self): + """Test make_dist handle_args function.""" + args = handle_args() + self.assertEqual(args, (False, ) * 5) + self._test_argv() + + def test_handle_args_nodist(self): + """Test make_dist handle_args function.""" + sys.argv += ['-local', '-nodist', '-remote'] + *args, nodist = handle_args() + self.assertEqual(args, [False] * 4) + self.assertTrue(nodist) + self._test_argv() + + def test_handle_args(self): + """Test make_dist handle_args function.""" + sys.argv += ['-clear', '-local', '-remote', '-upgrade'] + local, remote, clear, upgrade, nodist = handle_args() + self.assertTrue(local) + self.assertEqual(remote, 'dev' not in __version__) + self.assertTrue(clear) + self.assertTrue(upgrade) + self.assertFalse(nodist) + self._test_argv() + + +if __name__ == '__main__': # pragma: no cover + unittest.main() diff --git a/tox.ini b/tox.ini index bd09bf3..f852f3e 100644 --- a/tox.ini +++ b/tox.ini @@ -21,6 +21,7 @@ setenv = VIRTUAL_ENV={envdir} PYWIKIBOT_NO_USER_CONFIG=2 + PYWIKIBOT_TEST_RUNNING=1 usedevelop = True commands = flake8: flake8 --version