Beispiel #1
0
 def test_odd_filenames(self):
     acu = PythonFileReporter("aa/afile.odd.py")
     bcu = PythonFileReporter("aa/bb/bfile.odd.py")
     b2cu = PythonFileReporter("aa/bb.odd/bfile.py")
     assert acu.relative_filename() == "aa/afile.odd.py"
     assert bcu.relative_filename() == "aa/bb/bfile.odd.py"
     assert b2cu.relative_filename() == "aa/bb.odd/bfile.py"
     assert acu.source() == "# afile.odd.py\n"
     assert bcu.source() == "# bfile.odd.py\n"
     assert b2cu.source() == "# bfile.py\n"
Beispiel #2
0
 def test_filenames(self):
     acu = PythonFileReporter("aa/afile.py")
     bcu = PythonFileReporter("aa/bb/bfile.py")
     ccu = PythonFileReporter("aa/bb/cc/cfile.py")
     self.assertEqual(acu.relative_filename(), "aa/afile.py")
     self.assertEqual(bcu.relative_filename(), "aa/bb/bfile.py")
     self.assertEqual(ccu.relative_filename(), "aa/bb/cc/cfile.py")
     self.assertEqual(acu.source(), "# afile.py\n")
     self.assertEqual(bcu.source(), "# bfile.py\n")
     self.assertEqual(ccu.source(), "# cfile.py\n")
Beispiel #3
0
 def test_filenames(self):
     acu = PythonFileReporter("aa/afile.py")
     bcu = PythonFileReporter("aa/bb/bfile.py")
     ccu = PythonFileReporter("aa/bb/cc/cfile.py")
     assert acu.relative_filename() == "aa/afile.py"
     assert bcu.relative_filename() == "aa/bb/bfile.py"
     assert ccu.relative_filename() == "aa/bb/cc/cfile.py"
     assert acu.source() == "# afile.py\n"
     assert bcu.source() == "# bfile.py\n"
     assert ccu.source() == "# cfile.py\n"
Beispiel #4
0
 def test_odd_filenames(self):
     acu = PythonFileReporter("aa/afile.odd.py")
     bcu = PythonFileReporter("aa/bb/bfile.odd.py")
     b2cu = PythonFileReporter("aa/bb.odd/bfile.py")
     self.assertEqual(acu.relative_filename(), "aa/afile.odd.py")
     self.assertEqual(bcu.relative_filename(), "aa/bb/bfile.odd.py")
     self.assertEqual(b2cu.relative_filename(), "aa/bb.odd/bfile.py")
     self.assertEqual(acu.source(), "# afile.odd.py\n")
     self.assertEqual(bcu.source(), "# bfile.odd.py\n")
     self.assertEqual(b2cu.source(), "# bfile.py\n")
Beispiel #5
0
    def test_modules(self):
        import aa
        import aa.bb
        import aa.bb.cc

        acu = PythonFileReporter(aa)
        bcu = PythonFileReporter(aa.bb)
        ccu = PythonFileReporter(aa.bb.cc)
        assert acu.relative_filename() == native("aa/__init__.py")
        assert bcu.relative_filename() == native("aa/bb/__init__.py")
        assert ccu.relative_filename() == native("aa/bb/cc/__init__.py")
        assert acu.source() == "# aa\n"
        assert bcu.source() == "# bb\n"
        assert ccu.source() == ""  # yes, empty
Beispiel #6
0
    def test_modules(self):
        import aa
        import aa.bb
        import aa.bb.cc

        acu = PythonFileReporter(aa)
        bcu = PythonFileReporter(aa.bb)
        ccu = PythonFileReporter(aa.bb.cc)
        self.assertEqual(acu.relative_filename(), native("aa.py"))
        self.assertEqual(bcu.relative_filename(), native("aa/bb.py"))
        self.assertEqual(ccu.relative_filename(), native("aa/bb/cc.py"))
        self.assertEqual(acu.source(), "# aa\n")
        self.assertEqual(bcu.source(), "# bb\n")
        self.assertEqual(ccu.source(), "")  # yes, empty
Beispiel #7
0
    def test_module_files(self):
        import aa.afile
        import aa.bb.bfile
        import aa.bb.cc.cfile

        acu = PythonFileReporter(aa.afile)
        bcu = PythonFileReporter(aa.bb.bfile)
        ccu = PythonFileReporter(aa.bb.cc.cfile)
        assert acu.relative_filename() == native("aa/afile.py")
        assert bcu.relative_filename() == native("aa/bb/bfile.py")
        assert ccu.relative_filename() == native("aa/bb/cc/cfile.py")
        assert acu.source() == "# afile.py\n"
        assert bcu.source() == "# bfile.py\n"
        assert ccu.source() == "# cfile.py\n"
Beispiel #8
0
    def test_module_files(self):
        import aa.afile
        import aa.bb.bfile
        import aa.bb.cc.cfile

        acu = PythonFileReporter(aa.afile)
        bcu = PythonFileReporter(aa.bb.bfile)
        ccu = PythonFileReporter(aa.bb.cc.cfile)
        self.assertEqual(acu.relative_filename(), native("aa/afile.py"))
        self.assertEqual(bcu.relative_filename(), native("aa/bb/bfile.py"))
        self.assertEqual(ccu.relative_filename(), native("aa/bb/cc/cfile.py"))
        self.assertEqual(acu.source(), "# afile.py\n")
        self.assertEqual(bcu.source(), "# bfile.py\n")
        self.assertEqual(ccu.source(), "# cfile.py\n")
Beispiel #9
0
    def test_egg(self):
        # Test that we can get files out of eggs, and read their source files.
        # The egg1 module is installed by an action in igor.py.
        import egg1
        import egg1.egg1

        # Verify that we really imported from an egg.  If we did, then the
        # __file__ won't be an actual file, because one of the "directories"
        # in the path is actually the .egg zip file.
        self.assert_doesnt_exist(egg1.__file__)

        ecu = PythonFileReporter(egg1)
        eecu = PythonFileReporter(egg1.egg1)
        assert ecu.source() == u""
        assert u"# My egg file!" in eecu.source().splitlines()
Beispiel #10
0
    def _get_file_reporter(self, morf):
        """Get a FileReporter for a module or filename."""
        plugin = None

        if isinstance(morf, string_class):
            abs_morf = abs_file(morf)
            plugin_name = self.data.plugin_data().get(abs_morf)
            if plugin_name:
                plugin = self.plugins.get(plugin_name)

        if plugin:
            file_reporter = plugin.file_reporter(abs_morf)
            if file_reporter is None:
                raise CoverageException(
                    "Plugin %r did not provide a file reporter for %r." % (
                        plugin._coverage_plugin_name, morf
                    )
                )
        else:
            file_reporter = PythonFileReporter(morf, self)

        # The FileReporter can have a name attribute, but if it doesn't, we'll
        # supply it as the relative path to self.filename.
        if not hasattr(file_reporter, "name"):
            file_reporter.name = files.relative_filename(file_reporter.filename)

        return file_reporter
    def _get_file_reporter(self, morf):
        """Get a FileReporter for a module or file name."""
        plugin = None
        file_reporter = "python"

        if isinstance(morf, string_class):
            abs_morf = abs_file(morf)
            plugin_name = self.data.file_tracer(abs_morf)
            if plugin_name:
                plugin = self.plugins.get(plugin_name)

        if plugin:
            file_reporter = plugin.file_reporter(abs_morf)
            if file_reporter is None:
                raise CoverageException(
                    "Plugin %r did not provide a file reporter for %r." % (
                        plugin._coverage_plugin_name, morf
                    )
                )

        if file_reporter == "python":
            # pylint: disable=redefined-variable-type
            file_reporter = PythonFileReporter(morf, self)

        return file_reporter
Beispiel #12
0
 def setUp(self):
     coverage = coveralls(data_file=Arguments.data_file,
                          config_file=Arguments.config_file)
     coverage.load()
     self.reporter = CoverallsReporter(coverage, coverage.config)
     self.reporter.find_file_reporters(None)
     self.reporter.file_reporters.append(
         PythonFileReporter('LICENSE', coverage=coverage))
Beispiel #13
0
    def test_zipfile(self):
        sys.path.append("tests/zip1.zip")

        # Test that we can get files out of zipfiles, and read their source files.
        # The zip1 module is installed by an action in igor.py.
        import zip1
        import zip1.zip1

        # Verify that we really imported from an zipfile.  If we did, then the
        # __file__ won't be an actual file, because one of the "directories"
        # in the path is actually the zip file.
        self.assert_doesnt_exist(zip1.__file__)

        z1 = PythonFileReporter(zip1)
        z1z1 = PythonFileReporter(zip1.zip1)
        assert z1.source() == u""
        assert u"# My zip file!" in z1z1.source().splitlines()
    def _canonical_path(self, morf, directory=False):
        """Return the canonical path of the module or file `morf`.

        If the module is a package, then return its directory. If it is a
        module, then return its file, unless `directory` is True, in which
        case return its enclosing directory.

        """
        morf_path = PythonFileReporter(morf, self).filename
        if morf_path.endswith("__init__.py") or directory:
            morf_path = os.path.split(morf_path)[0]
        return morf_path
    def _get_file_reporter(self, morf):
        """Get a FileReporter for a module or file name."""
        plugin = None
        file_reporter = "python"

        if isinstance(morf, string_class):
            mapped_morf = self._file_mapper(morf)
            plugin_name = self._data.file_tracer(mapped_morf)
            if plugin_name:
                plugin = self._plugins.get(plugin_name)

                if plugin:
                    file_reporter = plugin.file_reporter(mapped_morf)
                    if file_reporter is None:
                        raise CoverageException(
                            "Plugin %r did not provide a file reporter for %r."
                            % (plugin._coverage_plugin_name, morf))

        if file_reporter == "python":
            file_reporter = PythonFileReporter(morf, self)

        return file_reporter
Beispiel #16
0
    def _get_file_reporter(self, morf):
        """Get a FileReporter for a module or file name."""
        plugin = None
        file_reporter = "python"

        if isinstance(morf, str):
            mapped_morf = self._file_mapper(morf)
            plugin_name = self._data.file_tracer(mapped_morf)
            if plugin_name:
                plugin = self._plugins.get(plugin_name)

                if plugin:
                    file_reporter = plugin.file_reporter(mapped_morf)
                    if file_reporter is None:
                        raise PluginError(
                            "Plugin {!r} did not provide a file reporter for {!r}."
                            .format(plugin._coverage_plugin_name, morf))

        if file_reporter == "python":
            file_reporter = PythonFileReporter(morf, self)

        return file_reporter
Beispiel #17
0
 def _canonical_dir(self, morf):
     """Return the canonical directory of the module or file `morf`."""
     morf_filename = PythonFileReporter(morf, self).filename
     return os.path.split(morf_filename)[0]
    test_result = reporter.run(suite)

    error_string = ''.join([repr(error) for error in test_result.errors])
    assert len(test_result.errors) == 0,\
        "ERROR: UNIT TESTS FAILED, PLEASE FIX BEFORE RUNNING COVERAGE:\n%s\n%s" % (output_stream.getvalue(),
                                                                                   error_string)
    output_stream.close()

cov.stop()
print("Generating HTML report")
cov.html_report(directory='coverage')

print("Aggregating package stats")
total_numbers = {}  # Package name -> (Numbers: package coverage stats, dict: files per coverage bin)
for filename in cov.get_data().measured_files():
    file_reporter = PythonFileReporter(filename, cov)
    analysis = Analysis(cov.get_data(), file_reporter, abs_file)

    # If the package name does not contain more than 2 parts, it's a top-level file.
    package_path = pathlib.Path(relative_filename(filename))
    package = ".".join(package_path.parts[:2 if len(package_path.parts) > 2 else 1])
    package_stats = total_numbers.get(package)

    # Put all exactly 100% coverage files into the 80%-100% bin
    individual_coverage = min(4, int(analysis.numbers.pc_covered / 20.0))

    if not package_stats:
        total_numbers[package] = (analysis.numbers, {individual_coverage: 1})
    else:
        package_numbers, package_buckets = package_stats
        package_buckets[individual_coverage] = 1 + package_buckets.get(individual_coverage, 0)