jenkins-bot submitted this change.

View Change

Approvals: Zoranzoki21: Looks good to me, but someone else must approve Matěj Suchánek: Looks good to me, approved jenkins-bot: Verified
[IMPR] Leave the script gracefully for wrong -lang and -family option

- If the site given by -lang and -family option does not exists
show an error message and leave immediately, instead of printing
a full traceback after the script has started.
- Update script_tests.py to that pywikibot.Site is a function instead
of None.

Bug: T259756
Change-Id: I7474b6776625b45ccda07305d70764f8aefa6c05
---
M pywikibot/bot.py
M tests/script_tests.py
2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 7e01efe..dad67ad 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -113,9 +113,8 @@
ChoiceException, QuitKeyboardInterrupt,
Choice, StaticChoice, LinkChoice, AlwaysChoice
)
-from pywikibot.logging import (
- CRITICAL, ERROR, INFO, WARNING,
-)
+from pywikibot.exceptions import UnknownFamily, UnknownSite
+from pywikibot.logging import CRITICAL, ERROR, INFO, WARNING
from pywikibot.logging import DEBUG, INPUT, STDOUT, VERBOSE
from pywikibot.logging import (
add_init_routine,
@@ -875,6 +874,12 @@
# argument not global -> specific bot script will take care
non_global_args.append(arg)

+ try:
+ pywikibot.Site()
+ except (UnknownFamily, UnknownSite):
+ pywikibot.exception()
+ sys.exit(1)
+
if username:
config.usernames[config.family][config.mylang] = username

diff --git a/tests/script_tests.py b/tests/script_tests.py
index 8e64326..61c996a 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -228,7 +228,7 @@

test_overrides = {}
if not hasattr(self, 'net') or not self.net:
- test_overrides['pywikibot.Site'] = 'None'
+ test_overrides['pywikibot.Site'] = 'lambda *a, **k: None'

# run the script
result = execute_pwb(cmd, data_in, timeout=timeout,

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7474b6776625b45ccda07305d70764f8aefa6c05
Gerrit-Change-Number: 618702
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444@gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged