def test_comparison(self):
     acu = code_unit_factory("aa/afile.py", FileLocator())[0]
     acu2 = code_unit_factory("aa/afile.py", FileLocator())[0]
     zcu = code_unit_factory("aa/zfile.py", FileLocator())[0]
     bcu = code_unit_factory("aa/bb/bfile.py", FileLocator())[0]
     assert acu == acu2 and acu <= acu2 and acu >= acu2
     assert acu < zcu and acu <= zcu and acu != zcu
     assert zcu > acu and zcu >= acu and zcu != acu
     assert acu < bcu and acu <= bcu and acu != bcu
     assert bcu > acu and bcu >= acu and bcu != acu
Exemple #2
0
 def test_comparison(self):
     acu = code_unit_factory("aa/afile.py", FileLocator())[0]
     acu2 = code_unit_factory("aa/afile.py", FileLocator())[0]
     zcu = code_unit_factory("aa/zfile.py", FileLocator())[0]
     bcu = code_unit_factory("aa/bb/bfile.py", FileLocator())[0]
     assert acu == acu2 and acu <= acu2 and acu >= acu2
     assert acu < zcu and acu <= zcu and acu != zcu
     assert zcu > acu and zcu >= acu and zcu != acu
     assert acu < bcu and acu <= bcu and acu != bcu
     assert bcu > acu and bcu >= acu and bcu != acu
Exemple #3
0
 def test_filenames(self):
     acu = code_unit_factory("aa/afile.py", FileLocator())
     bcu = code_unit_factory("aa/bb/bfile.py", FileLocator())
     ccu = code_unit_factory("aa/bb/cc/cfile.py", FileLocator())
     self.assertEqual(acu[0].name, "aa/afile")
     self.assertEqual(bcu[0].name, "aa/bb/bfile")
     self.assertEqual(ccu[0].name, "aa/bb/cc/cfile")
     self.assertEqual(acu[0].flat_rootname(), "aa_afile")
     self.assertEqual(bcu[0].flat_rootname(), "aa_bb_bfile")
     self.assertEqual(ccu[0].flat_rootname(), "aa_bb_cc_cfile")
     self.assertEqual(acu[0].source_file().read(), "# afile.py\n")
     self.assertEqual(bcu[0].source_file().read(), "# bfile.py\n")
     self.assertEqual(ccu[0].source_file().read(), "# cfile.py\n")
 def test_filenames(self):
     acu = code_unit_factory("aa/afile.py", FileLocator())
     bcu = code_unit_factory("aa/bb/bfile.py", FileLocator())
     ccu = code_unit_factory("aa/bb/cc/cfile.py", FileLocator())
     self.assertEqual(acu[0].name, "aa/afile")
     self.assertEqual(bcu[0].name, "aa/bb/bfile")
     self.assertEqual(ccu[0].name, "aa/bb/cc/cfile")
     self.assertEqual(acu[0].flat_rootname(), "aa_afile")
     self.assertEqual(bcu[0].flat_rootname(), "aa_bb_bfile")
     self.assertEqual(ccu[0].flat_rootname(), "aa_bb_cc_cfile")
     self.assertEqual(acu[0].source_file().read(), "# afile.py\n")
     self.assertEqual(bcu[0].source_file().read(), "# bfile.py\n")
     self.assertEqual(ccu[0].source_file().read(), "# cfile.py\n")
 def test_odd_filenames(self):
     acu = code_unit_factory("aa/afile.odd.py", FileLocator())
     bcu = code_unit_factory("aa/bb/bfile.odd.py", FileLocator())
     b2cu = code_unit_factory("aa/bb.odd/bfile.py", FileLocator())
     self.assertEqual(acu[0].name, "aa/afile.odd")
     self.assertEqual(bcu[0].name, "aa/bb/bfile.odd")
     self.assertEqual(b2cu[0].name, "aa/bb.odd/bfile")
     self.assertEqual(acu[0].flat_rootname(), "aa_afile_odd")
     self.assertEqual(bcu[0].flat_rootname(), "aa_bb_bfile_odd")
     self.assertEqual(b2cu[0].flat_rootname(), "aa_bb_odd_bfile")
     self.assertEqual(acu[0].source_file().read(), "# afile.odd.py\n")
     self.assertEqual(bcu[0].source_file().read(), "# bfile.odd.py\n")
     self.assertEqual(b2cu[0].source_file().read(), "# bfile.py\n")
Exemple #6
0
 def test_odd_filenames(self):
     acu = code_unit_factory("aa/afile.odd.py", FileLocator())
     bcu = code_unit_factory("aa/bb/bfile.odd.py", FileLocator())
     b2cu = code_unit_factory("aa/bb.odd/bfile.py", FileLocator())
     self.assertEqual(acu[0].name, "aa/afile.odd")
     self.assertEqual(bcu[0].name, "aa/bb/bfile.odd")
     self.assertEqual(b2cu[0].name, "aa/bb.odd/bfile")
     self.assertEqual(acu[0].flat_rootname(), "aa_afile_odd")
     self.assertEqual(bcu[0].flat_rootname(), "aa_bb_bfile_odd")
     self.assertEqual(b2cu[0].flat_rootname(), "aa_bb_odd_bfile")
     self.assertEqual(acu[0].source_file().read(), "# afile.odd.py\n")
     self.assertEqual(bcu[0].source_file().read(), "# bfile.odd.py\n")
     self.assertEqual(b2cu[0].source_file().read(), "# bfile.py\n")
Exemple #7
0
    def find_code_units(self, morfs):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames.

        """
        morfs = morfs or self.coverage.data.measured_files()
        file_locator = self.coverage.file_locator
        get_ext = self.coverage.data.extension_data().get
        self.code_units = code_unit_factory(morfs, file_locator, get_ext)

        if self.config.include:
            patterns = prep_patterns(self.config.include)
            matcher = FnmatchMatcher(patterns)
            filtered = []
            for cu in self.code_units:
                if matcher.match(cu.filename):
                    filtered.append(cu)
            self.code_units = filtered

        if self.config.omit:
            patterns = prep_patterns(self.config.omit)
            matcher = FnmatchMatcher(patterns)
            filtered = []
            for cu in self.code_units:
                if not matcher.match(cu.filename):
                    filtered.append(cu)
            self.code_units = filtered

        self.code_units.sort()
Exemple #8
0
    def find_code_units(self, morfs):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames.

        """
        morfs = morfs or self.coverage.data.measured_files()
        file_locator = self.coverage.file_locator
        get_ext = self.coverage.data.extension_data().get
        self.code_units = code_unit_factory(morfs, file_locator, get_ext)

        if self.config.include:
            patterns = prep_patterns(self.config.include)
            matcher = FnmatchMatcher(patterns)
            filtered = []
            for cu in self.code_units:
                if matcher.match(cu.filename):
                    filtered.append(cu)
            self.code_units = filtered

        if self.config.omit:
            patterns = prep_patterns(self.config.omit)
            matcher = FnmatchMatcher(patterns)
            filtered = []
            for cu in self.code_units:
                if not matcher.match(cu.filename):
                    filtered.append(cu)
            self.code_units = filtered

        self.code_units.sort()
 def test_egg(self):
     import egg1, egg1.egg1
     cu = code_unit_factory([egg1, egg1.egg1], FileLocator())
     self.assertEqual(cu[0].source_file().read(), "")
     self.assertEqual(cu[1].source_file().read().split("\n")[0],
             "# My egg file!"
             )
Exemple #10
0
    def find_code_units(self, morfs):
        morfs = morfs or self.coverage.data.measured_files()
        file_locator = self.coverage.file_locator
        self.code_units = code_unit_factory(morfs, file_locator)
        if self.config.include:
            patterns = prep_patterns(self.config.include)
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        filtered.append(cu)
                        break

            self.code_units = filtered
        if self.config.omit:
            patterns = prep_patterns(self.config.omit)
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        break
                else:
                    filtered.append(cu)

            self.code_units = filtered
        self.code_units.sort()
Exemple #11
0
    def find_code_units(self, morfs, config):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames. `config` is a
        CoverageConfig instance.

        """
        morfs = morfs or self.coverage.data.measured_files()
        file_locator = self.coverage.file_locator
        self.code_units = code_unit_factory(morfs, file_locator)

        if config.include:
            patterns = [file_locator.abs_file(p) for p in config.include]
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        filtered.append(cu)
                        break
            self.code_units = filtered

        if config.omit:
            patterns = [file_locator.abs_file(p) for p in config.omit]
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        break
                else:
                    filtered.append(cu)
            self.code_units = filtered

        self.code_units.sort()
Exemple #12
0
    def find_code_units(self, morfs):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames.

        """
        morfs = morfs or self.coverage.data.measured_files()
        file_locator = self.coverage.file_locator
        self.code_units = code_unit_factory(morfs, file_locator)

        if self.config.include:
            patterns = prep_patterns(self.config.include)
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        filtered.append(cu)
                        break
            self.code_units = filtered

        if self.config.omit:
            patterns = prep_patterns(self.config.omit)
            filtered = []
            for cu in self.code_units:
                for pattern in patterns:
                    if fnmatch.fnmatch(cu.filename, pattern):
                        break
                else:
                    filtered.append(cu)
            self.code_units = filtered

        self.code_units.sort()
Exemple #13
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator)[0]

        return Analysis(self, it)
Exemple #14
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator)[0]

        return Analysis(self, it)
Exemple #15
0
 def find_code_units(self, morfs, omit_prefixes):
     """Find the code units we'll report on.
     
     `morfs` is a list of modules or filenames. `omit_prefixes` is a list
     of prefixes to leave out of the list.
     
     """
     morfs = morfs or self.coverage.data.executed_files()
     self.code_units = code_unit_factory(morfs, self.coverage.file_locator,
                                         omit_prefixes)
     self.code_units.sort()
Exemple #16
0
 def find_code_units(self, morfs, omit_prefixes):
     """Find the code units we'll report on.
     
     `morfs` is a list of modules or filenames. `omit_prefixes` is a list
     of prefixes to leave out of the list.
     
     """
     morfs = morfs or self.coverage.data.executed_files()
     self.code_units = code_unit_factory(
                         morfs, self.coverage.file_locator, omit_prefixes)
     self.code_units.sort()
Exemple #17
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        self._harvest_data()
        if not isinstance(it, CodeUnit):
            get_ext = self.data.extension_data().get
            it = code_unit_factory(it, self.file_locator, get_ext)[0]

        return Analysis(self, it)
Exemple #18
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, 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__)

        cu = code_unit_factory([egg1, egg1.egg1], FileLocator())
        self.assertEqual(cu[0].source(), "")
        self.assertEqual(cu[1].source().split("\n")[0], "# My egg file!")
Exemple #19
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        self._harvest_data()
        if not isinstance(it, CodeUnit):
            get_ext = self.data.extension_data().get
            it = code_unit_factory(it, self.file_locator, get_ext)[0]

        return Analysis(self, it)
Exemple #20
0
 def test_modules(self):
     import aa, aa.bb, aa.bb.cc
     cu = code_unit_factory([aa, aa.bb, aa.bb.cc], FileLocator())
     self.assertEqual(cu[0].name, "aa")
     self.assertEqual(cu[1].name, "aa.bb")
     self.assertEqual(cu[2].name, "aa.bb.cc")
     self.assertEqual(cu[0].flat_rootname(), "aa")
     self.assertEqual(cu[1].flat_rootname(), "aa_bb")
     self.assertEqual(cu[2].flat_rootname(), "aa_bb_cc")
     self.assertEqual(cu[0].source_file().read(), "# aa\n")
     self.assertEqual(cu[1].source_file().read(), "# bb\n")
     self.assertEqual(cu[2].source_file().read(), "")  # yes, empty
 def test_modules(self):
     import aa, aa.bb, aa.bb.cc
     cu = code_unit_factory([aa, aa.bb, aa.bb.cc], FileLocator())
     self.assertEqual(cu[0].name, "aa")
     self.assertEqual(cu[1].name, "aa.bb")
     self.assertEqual(cu[2].name, "aa.bb.cc")
     self.assertEqual(cu[0].flat_rootname(), "aa")
     self.assertEqual(cu[1].flat_rootname(), "aa_bb")
     self.assertEqual(cu[2].flat_rootname(), "aa_bb_cc")
     self.assertEqual(cu[0].source_file().read(), "# aa\n")
     self.assertEqual(cu[1].source_file().read(), "# bb\n")
     self.assertEqual(cu[2].source_file().read(), "")  # yes, empty
Exemple #22
0
    def find_code_units(self, morfs, omit, include):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames.

        See `coverage.report()` for other arguments.

        """
        morfs = morfs or self.coverage.data.executed_files()
        self.code_units = code_unit_factory(morfs, self.coverage.file_locator,
                                            omit, include)
        self.code_units.sort()
 def test_module_files(self):
     import aa.afile, aa.bb.bfile, aa.bb.cc.cfile
     cu = code_unit_factory([aa.afile, aa.bb.bfile, aa.bb.cc.cfile],
                                                             FileLocator())
     self.assertEqual(cu[0].name, "aa.afile")
     self.assertEqual(cu[1].name, "aa.bb.bfile")
     self.assertEqual(cu[2].name, "aa.bb.cc.cfile")
     self.assertEqual(cu[0].flat_rootname(), "aa_afile")
     self.assertEqual(cu[1].flat_rootname(), "aa_bb_bfile")
     self.assertEqual(cu[2].flat_rootname(), "aa_bb_cc_cfile")
     self.assertEqual(cu[0].source_file().read(), "# afile.py\n")
     self.assertEqual(cu[1].source_file().read(), "# bfile.py\n")
     self.assertEqual(cu[2].source_file().read(), "# cfile.py\n")
Exemple #24
0
    def find_code_units(self, morfs, omit, include):
        """Find the code units we'll report on.

        `morfs` is a list of modules or filenames.

        See `coverage.report()` for other arguments.

        """
        morfs = morfs or self.coverage.data.executed_files()
        self.code_units = code_unit_factory(
                            morfs, self.coverage.file_locator, omit, include
                            )
        self.code_units.sort()
Exemple #25
0
 def test_module_files(self):
     import aa.afile, aa.bb.bfile, aa.bb.cc.cfile
     cu = code_unit_factory([aa.afile, aa.bb.bfile, aa.bb.cc.cfile],
                            FileLocator())
     self.assertEqual(cu[0].name, "aa.afile")
     self.assertEqual(cu[1].name, "aa.bb.bfile")
     self.assertEqual(cu[2].name, "aa.bb.cc.cfile")
     self.assertEqual(cu[0].flat_rootname(), "aa_afile")
     self.assertEqual(cu[1].flat_rootname(), "aa_bb_bfile")
     self.assertEqual(cu[2].flat_rootname(), "aa_bb_cc_cfile")
     self.assertEqual(cu[0].source_file().read(), "# afile.py\n")
     self.assertEqual(cu[1].source_file().read(), "# bfile.py\n")
     self.assertEqual(cu[2].source_file().read(), "# cfile.py\n")
    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, 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__)

        cu = code_unit_factory([egg1, egg1.egg1], FileLocator())
        self.assertEqual(cu[0].source_file().read(), "")
        self.assertEqual(cu[1].source_file().read().split("\n")[0],
                "# My egg file!"
                )
Exemple #27
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        def get_plugin(filename):
            """For code_unit_factory to use to find the plugin for a file."""
            plugin = None
            plugin_name = self.data.plugin_data().get(filename)
            if plugin_name:
                plugin = self.plugins.get(plugin_name)
            return plugin

        self._harvest_data()
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator, get_plugin)[0]

        return Analysis(self, it)
Exemple #28
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator)[0]

        try:
            a = Analysis(self, it)
            return a
        except NotPython:
            try:
                if isinstance(it, CodeUnit):
                    it.name = it.filename
                return DjangoTemplateAnalysis(self, it)
            except:
                traceback.print_exc()
Exemple #29
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator)[0]

        try:
            a = Analysis(self, it)
            return a
        except NotPython:
            try:
                if isinstance(it, CodeUnit):
                    it.name = it.filename
                return DjangoTemplateAnalysis(self, it)
            except:
                traceback.print_exc()
Exemple #30
0
    def _analyze(self, it):
        """Analyze a single morf or code unit.

        Returns an `Analysis` object.

        """
        def get_plugin(filename):
            """For code_unit_factory to use to find the plugin for a file."""
            plugin = None
            plugin_name = self.data.plugin_data().get(filename)
            if plugin_name:
                plugin = self.plugins.get(plugin_name)
            return plugin

        self._harvest_data()
        if not isinstance(it, CodeUnit):
            it = code_unit_factory(it, self.file_locator, get_plugin)[0]

        return Analysis(self, it)
Exemple #31
0
 def _analyze(self, it):
     self._harvest_data()
     if not isinstance(it, CodeUnit):
         it = code_unit_factory(it, self.file_locator)[0]
     return Analysis(self, it)
 def _analyze(self, it):
     self._harvest_data()
     if not isinstance(it, CodeUnit):
         it = code_unit_factory(it, self.file_locator)[0]
     return Analysis(self, it)
Exemple #33
0
 def test_egg(self):
     import egg1, egg1.egg1
     cu = code_unit_factory([egg1, egg1.egg1], FileLocator())
     self.assertEqual(cu[0].source_file().read(), "")
     self.assertEqual(cu[1].source_file().read().split("\n")[0],
                      "# My egg file!")