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(
pywikibot-commits@lists.wikimedia.org