Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1049191?usp=email )

Change subject: [make_dist] additional tests for make_dist.py
......................................................................

[make_dist] additional tests for make_dist.py

also update coverage.

Change-Id: Ifb12cec13ce6f61f021df3818a2f71b3554e58f0
---
M make_dist.py
M tests/make_dist_tests.py
2 files changed, 29 insertions(+), 12 deletions(-)

Approvals:
  Xqt: Verified; Looks good to me, approved




diff --git a/make_dist.py b/make_dist.py
index cc498e2..2c0ca36 100755
--- a/make_dist.py
+++ b/make_dist.py
@@ -109,7 +109,7 @@
         if self.local or self.remote or self.clear:
             self.clear_old_dist()
             if self.clear:
-                return True  # pragma: no cover
+                return True

         if self.upgrade:  # pragma: no cover
             check_call('python -m pip install --upgrade pip', shell=True)
@@ -125,16 +125,22 @@
             for module in ('build', 'twine'):
                 try:
                     import_module(module)
-                except ModuleNotFoundError as e:  # pragma: no cover
+                except ModuleNotFoundError as e:
                     error(f'<<lightred>>{e}')
                     info('<<lightblue>>You may use -upgrade option to install')
                     return False
+        return self.build()  # pragma: no cover

+    def build(self) -> bool:  # pragma: no cover
+        """Build the packages.
+
+        .. versionadded:: 9.3
+        """
         self.copy_files()
         info('<<lightyellow>>Build package')
         try:
             check_call('python -m build')
-        except Exception as e:  # pragma: no cover
+        except Exception as e:
             error(e)
             return False
         finally:
@@ -142,7 +148,7 @@

         info('<<lightyellow>>Check package and description')
         if run('twine check dist/*', shell=True).returncode:
-            return False  # pragma: no cover
+            return False

         if self.local:
             info('<<lightyellow>>Install locally')
@@ -153,7 +159,7 @@

         if self.remote and input_yn(
                 '<<lightblue>>Upload dist to pypi', automatic_quit=False):
-            check_call('twine upload dist/*', shell=True)  # pragma: no cover
+            check_call('twine upload dist/*', shell=True)
         return True


@@ -172,7 +178,7 @@
         self.target = target
         self.source = source

-    def copy_files(self) -> None:
+    def copy_files(self) -> None:  # pragma: no cover
         """Copy i18n files to pywikibot.scripts folder.

         Pywikibot i18n files are used for some translations. They are copied
@@ -186,7 +192,7 @@
         shutil.copytree(self.source, self.target)
         info('done')

-    def cleanup(self) -> None:
+    def cleanup(self) -> None:  # pragma: no cover
         """Remove all copied files from pywikibot scripts folder."""
         info('<<lightyellow>>Remove copied files... ', newline=False)
         shutil.rmtree(self.target)
diff --git a/tests/make_dist_tests.py b/tests/make_dist_tests.py
index 26d498f..699c666 100755
--- a/tests/make_dist_tests.py
+++ b/tests/make_dist_tests.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 """Tests for fixes module."""
 #
-# (C) Pywikibot team, 2022-2023
+# (C) Pywikibot team, 2022-2024
 #
 # Distributed under the terms of the MIT license.
 #
@@ -10,6 +10,7 @@
 import sys
 import unittest

+import make_dist
 from pywikibot import __version__
 from tests.aspects import TestCase

@@ -22,20 +23,30 @@

     def test_handle_args_empty(self):
         """Test make_dist handle_args function."""
-        from make_dist import handle_args
-        args = handle_args()
+        args = make_dist.handle_args()
         self.assertEqual(args, (False, ) * 4)

     def test_handle_args(self):
         """Test make_dist handle_args function."""
-        from make_dist import handle_args
         sys.argv += ['-clear', '-local', '-remote', '-upgrade']
-        local, remote, clear, upgrade = handle_args()
+        local, remote, clear, upgrade = make_dist.handle_args()
         self.assertTrue(local)
         self.assertEqual(remote, 'dev' not in __version__)
         self.assertTrue(clear)
         self.assertTrue(upgrade)

+    def test_main(self):
+        """Test main result."""
+        saved_argv = sys.argv
+        sys.argv = saved_argv + ['-clear']
+        self.assertTrue(make_dist.main())
+
+        # no build or twine modules
+        self.assertFalse(make_dist.main())
+        sys.argv = saved_argv + ['-local']
+        self.assertFalse(make_dist.main())
+        sys.argv = saved_argv
+

 if __name__ == '__main__':
     unittest.main()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1049191?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ifb12cec13ce6f61f021df3818a2f71b3554e58f0
Gerrit-Change-Number: 1049191
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to