jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/767464 )
Change subject: [cleanup] Remove unused tests parts
......................................................................
[cleanup] Remove unused tests parts
- remove unused bot_tests.FakeSaveBotTestCase
- remove unused tests/i18n/pywikibot.py
- remove api_tests.TestBadTokenRecovery because not test is made and no
log is written due to this test
Change-Id: I316224f415c97928d6485f007ecee54f75c99d64
---
M tests/api_tests.py
M tests/bot_tests.py
D tests/i18n/pywikibot.py
3 files changed, 0 insertions(+), 100 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 6d6447d..f9d22c5 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -900,25 +900,6 @@
'You have no API read permissions. Seems you are not logged in.')
-class TestBadTokenRecovery(TestCase):
-
- """Test that the request recovers from bad tokens."""
-
- family = 'wikipedia'
- code = 'test'
-
- write = True
-
- def test_bad_token(self):
- """Test the bad token recovery by corrupting the cache."""
- site = self.get_site()
- site.tokens._tokens.setdefault(site.user(), {})['edit'] = 'INVALID'
- page = pywikibot.Page(site, 'Pywikibot bad token test')
- page.text = ('This page is testing whether pywikibot rerequests '
- 'a token when a badtoken error was received.')
- page.save(summary='Bad token test')
-
-
class TestUrlEncoding(TestCase):
"""Test encode_url() function."""
diff --git a/tests/bot_tests.py b/tests/bot_tests.py
index c06cee0..12c89de 100644
--- a/tests/bot_tests.py
+++ b/tests/bot_tests.py
@@ -32,80 +32,6 @@
super().setUpClass()
-class FakeSaveBotTestCase(TestCase):
-
- """
- An abstract test case which patches the bot class to not actually write.
-
- It redirects the bot's _save_page to it's own ``bot_save`` method.
- Currently userPut, put_current and user_edit_entity call it. By
- default it'll call the original method but replace the function
- called to actually save the page by ``page_save``. It patches the
- bot class as soon as this class' attribute bot is defined. It also
- sets the bot's 'always' option to True to avoid user interaction.
-
- The ``bot_save`` method compares the save counter before the call and
- asserts that it has increased by one after the call. It also stores
- locally in ``save_called`` if ``page_save`` has been called. If
- ``bot_save`` or ``page_save`` are implemented they should call
- super's method at some point to make sure these assertions work. At
- ``tearDown`` it checks that the pages are saved often enough. The
- attribute ``default_assert_saves`` defines the number of saves which
- must happen and compares it to the difference using the save counter.
- It is possible to define ``assert_saves`` after ``setUp`` to
- overwrite the default value for certain tests. By default the number
- of saves it asserts are 1. Additionally ``save_called`` increases by
- 1 on each call of ``page_save`` and should be equal to
- ``assert_saves``.
-
- This means if the bot class actually does other writes, like using
- :py:obj:`pywikibot.page.Page.save` manually, it'll still write.
- """
-
- @property
- def bot(self):
- """Get the current bot."""
- return self._bot
-
- @bot.setter
- def bot(self, value):
- """Set and patch the current bot."""
- assert value._save_page != self.bot_save, 'bot may not be patched.'
- self._bot = value
- self._bot.opt.always = True
- self._original = self._bot._save_page
- self._bot._save_page = self.bot_save
- self._old_counter = self._bot.counter['write']
-
- def setUp(self):
- """Set up test by resetting the counters."""
- super().setUp()
- self.assert_saves = getattr(self, 'default_assert_saves', 1)
- self.save_called = 0
-
- def tearDown(self):
- """Tear down by asserting the counters."""
- self.assertEqual(self._bot.counter['write'],
- self._old_counter + self.assert_saves)
- self.assertEqual(self.save_called, self.assert_saves)
- super().tearDown()
-
- def bot_save(self, page, func, *args, **kwargs):
- """Handle when bot's userPut was called."""
- self.assertGreaterEqual(self._bot.counter['write'], 0)
- old_counter = self._bot.counter['write']
- old_local_cnt = self.save_called
- result = self._original(page, self.page_save, *args, **kwargs)
- self.assertEqual(self._bot.counter['write'], old_counter + 1)
- self.assertEqual(self.save_called, old_local_cnt + 1)
- self.assertGreater(self._bot.counter['write'], self._old_counter)
- return result
-
- def page_save(self, *args, **kwargs):
- """Handle when bot calls the page's save method."""
- self.save_called += 1
-
-
class TestBotTreatExit:
"""Mixin to provide handling for treat and exit."""
diff --git a/tests/i18n/pywikibot.py b/tests/i18n/pywikibot.py
deleted file mode 100644
index 8fc88bf..0000000
--- a/tests/i18n/pywikibot.py
+++ /dev/null
@@ -1,7 +0,0 @@
-"""i18n message bundle called 'pywikibot' to fool the i18n loader."""
-#
-# (C) Pywikibot team, 2014-2020
-#
-# Distributed under the terms of the MIT license.
-#
-msg = {}
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/767464
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I316224f415c97928d6485f007ecee54f75c99d64
Gerrit-Change-Number: 767464
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
Xqt has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/767225 )
Change subject: [tests] ignore code parts from coverage
......................................................................
[tests] ignore code parts from coverage
- ignore some exceptions
- ignore setup.main() which cannot be tested
- ignore some pwb.py parts
Change-Id: Ic6f310c0b0ef9f9a95935c0154ecf2c38887a88d
---
M .coveragerc
M pwb.py
M setup.py
3 files changed, 21 insertions(+), 16 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/.coveragerc b/.coveragerc
index d97beb0..7a11b16 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -5,6 +5,10 @@
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
+ except ImportError
+ except KeyboardInterrupt
+ except pkg_resources
+ except SyntaxError
raise NotImplementedError
raise unittest\.SkipTest
if .PYWIKIBOT_TEST_.*. in os.environ:
diff --git a/pwb.py b/pwb.py
index fd1ae8a..94b567e 100755
--- a/pwb.py
+++ b/pwb.py
@@ -73,7 +73,7 @@
scripts_version = Version(getattr(package, '__version__', pwb.__version__))
wikibot_version = Version(pwb.__version__)
- if scripts_version.release > wikibot_version.release:
+ if scripts_version.release > wikibot_version.release: # pragma: no cover
print('WARNING: Pywikibot version {} is behind scripts package '
'version {}.\nYour Pywikibot may need an update or be '
'misconfigured.\n'.format(wikibot_version, scripts_version))
@@ -84,12 +84,12 @@
.format(wikibot_version.minor - 1,
v=wikibot_version))
- if scripts_version.release < prev_wikibot.release:
+ if scripts_version.release < prev_wikibot.release: # pragma: no cover
print('WARNING: Scripts package version {} is behind legacy '
'Pywikibot version {} and current version {}\nYour scripts '
'may need an update or be misconfigured.\n'
.format(scripts_version, prev_wikibot, wikibot_version))
- elif scripts_version.release < wikibot_version.release:
+ elif scripts_version.release < wikibot_version.release: # pragma: no cover
print('WARNING: Scripts package version {} is behind current version '
'{}\nYour scripts may need an update or be misconfigured.\n'
.format(scripts_version, wikibot_version))
@@ -185,7 +185,7 @@
return fname, list(args[index + int(bool(fname)):]), args[:index]
-def _print_requirements(requirements, script, variant):
+def _print_requirements(requirements, script, variant): # pragma: no cover
"""Print pip command to install requirements."""
if not requirements:
return
@@ -227,7 +227,7 @@
from setup import dependencies
try:
next(pkg_resources.parse_requirements(dependencies))
- except ValueError as e:
+ except ValueError as e: # pragma: no cover
# T286980: setuptools is too old and requirement parsing fails
import setuptools
setupversion = tuple(int(num)
@@ -259,7 +259,7 @@
_print_requirements(missing_requirements, script, 'missing')
_print_requirements(version_conflicts, script, 'outdated')
- if version_conflicts and not missing_requirements:
+ if version_conflicts and not missing_requirements: # pragma: no cover
print('\nYou may continue on your own risk; type CTRL-C to stop.')
try:
sleep(5)
@@ -279,7 +279,7 @@
os.environ['PYWIKIBOT_DIR_PWB'] = _pwb_dir
try:
import pywikibot as pwb
-except RuntimeError:
+except RuntimeError: # pragma: no cover
os.environ['PYWIKIBOT_NO_USER_CONFIG'] = '2'
import pywikibot as pwb
@@ -350,7 +350,7 @@
alternatives, default='1')
except QuitKeyboardInterrupt:
return None
- print()
+ print() # pragma: no cover
return str(scripts[script])
@@ -374,7 +374,7 @@
path_list.append(package)
return None
- if site_package:
+ if site_package: # pragma: no cover
script_paths = [_pwb_dir]
else:
script_paths = [
@@ -385,7 +385,7 @@
]
user_script_paths = []
- if config.user_script_paths:
+ if config.user_script_paths: # pragma: no cover
if isinstance(config.user_script_paths, list):
user_script_paths = config.user_script_paths
else:
@@ -394,7 +394,7 @@
.format(type(config.user_script_paths)))
found = test_paths(user_script_paths, config.base_dir)
- if found:
+ if found: # pragma: no cover
return found
found = test_paths(script_paths, _pwb_dir)
@@ -414,7 +414,7 @@
if global_args: # don't use sys.argv
unknown_args = pwb.handle_args(global_args)
- if unknown_args:
+ if unknown_args: # pragma: no cover
print('ERROR: unknown pwb.py argument{}: {}\n'
.format('' if len(unknown_args) == 1 else 's',
', '.join(unknown_args)))
@@ -471,16 +471,17 @@
previous implementation was renamed to :func:`execute`
"""
try:
- if not check_modules():
+ if not check_modules(): # pragma: no cover
raise RuntimeError('') # no further output needed
- except RuntimeError as e: # setup.py may also raise RuntimeError
+ # setup.py may also raise RuntimeError
+ except RuntimeError as e: # pragma: no cover
sys.exit(e)
if not execute():
print(__doc__)
-def run():
+def run(): # pragma: no cover
"""Site package entry point. Print doc if necessary.
.. versionadded:: 7.0
diff --git a/setup.py b/setup.py
index 45bf661..76a83e6 100644
--- a/setup.py
+++ b/setup.py
@@ -243,7 +243,7 @@
return [str(name)] + packages
-def main():
+def main(): # pragma: no cover
"""Setup entry point."""
version = get_validated_version()
setup(
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/767225
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ic6f310c0b0ef9f9a95935c0154ecf2c38887a88d
Gerrit-Change-Number: 767225
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-MessageType: merged