jenkins-bot merged this change.

View Change

Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
[tests] Additional pwb.py tests

Test selection of similar scripts

Change-Id: I08462df62401b6dbfe224ef9bda405732d6716d8
---
M tests/pwb_tests.py
1 file changed, 48 insertions(+), 0 deletions(-)

diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index cabc3c1..5cba20b 100644
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -13,6 +13,7 @@
#
from __future__ import absolute_import, division, unicode_literals

+import io
import sys

from tests import join_tests_path, create_path_func
@@ -75,6 +76,53 @@
self.assertEqual('Häuser', vpwb['stdout'].strip())
self.assertEqual('Häuser', vpwb['stderr'].strip())

+ def test_script_found(self):
+ """Test pwb.py script call which is found."""
+ stdout = io.StringIO(execute_pwb(['pwb'])['stdout'])
+ self.assertEqual(
+ stdout.readline().strip(),
+ "Wrapper script to use Pywikibot in 'directory' mode.")
+
+ def test_script_not_found(self):
+ """Test pwbot.py script call which is not found."""
+ stderr = io.StringIO(execute_pwb(['pywikibot'])['stderr'])
+ self.assertEqual(stderr.readline().strip(),
+ 'ERROR: pywikibot.py not found! Misspelling?')
+
+ def test_one_similar_script(self):
+ """Test shell.py script call which gives one similar result."""
+ result = [
+ 'ERROR: hello.py not found! Misspelling?',
+ 'NOTE: Starting the most similar script shell.py',
+ 'in 5.0 seconds; type CTRL-C to stop.',
+ ]
+ stream = execute_pwb(['hello'], data_in=chr(3), timeout=6)
+ stderr = io.StringIO(stream['stderr'])
+ with self.subTest(line=0):
+ self.assertEqual(stderr.readline().strip(), result[0])
+ with self.subTest(line=1):
+ text = stderr.readline().strip()
+ self.assertTrue(
+ text.startswith(result[1]),
+ msg='"{}" does not start with "{}"'.format(text, result[1]))
+ with self.subTest(line=2):
+ self.assertEqual(stderr.readline().strip(), result[2])
+
+ def test_similar_scripts_found(self):
+ """Test script call which gives multiple similar results."""
+ result = [
+ 'ERROR: commons.py not found! Misspelling?',
+ '',
+ 'The most similar scripts are:',
+ '1 - nowcommons',
+ '2 - commonscat',
+ '3 - commons_link',
+ ]
+ stderr = io.StringIO(execute_pwb(['commons'], data_in='q')['stderr'])
+ for line in range(6):
+ with self.subTest(line=line):
+ self.assertEqual(stderr.readline().strip(), result[line])
+

if __name__ == '__main__': # pragma: no cover
unittest.main(verbosity=10)

To view, visit change 511906. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I08462df62401b6dbfe224ef9bda405732d6716d8
Gerrit-Change-Number: 511906
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)