Пример #1
0
    def test_exception(self):
        # Python 2.3's trace function doesn't get called with "return" if the
        # scope is exiting due to an exception.  This confounds our trace
        # function which relies on scope announcements to track which files to
        # trace.
        #
        # This test is designed to sniff this out.  Each function in the call
        # stack is in a different file, to try to trip up the tracer.  Each
        # file has active lines in a different range so we'll see if the lines
        # get attributed to the wrong file.

        self.make_file(
            "oops.py", """\
            def oops(args):
                a = 2
                raise Exception("oops")
                a = 4
            """)

        self.make_file(
            "fly.py", "\n" * 100 + """\
            def fly(calls):
                a = 2
                calls[0](calls[1:])
                a = 4
            """)

        self.make_file(
            "catch.py", "\n" * 200 + """\
            def catch(calls):
                try:
                    a = 3
                    calls[0](calls[1:])
                    a = 5
                except:
                    a = 7
            """)

        self.make_file(
            "doit.py", "\n" * 300 + """\
            def doit(calls):
                try:
                    calls[0](calls[1:])
                except:
                    a = 5
            """)

        # Import all the modules before starting coverage, so the def lines
        # won't be in all the results.
        for mod in "oops fly catch doit".split():
            import_local_file(mod)

        # Each run nests the functions differently to get different
        # combinations of catching exceptions and letting them fly.
        runs = [
            ("doit fly oops", {
                'doit.py': [302, 303, 304, 305],
                'fly.py': [102, 103],
                'oops.py': [2, 3],
            }),
            ("doit catch oops", {
                'doit.py': [302, 303],
                'catch.py': [202, 203, 204, 206, 207],
                'oops.py': [2, 3],
            }),
            ("doit fly catch oops", {
                'doit.py': [302, 303],
                'fly.py': [102, 103, 104],
                'catch.py': [202, 203, 204, 206, 207],
                'oops.py': [2, 3],
            }),
            ("doit catch fly oops", {
                'doit.py': [302, 303],
                'catch.py': [202, 203, 204, 206, 207],
                'fly.py': [102, 103],
                'oops.py': [2, 3],
            }),
        ]

        for callnames, lines_expected in runs:

            # Make the list of functions we'll call for this test.
            callnames = callnames.split()
            calls = [getattr(sys.modules[cn], cn) for cn in callnames]

            cov = coverage.Coverage()
            cov.start()
            # Call our list of functions: invoke the first, with the rest as
            # an argument.
            calls[0](calls[1:])  # pragma: nested
            cov.stop()  # pragma: nested

            # Clean the line data and compare to expected results.
            # The file names are absolute, so keep just the base.
            clean_lines = {}
            data = cov.get_data()
            for callname in callnames:
                filename = callname + ".py"
                lines = data.lines(abs_file(filename))
                clean_lines[filename] = sorted(lines)

            if env.JYTHON:  # pragma: only jython
                # Jython doesn't report on try or except lines, so take those
                # out of the expected lines.
                invisible = [202, 206, 302, 304]
                for lines in lines_expected.values():
                    lines[:] = [l for l in lines if l not in invisible]

            assert clean_lines == lines_expected
Пример #2
0
import coverage

cov = coverage.Coverage()
cov.start()

# .. call your code ..

cov.stop()
cov.save()

cov.html_report()m
Пример #3
0
    def test_b_branch(self):
        self.make_file(
            "b.py", """\
            def one(x):
                # This will be a branch that misses the else.
                if x < 2:
                    a = 3
                else:
                    a = 4

            one(1)

            def two(x):
                # A missed else that branches to "exit"
                if x:
                    a = 5

            two(1)

            def three():
                try:
                    # This if has two branches, *neither* one taken.
                    if name_error_this_variable_doesnt_exist:
                        a = 1
                    else:
                        a = 2
                except:
                    pass

            three()
            """)

        cov = coverage.Coverage(branch=True)
        b = self.start_import_stop(cov, "b")
        cov.html_report(b, directory="out")

        compare_html(gold_path("html/b_branch"), "out")
        contains(
            "out/b_py.html",
            ('<span class="key">if</span> <span class="nam">x</span> '
             '<span class="op">&lt;</span> <span class="num">2</span>'),
            ('    <span class="nam">a</span> <span class="op">=</span> '
             '<span class="num">3</span>'),
            '<span class="pc_cov">70%</span>',
            ('<span class="annotate short">3&#x202F;&#x219B;&#x202F;6</span>'
             '<span class="annotate long">line 3 didn\'t jump to line 6, '
             'because the condition on line 3 was never false</span>'),
            ('<span class="annotate short">12&#x202F;&#x219B;&#x202F;exit</span>'
             '<span class="annotate long">line 12 didn\'t return from function \'two\', '
             'because the condition on line 12 was never false</span>'),
            ('<span class="annotate short">20&#x202F;&#x219B;&#x202F;21,&nbsp;&nbsp; '
             '20&#x202F;&#x219B;&#x202F;23</span>'
             '<span class="annotate long">2 missed branches: '
             '1) line 20 didn\'t jump to line 21, '
             'because the condition on line 20 was never true, '
             '2) line 20 didn\'t jump to line 23, '
             'because the condition on line 20 was never false</span>'),
        )
        contains(
            "out/index.html",
            '<a href="b_py.html">b.py</a>',
            '<span class="pc_cov">70%</span>',
            '<td class="right" data-ratio="16 23">70%</td>',
        )
Пример #4
0
 def test_source_include_exclusive(self):
     cov = coverage.Coverage(source=["pkg1"], include=["pkg2"])
     with self.assert_warnings(
             cov, ["--include is ignored because --source is set"]):
         cov.start()
     cov.stop()  # pragma: nested
Пример #5
0
def run_tests_with_coverage(tracer, *nose_args):
    """Run tests, but with coverage."""

    # Need to define this early enough that the first import of env.py sees it.
    os.environ['COVERAGE_TESTING'] = "True"
    os.environ['COVERAGE_PROCESS_START'] = os.path.abspath('metacov.ini')
    os.environ['COVERAGE_HOME'] = os.getcwd()

    # Create the .pth file that will let us measure coverage in sub-processes.
    # The .pth file seems to have to be alphabetically after easy-install.pth
    # or the sys.path entries aren't created right?
    import nose
    pth_dir = os.path.dirname(os.path.dirname(nose.__file__))
    pth_path = os.path.join(pth_dir, "zzz_metacov.pth")
    with open(pth_path, "w") as pth_file:
        pth_file.write("import coverage; coverage.process_startup()\n")

    # Make names for the data files that keep all the test runs distinct.
    impl = platform.python_implementation().lower()
    version = "%s%s" % sys.version_info[:2]
    if '__pypy__' in sys.builtin_module_names:
        version += "_%s%s" % sys.pypy_version_info[:2]
    suffix = "%s%s_%s_%s" % (impl, version, tracer, platform.platform())

    os.environ['COVERAGE_METAFILE'] = os.path.abspath(".metacov." + suffix)

    import coverage
    cov = coverage.Coverage(config_file="metacov.ini", data_suffix=False)
    # Cheap trick: the coverage.py code itself is excluded from measurement,
    # but if we clobber the cover_prefix in the coverage object, we can defeat
    # the self-detection.
    cov.cover_prefix = "Please measure coverage.py!"
    cov._warn_unimported_source = False
    cov.start()

    try:
        # Re-import coverage to get it coverage tested!  I don't understand all
        # the mechanics here, but if I don't carry over the imported modules
        # (in covmods), then things go haywire (os == None, eventually).
        covmods = {}
        covdir = os.path.split(coverage.__file__)[0]
        # We have to make a list since we'll be deleting in the loop.
        modules = list(sys.modules.items())
        for name, mod in modules:
            if name.startswith('coverage'):
                if getattr(mod, '__file__', "??").startswith(covdir):
                    covmods[name] = mod
                    del sys.modules[name]
        import coverage  # pylint: disable=reimported
        sys.modules.update(covmods)

        # Run nosetests, with the arguments from our command line.
        try:
            run_tests(tracer, *nose_args)
        except SystemExit:
            # nose3 seems to raise SystemExit, not sure why?
            pass
    finally:
        cov.stop()
        os.remove(pth_path)

    cov.combine()
    cov.save()
Пример #6
0
    if v >= StrictVersion("3.5.0") and v < StrictVersion("3.7.0"):
        from cherrypy.wsgiserver.wsgiserver2 import HTTPConnection,\
                                                    CP_fileobject

        def fixed_init(hc_self, server, sock, makefile=CP_fileobject):
            hc_self.server = server
            hc_self.socket = sock
            hc_self.rfile = makefile(sock, "rb", hc_self.rbufsize)
            hc_self.wfile = makefile(sock, "wb", hc_self.wbufsize)
            hc_self.requests_seen = 0

        HTTPConnection.__init__ = fixed_init

if 'COVERAGE_ENABLED' in os.environ:
    import coverage
    _cov = coverage.Coverage(
        config_file="{}/.coveragerc".format(os.path.dirname(__file__)))
    _cov.start()

# pylint: disable=wrong-import-position
from . import logger, mgr
from .controllers import generate_routes, json_error_page
from .controllers.auth import Auth
from .tools import SessionExpireAtBrowserCloseTool, NotificationQueue, \
                   RequestLoggingTool, TaskManager
from .services.exception import dashboard_exception_handler
from .settings import options_command_list, options_schema_list, \
                      handle_option_command


# cherrypy likes to sys.exit on error.  don't let it take us down too!
# pylint: disable=W0613
Пример #7
0
 def test_empty_reporting(self):
     # empty summary reports raise exception, just like the xml report
     cov = coverage.Coverage()
     cov.erase()
     with self.assertRaisesRegex(CoverageException, "No data to report."):
         cov.report()
Пример #8
0
 def test_missing_rcfile_from_environment(self):
     self.set_environ("COVERAGE_RCFILE", "nowhere.ini")
     msg = "Couldn't read 'nowhere.ini' as a config file"
     with pytest.raises(CoverageException, match=msg):
         coverage.Coverage()
Пример #9
0
 def test_default_config(self):
     # Just constructing a coverage() object gets the right defaults.
     cov = coverage.Coverage()
     assert not cov.config.timid
     assert not cov.config.branch
     assert cov.config.data_file == ".coverage"
Пример #10
0
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

_cov = None
import os
if os.environ.get('ZNC_MODPYTHON_COVERAGE'):
    import coverage
    _cov = coverage.Coverage(auto_data=True, branch=True)
    _cov.start()

from functools import wraps
import imp
import re
import traceback
import collections

from znc_core import *


class Socket:
    ADDR_MAP = {'ipv4': ADDR_IPV4ONLY, 'ipv6': ADDR_IPV6ONLY, 'all': ADDR_ALL}

    def _Accepted(self, host, port):
Пример #11
0
    try:
        test_module_list = get_test_modules(args)
    except Exception as e:
        print(str(e))
        sys.exit(1)
    # Login the test client
    test_utils.login_tester_account(test_client)

    servers_info = test_utils.get_config_data()
    node_name = "all"
    if args['pkg'] is not None:
        node_name = args['pkg'].split('.')[-1]

    # Start coverage
    if test_utils.is_coverage_enabled(args):
        cov = coverage.Coverage(config_file=COVERAGE_CONFIG_FILE)
        cov.start()

    # Check if feature tests included & parallel tests switch passed
    if test_utils.is_feature_test_included(args) and \
            test_utils.is_parallel_ui_tests(args):
        try:
            # Get selenium config dict
            selenoid_config = test_setup.config_data['selenoid_config']

            # Set DEFAULT_SERVER value
            default_server = selenoid_config['pgAdmin_default_server']
            os.environ["PGADMIN_CONFIG_DEFAULT_SERVER"] = str(default_server)
            config.DEFAULT_SERVER = str(default_server)

            # Get hub url
"""


if __name__ == "__main__":  # pragma: no cover
    import base64
    import os
    import pickle
    import sys

    # Run coverage in the subprocess if necessary
    if "GLEAN_COVERAGE" in os.environ and "COVERAGE_PROCESS_START" in os.environ:
        import coverage  # type: ignore

        config_path = os.environ.get("COVERAGE_PROCESS_START")

        cov = coverage.Coverage(data_suffix=True, config_file=config_path)
        cov.start()
        cov._warn_no_data = False
        cov._warn_unimported_source = False
        cov._auto_save = True

    __builtins__.IN_GLEAN_SUBPROCESS = True  # type: ignore

    func, args = pickle.loads(base64.b64decode(sys.argv[1]))

    success = func(*args)

    if success:
        sys.exit(0)
    else:
        sys.exit(1)
Пример #13
0
def test_thread_safe_save_data(tmpdir):
    # Non-regression test for: https://github.com/nedbat/coveragepy/issues/581

    # Create some Python modules and put them in the path
    modules_dir = tmpdir.mkdir('test_modules')
    module_names = ["m{:03d}".format(i) for i in range(1000)]
    for module_name in module_names:
        modules_dir.join(module_name + ".py").write("def f(): pass\n")

    # Shared variables for threads
    should_run = [True]
    imported = []

    old_dir = os.getcwd()
    os.chdir(modules_dir.strpath)
    try:
        # Make sure that all dummy modules can be imported.
        for module_name in module_names:
            import_local_file(module_name)

        def random_load():  # pragma: nested
            """Import modules randomly to stress coverage."""
            while should_run[0]:
                module_name = random.choice(module_names)
                mod = import_local_file(module_name)
                mod.f()
                imported.append(mod)

        # Spawn some threads with coverage enabled and attempt to read the
        # results right after stopping coverage collection with the threads
        #  still running.
        duration = 0.01
        for _ in range(3):
            cov = coverage.Coverage()
            cov.start()

            threads = [
                threading.Thread(target=random_load) for _ in range(10)
            ]  # pragma: nested
            should_run[0] = True  # pragma: nested
            for t in threads:  # pragma: nested
                t.start()

            time.sleep(duration)  # pragma: nested

            cov.stop()  # pragma: nested

            # The following call used to crash with running background threads.
            cov.get_data()

            # Stop the threads
            should_run[0] = False
            for t in threads:
                t.join()

            if (not imported) and duration < 10:  # pragma: only failure
                duration *= 2

    finally:
        os.chdir(old_dir)
        should_run[0] = False
Пример #14
0
    def check_coverage(
        self, text, lines=None, missing="", report="",
        excludes=None, partials="",
        arcz=None, arcz_missing=None, arcz_unpredicted=None,
        arcs=None, arcs_missing=None, arcs_unpredicted=None,
    ):
        """Check the coverage measurement of `text`.

        The source `text` is run and measured.  `lines` are the line numbers
        that are executable, or a list of possible line numbers, any of which
        could match. `missing` are the lines not executed, `excludes` are
        regexes to match against for excluding lines, and `report` is the text
        of the measurement report.

        For arc measurement, `arcz` is a string that can be decoded into arcs
        in the code (see `arcz_to_arcs` for the encoding scheme).
        `arcz_missing` are the arcs that are not executed, and
        `arcz_unpredicted` are the arcs executed in the code, but not deducible
        from the code.  These last two default to "", meaning we explicitly
        check that there are no missing or unpredicted arcs.

        Returns the Coverage object, in case you want to poke at it some more.

        """
        # We write the code into a file so that we can import it.
        # Coverage.py wants to deal with things as modules with file names.
        modname = self.get_module_name()

        self.make_file(modname + ".py", text)

        if arcs is None and arcz is not None:
            arcs = arcz_to_arcs(arcz)
        if arcs_missing is None and arcz_missing is not None:
            arcs_missing = arcz_to_arcs(arcz_missing)
        if arcs_unpredicted is None and arcz_unpredicted is not None:
            arcs_unpredicted = arcz_to_arcs(arcz_unpredicted)

        # Start up coverage.py.
        cov = coverage.Coverage(branch=True)
        cov.erase()
        for exc in excludes or []:
            cov.exclude(exc)
        for par in partials or []:
            cov.exclude(par, which='partial')

        mod = self.start_import_stop(cov, modname)

        # Clean up our side effects
        del sys.modules[modname]

        # Get the analysis results, and check that they are right.
        analysis = cov._analyze(mod)
        statements = sorted(analysis.statements)
        if lines is not None:
            if isinstance(lines[0], int):
                # lines is just a list of numbers, it must match the statements
                # found in the code.
                assert statements == lines, f"{statements!r} != {lines!r}"
            else:
                # lines is a list of possible line number lists, one of them
                # must match.
                for line_list in lines:
                    if statements == line_list:
                        break
                else:
                    assert False, f"None of the lines choices matched {statements!r}"

            missing_formatted = analysis.missing_formatted()
            if isinstance(missing, str):
                msg = f"{missing_formatted!r} != {missing!r}"
                assert missing_formatted == missing, msg
            else:
                for missing_list in missing:
                    if missing_formatted == missing_list:
                        break
                else:
                    assert False, f"None of the missing choices matched {missing_formatted!r}"

        if arcs is not None:
            # print("Possible arcs:")
            # print(" expected:", arcs)
            # print(" actual:", analysis.arc_possibilities())
            # print("Executed:")
            # print(" actual:", sorted(set(analysis.arcs_executed())))
            # TODO: this would be nicer with pytest-check, once we can run that.
            msg = (
                self._check_arcs(arcs, analysis.arc_possibilities(), "Possible") +
                self._check_arcs(arcs_missing, analysis.arcs_missing(), "Missing") +
                self._check_arcs(arcs_unpredicted, analysis.arcs_unpredicted(), "Unpredicted")
            )
            if msg:
                assert False, msg

        if report:
            frep = io.StringIO()
            cov.report(mod, file=frep, show_missing=True)
            rep = " ".join(frep.getvalue().split("\n")[2].split()[1:])
            assert report == rep, f"{report!r} != {rep!r}"

        return cov
Пример #15
0
    logger.info("Set log level: DEBUG")
    test_verbosity = 2
    use_buffer = False

if options.coverage:
    logger.info("Running test-coverage")
    import coverage
    omits = [
        "*test*",
        "*third_party*",
        "*/setup.py",
        # temporary test modules (silx.math.fit.test.test_fitmanager)
        "*customfun.py",
    ]
    try:
        cov = coverage.Coverage(omit=omits)
    except AttributeError:
        cov = coverage.coverage(omit=omits)
    cov.start()

if options.qt_binding:
    binding = options.qt_binding.lower()
    if binding == "pyqt4":
        logger.info("Force using PyQt4")
        if sys.version < "3.0.0":
            try:
                import sip
                sip.setapi("QString", 2)
                sip.setapi("QVariant", 2)
            except Exception:
                logger.warning("Cannot set sip API")
Пример #16
0
 def test_config_file_settings(self):
     self.make_file(".coveragerc", self.LOTSA_SETTINGS.format(section=""))
     cov = coverage.Coverage()
     self.assert_config_settings_are_correct(cov)
Пример #17
0
 def test_empty_reporting(self):
     # empty summary reports raise exception, just like the xml report
     cov = coverage.Coverage()
     cov.erase()
     self.assertRaises(CoverageException, cov.report)
Пример #18
0
 def check_config_file_settings_in_other_file(self, fname, contents):
     """Check config will be read from another file, with prefixed sections."""
     nested = self.LOTSA_SETTINGS.format(section="coverage:")
     fname = self.make_file(fname, nested + "\n" + contents)
     cov = coverage.Coverage()
     self.assert_config_settings_are_correct(cov)
Пример #19
0
    def test_partial(self):
        self.make_file(
            "partial.py", """\
            # partial branches and excluded lines
            a = 2

            while "no peephole".upper():        # t4
                break

            while a:        # pragma: no branch
                break

            if 0:
                never_happen()

            if 13:
                a = 14

            if a == 16:
                raise ZeroDivisionError("17")
            """)
        self.make_file(
            "partial.ini", """\
            [run]
            branch = True

            [report]
            exclude_lines =
                raise ZeroDivisionError
            """)

        cov = coverage.Coverage(config_file="partial.ini")
        partial = self.start_import_stop(cov, "partial")

        if env.PYBEHAVIOR.pep626:
            cov.html_report(partial, directory="out/partial_626")
            compare_html(gold_path("html/partial_626"), "out/partial_626")
            contains_rx(
                "out/partial_626/partial_py.html",
                r'<p class="par run show_par">.* id="t4"',
                r'<p class="run">.* id="t7"',
                # The "if 0" and "if 1" statements are marked as run.
                r'<p class="run">.* id="t10"',
                # The "raise ZeroDivisionError" is excluded by regex in the .ini.
                r'<p class="exc show_exc">.* id="t17"',
            )
            contains(
                "out/partial_626/index.html",
                '<a href="partial_py.html">partial.py</a>',
                '<span class="pc_cov">87%</span>',
            )
        else:
            cov.html_report(partial, directory="out/partial")
            compare_html(gold_path("html/partial"), "out/partial")
            contains_rx(
                "out/partial/partial_py.html",
                r'<p class="par run show_par">.* id="t4"',
                r'<p class="run">.* id="t7"',
                # The "if 0" and "if 1" statements are optimized away.
                r'<p class="pln">.* id="t10"',
                # The "raise ZeroDivisionError" is excluded by regex in the .ini.
                r'<p class="exc show_exc">.* id="t17"',
            )
            contains(
                "out/partial/index.html",
                '<a href="partial_py.html">partial.py</a>',
                '<span class="pc_cov">91%</span>',
            )
Пример #20
0
 def check_other_config_if_coveragerc_specified(self, fname, contents):
     """Check that config `fname` is read if .coveragerc is missing, but specified."""
     nested = self.LOTSA_SETTINGS.format(section="coverage:")
     self.make_file(fname, nested + "\n" + contents)
     cov = coverage.Coverage(config_file=".coveragerc")
     self.assert_config_settings_are_correct(cov)
Пример #21
0
 def test_config_crash_no_crash(self):
     # '[run] _crash' really checks the call stack.
     cov = coverage.Coverage()
     cov.set_option("run:_crash", "not_my_caller")
     cov.start()
     cov.stop()
Пример #22
0
 def test_read_prefixed_sections_from_explicit_file(self):
     # You can point to a tox.ini, and it will find [coverage:run] sections
     nested = self.LOTSA_SETTINGS.format(section="coverage:")
     self.make_file("tox.ini", self.TOX_INI + "\n" + nested)
     cov = coverage.Coverage(config_file="tox.ini")
     self.assert_config_settings_are_correct(cov)
Пример #23
0
 def __init__(self, context):
     self._context = context
     self.reset()
     self.cov = coverage.Coverage()
     self.cov.load()
Пример #24
0
 def test_nocoveragerc_file_when_specified(self):
     cov = coverage.Coverage(config_file=".coveragerc")
     assert not cov.config.timid
     assert not cov.config.branch
     assert cov.config.data_file == ".coverage"
Пример #25
0
# "::" it tries both ipv4 and ipv6, and in some environments (e.g. kubernetes)
# ipv6 isn't yet configured / supported and CherryPy throws an uncaught
# exception.
if cherrypy is not None:
    v = StrictVersion(cherrypy.__version__)
    # the issue was fixed in 3.2.3. it's present in 3.2.2 (current version on
    # centos:7) and back to at least 3.0.0.
    if StrictVersion("3.1.2") <= v < StrictVersion("3.2.3"):
        # https://github.com/cherrypy/cherrypy/issues/1100
        from cherrypy.process import servers
        servers.wait_for_occupied_port = lambda host, port: None

if 'COVERAGE_ENABLED' in os.environ:
    import coverage
    __cov = coverage.Coverage(config_file="{}/.coveragerc".format(
        os.path.dirname(__file__)),
                              data_suffix=True)

    cherrypy.engine.subscribe('start', __cov.start)
    cherrypy.engine.subscribe('after_request', __cov.save)
    cherrypy.engine.subscribe('stop', __cov.stop)

# pylint: disable=wrong-import-position
from . import logger, mgr
from .controllers import generate_routes, json_error_page
from .grafana import push_local_dashboards
from .tools import NotificationQueue, RequestLoggingTool, TaskManager, \
                   prepare_url_prefix, str_to_bool
from .services.auth import AuthManager, AuthManagerTool, JwtManager
from .services.sso import SSO_COMMANDS, \
                          handle_sso_command
Пример #26
0
 def test_no_toml_installed_no_toml(self):
     # Can't read a toml file that doesn't exist.
     with without_module(coverage.tomlconfig, 'toml'):
         msg = "Couldn't read 'cov.toml' as a config file"
         with pytest.raises(CoverageException, match=msg):
             coverage.Coverage(config_file="cov.toml")
Пример #27
0
 def run_coverage(self, covargs=None, htmlargs=None):
     """Run coverage.py on main_file.py, and create an HTML report."""
     self.clean_local_file_imports()
     cov = coverage.Coverage(**(covargs or {}))
     self.start_import_stop(cov, "main_file")
     return cov.html_report(**(htmlargs or {}))
Пример #28
0
 def test_static_context(self):
     self.make_file("main.py", "a = 1")
     cov = coverage.Coverage(context="gooey")
     self.start_import_stop(cov, "main")
     data = cov.get_data()
     assert_count_equal(data.measured_contexts(), ["gooey"])
Пример #29
0
 def test_omit_2(self):
     self.make_main_etc()
     cov = coverage.Coverage(include=["./*"])
     self.start_import_stop(cov, "main")
     cov.html_report(directory="out", omit=["m1.py"])
     compare_html(gold_path("html/omit_2"), "out")
Пример #30
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""py_unittest.py runs tests under src/appengine and butler/tests"""
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import object
from builtins import range
import coverage

# Coverage needs to be at the top of the page. See: go/why-top-cov
COV = coverage.Coverage(config_file='.coveragerc')
COV.start()

import io
import itertools
import logging
import multiprocessing
import os
import platform
import signal
import sys
import time
import unittest

from local.butler import appengine
from local.butler import common