jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/511906 )
Change subject: [tests] Additional pwb.py tests ......................................................................
[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(-)
Approvals: Framawiki: Looks good to me, approved jenkins-bot: Verified
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)
pywikibot-commits@lists.wikimedia.org