jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/482404 )

Change subject: [tests] New uploadscript_tests
......................................................................

[tests] New uploadscript_tests

- make chunk_size_regex a global const to be imported by the test
- test the upload.get_chunk_size function and it's regex

Change-Id: Id9438b641288fd69088415fa48822a6f52186178
---
M scripts/upload.py
A tests/uploadscript_tests.py
2 files changed, 53 insertions(+), 4 deletions(-)

Approvals:
  Framawiki: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/upload.py b/scripts/upload.py
index 3750bb2..b5396b9 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -52,7 +52,7 @@
 """
 #
 # (C) Rob W.W. Hooft, Andre Engels 2003-2004
-# (C) Pywikibot team, 2003-2018
+# (C) Pywikibot team, 2003-2019
 #
 # Distributed under the terms of the MIT license.
 #
@@ -68,6 +68,10 @@
 from pywikibot.specialbots import UploadRobot


+CHUNK_SIZE_REGEX = re.compile(
+    r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$', re.I)
+
+
 def get_chunk_size(match):
     """Get chunk size."""
     if not match:
@@ -113,8 +117,6 @@
     aborts = set()
     ignorewarn = set()
     chunk_size = 0
-    chunk_size_regex = re.compile(
-        r'^-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?$', re.I)
     recursive = False
     description_file = None

@@ -150,7 +152,7 @@
             else:
                 ignorewarn = True
         elif arg == '-chunked':
-            match = chunk_size_regex.match(option)
+            match = CHUNK_SIZE_REGEX.match(option)
             chunk_size = get_chunk_size(match)
         elif arg == '-descfile':
             description_file = value
diff --git a/tests/uploadscript_tests.py b/tests/uploadscript_tests.py
new file mode 100644
index 0000000..e67b384
--- /dev/null
+++ b/tests/uploadscript_tests.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+"""upload.py script test."""
+#
+# (C) Pywikibot team, 2019
+#
+# Distributed under the terms of the MIT license.
+#
+from __future__ import absolute_import, division, unicode_literals
+
+from scripts.upload import CHUNK_SIZE_REGEX, get_chunk_size
+
+from tests.aspects import unittest, TestCase
+
+
+class TestUploadScript(TestCase):
+
+    """Test cases for upload."""
+
+    net = False
+
+    def match(self, value):
+        """Create a match object and call get_chunk_site.
+
+        @param value: a chunk size value
+        @type value: str
+        @return: chunk size in bytes
+        @rtype: int
+        """
+        option = '-chunked:' + value
+        match = CHUNK_SIZE_REGEX.match(option)
+        return get_chunk_size(match)
+
+    def test_regex(self):
+        """Test CHUNK_SIZE_REGEX and get_chunk_size function."""
+        self.assertEqual(self.match('12345'), 12345)
+        self.assertEqual(self.match('4567k'), 4567 * 1000)
+        self.assertEqual(self.match('7890m'), 7890 * 10 ** 6)
+        self.assertEqual(self.match('987ki'), 987 * 1024)
+        self.assertEqual(self.match('654mi'), 654 * 1024 ** 2)
+        self.assertEqual(self.match('3mike'), 0)
+
+
+if __name__ == '__main__':  # pragma: no cover
+    try:
+        unittest.main()
+    except SystemExit:
+        pass

--
To view, visit https://gerrit.wikimedia.org/r/482404
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id9438b641288fd69088415fa48822a6f52186178
Gerrit-Change-Number: 482404
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Framawiki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to