Commit fa8231c7 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov
Browse files

Merge branch 'noc-test-empty-module-docstrings' into 'master'

test: Report empty module's docstrings

See merge request noc/noc!1910
parents abdbbc13 b23f74bf
......@@ -21,7 +21,6 @@ contrib/share/*
!/.gitignore
!/.dockerignore
!/.gitlab-ci.yml
!/.gitignore
!/.flake8
!/.pylintrc
!/.coveragerc
......
......@@ -134,6 +134,9 @@ class Command(BaseCommand):
n_skipped = len(stats.get("skipped", []))
n_error = len(stats.get("error", []))
n_failed = len(stats.get("failed", []))
n_xfailed = len(stats.get("xfailed", []))
n_xpassed = len(stats.get("xpassed", []))
n_warnings = len(stats.get("warnings", []))
if n_error or n_failed:
status = "Failed"
else:
......@@ -143,6 +146,9 @@ class Command(BaseCommand):
self.print("Tests Skipped: : %s" % n_skipped)
self.print("Tests Failed: : %s" % n_failed)
self.print("Tests Error: : %s" % n_error)
self.print("Tests XFailed : %s" % n_xfailed)
self.print("Tests XPassed : %s" % n_xpassed)
self.print("Tests Warnings : %s" % n_warnings)
self.print("Coverage : %d%%" % totals.pc_covered)
self.print("Coverage Statements : %s" % totals.n_statements)
self.print("Coverage Missing : %s" % totals.n_missing)
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# TileCache updater
# ---------------------------------------------------------------------
# Copyright (C) 2007-2012 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -13,18 +13,13 @@ import threading
import Queue
import time
import datetime
# Third-party modules
import mapnik2
# NOC modules
from noc.settings import IS_TEST
from noc.config import config
from noc.gis.models import TileCache, Area
from noc.gis.mapxml import map_to_xml
from noc.gis.geo import xy_to_ll, ll_to_xy, TS, MIN_ZOOM, MAX_ZOOM
# Third-party modules
try:
import mapnik2
except ImportError, why:
if not IS_TEST:
raise ImportError(*why)
# Render additional N tiles around areas
......
......@@ -2,7 +2,7 @@
# ---------------------------------------------------------------------
# Test python module loading
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
......@@ -12,27 +12,39 @@ import os
import ast
# Third-party modules
import pytest
import cachetools
_ls_data = None
ALLOW_XFAIL = {
"noc.services.login.backends.pam",
"noc.services.web.apps.kb.parsers.mediawiki",
"noc.services.classifier.xrulelookup",
"noc.commands.translation",
"noc.scripts.build-pop-links",
"noc.scripts.build-models",
"noc.scripts.build.compile-handlebars",
"noc.scripts.check-db",
"noc.scripts.paste",
"noc.scripts.migrate-ignored-interfaces",
"noc.gis.parsers.address.fias",
"noc.gis.tile"
}
def _git_ls():
global _ls_data
if _ls_data is not None:
return _ls_data
@cachetools.cached(cache={})
def get_files():
try:
data = subprocess.check_output(["git", "ls-tree", "HEAD", "-r", "--name-only"])
_ls_data = data.splitlines()
except OSError:
# No git
_ls_data = []
return _ls_data
return data.splitlines()
except (OSError, subprocess.CalledProcessError):
# No git, emulate
data = subprocess.check_output(["find", ".", "-type", "f", "-print"])
return [p[2:] for p in data.splitlines()]
@cachetools.cached(cache={})
def get_py_modules_list():
result = []
for path in _git_ls():
for path in get_files():
if path.startswith(".") or not path.endswith(".py"):
continue
parts = path.split(os.sep)
......@@ -51,23 +63,35 @@ def get_py_modules_list():
return result
@pytest.fixture(scope="module", params=get_py_modules_list())
def py_module(request):
return request.param
def test_import(py_module):
m = __import__(py_module, {}, {}, "*")
assert m
@pytest.mark.parametrize("module", get_py_modules_list())
def test_import(module):
try:
m = __import__(module, {}, {}, "*")
assert m
except ImportError as e:
if module in ALLOW_XFAIL:
pytest.xfail(str(e))
else:
pytest.fail(str(e))
@pytest.fixture(scope="module", params=[f for f in _git_ls() if f.endswith("__init__.py")])
def py_init(request):
return request.param
@pytest.mark.parametrize("module", get_py_modules_list())
def test_module_empty_docstrings(module):
try:
m = __import__(module, {}, {}, "*")
if m.__doc__ is not None and not m.__doc__.strip():
# assert m.__doc__.strip(), "Module-level docstring must not be empty"
pytest.xfail("Module-level docstring must not be empty")
except ImportError as e:
if module in ALLOW_XFAIL:
pytest.xfail(str(e))
else:
pytest.fail(str(e))
def test_init(py_init):
with open(py_init) as f:
@pytest.mark.parametrize("path", [f for f in get_files() if f.endswith("__init__.py")])
def test_init(path):
with open(path) as f:
data = f.read()
n = compile(data, py_init, "exec", ast.PyCF_ONLY_AST)
n = compile(data, path, "exec", ast.PyCF_ONLY_AST)
assert bool(n.body) or not bool(data), "__init__.py must be empty"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment