Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326009?usp=email )
Change subject: tests: Test pwb alternate selection directly
......................................................................
tests: Test pwb alternate selection directly
Call find_alternates directly and mock its configured delay. This avoids the
five-second wait, subprocess startup, and unintended shell invocation.
The test no longer exercises the subprocess path from T413711, so it can run
on GraalPy.
Bug: T434934
Change-Id: I6938437d3cffb338d2a0ed90204a2fd1e64bb6d6
---
M tests/pwb_tests.py
1 file changed, 23 insertions(+), 17 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index c0eae35..b094eef 100755
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -10,8 +10,13 @@
import io
import sys
import unittest
+from pathlib import Path
from platform import python_implementation
+from unittest.mock import patch
+import pywikibot
+from pywikibot import config
+from pywikibot.scripts import wrapper
from tests import create_path_func, join_tests_path
from tests.aspects import PwbTestCase
from tests.utils import execute, execute_pwb
@@ -106,26 +111,27 @@
self.assertEqual(stderr.readline().strip(),
'ERROR: pywikibot.py not found! Misspelling?')
- @unittest.skipIf(python_implementation() == 'GraalVM', reason='T413711')
def test_one_similar_script(self) -> None:
"""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=12)
+ wait_time = config.pwb_autostart_waittime
+ scripts_path = Path(wrapper.__file__).parent
+ shell_path = scripts_path / 'shell.py'
- 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=f'"{text}" does not start with "{result[1]}"')
- with self.subTest(line=2):
- self.assertEqual(stderr.readline().strip(), result[2])
+ with (
+ patch.object(pywikibot, 'error') as error,
+ patch.object(pywikibot, 'info') as info,
+ patch.object(wrapper, 'sleep') as sleep,
+ ):
+ filename = wrapper.find_alternates('hello.py', [scripts_path])
+
+ self.assertEqual(filename, str(shell_path))
+ error.assert_called_once_with('hello.py not found! Misspelling?')
+ info.assert_called_once_with(
+ 'NOTE: Starting the most similar script '
+ '<<lightyellow>>shell.py<<default>>\n'
+ f' in {wait_time} seconds; type CTRL-C to stop.'
+ )
+ sleep.assert_called_once_with(wait_time)
@unittest.skipIf(python_implementation() == 'GraalVM', reason='T413711')
def test_similar_scripts_found(self) -> None:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1326009?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: I6938437d3cffb338d2a0ed90204a2fd1e64bb6d6
Gerrit-Change-Number: 1326009
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[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]