Example #1
0
 def setUp(self):
     xml_parser = etree.XMLParser(remove_comments=True)
     self.tree = etree.parse("samples/sample.xml", parser=xml_parser)
     self.rules_tree = etree.parse(
         "samples/rules_sample.xml", parser=xml_parser
     )
     self.test_file = files.File(r"STV\Trieuse\stv\src\ttpdsext.c")
Example #2
0
    def test_load_specific_rules(self):
        """ test for the load_specific_rules method """
        with self.assertRaises(rules_reader.BadRulesFormat):
            self.test_file.load_specific_rules(self.tree)

        no_rules_files = files.File(r"STV\Trieuse\stv\src\vcscope.c")
        no_rules_files.load_specific_rules(self.rules_tree)
        # Rules did not change from default rules
        self.assertDictEqual(
            no_rules_files.rules._metrics,  # pylint: disable=protected-access
            {
                "M0": 0, "M1": 0, "M2": 0, "M3": 0, "M4": 0,
                "M5": 0, "M6": 0, "M7": "disable", "M8": 0, "M9": 0,
                "M10": 0, "M11": 0, "M12": 0
            }
        )

        # specific rules
        self.test_file.load_specific_rules(self.rules_tree)
        self.assertDictEqual(
            self.test_file.rules._metrics,  # pylint: disable=protected-access
            {
                "M0": "disable", "M1": "disable", "M2": "disable",
                "M3": 1, "M4": "disable", "M5": "disable",
                "M6": "disable", "M7": "disable", "M8": "disable",
                "M9": "disable", "M10": "disable", "M11": "disable",
                "M12": "disable"
            }
        )
Example #3
0
 def setUp(self):
     self.test_report = reports.Report()
     # declaring all files
     self.test_files = set(
         [files.File("test_file.c"),
          files.File("second.c")])
     for file_ in self.test_files:
         file_.validity = False
     # declaring all functions
     self.functions = {
         "test_file.c": functions.Function("test_file.c", "func"),
         "second.c": functions.Function("second.c", "second")
     }
     self.functions["test_file.c"].validity = False
     self.functions["second.c"].validity = False
     # adding one function to each file
     for file_ in self.test_files:
         file_.functions.add(self.functions[file_.name])
Example #4
0
    def load_files(self):
        """
            Load all the files of the last source-monitor checkpoint
        """
        files_tree = smreader.all_file_pathfinder()(self.sm_tree)[0]
        for file_tree in files_tree:
            # Creating the file and loading all his data
            # print("adding", file_tree.get("file_name"))
            add_file = files.File(file_tree.get("file_name"))
            add_file.load(self.sm_tree, self.rules_tree)

            # Finally add it to the files set
            self.files.add(add_file)
Example #5
0
    def test_search_file_tree(self):
        """
            Test for the search_tree method used to search a specific
            function's tree
        """
        my_bad_file = files.File(r"STV\Trieuse\stv\src\kldslkd.c")
        with self.assertRaises(files.FileNotFound):
            my_bad_file.search_file_tree(self.tree)

        # We can't test all the equality on the tree (too big)
        # So we test that it seems to be a source-monitor file tree
        file_tree = self.test_file.search_file_tree(self.tree)
        self.assertEqual(len(file_tree), 3)
        self.assertEqual(file_tree[0].tag, "metrics")
        self.assertEqual(file_tree[1].tag, "function_metrics")
        self.assertEqual(file_tree[2].tag, "block_depths")
Example #6
0
    def test_load_functions(self):
        """ test for the load_functions method """
        self.test_file.load_functions(self.tree)

        # All functions are here
        self.assertNotEqual(self.test_file.functions, None)
        self.assertEqual(len(self.test_file.functions), 6)
        for function in self.test_file.functions:
            self.assertIn(function.name, {
                "initttpdsext()", "majtabpdsext()", "progexplttpdsext()",
                "proginterttpdsext()", "razttpdsext()", "recuppdsext()"
            })
            self.assertNotEqual(function.metrics, None)  # metrics are loaded

        # a file with no function doesn't have 'function_metrics' block in the
        # source-monitor report ...
        header_file = files.File(r"STV\Trieuse\stv\src\ttpdsext.h")
        header_file.load_functions(self.tree)
        self.assertEqual(len(header_file.functions), 0)
Example #7
0
    def test_load_metrics(self):
        """ test the load_metrics method """
        # The asked file doesn't exist in the sample file
        my_bad_file = files.File(r"STV\Trieuse\stv\src\ttdsext.c")
        with self.assertRaises(files.FileNotFound):
            my_bad_file.load_metrics(self.tree)

        self.test_file.load_metrics(self.tree)
        self.assertEqual(self.test_file.metrics.get("M0"), 461)
        self.assertEqual(self.test_file.metrics.get("M1"), 289)
        self.assertEqual(self.test_file.metrics.get("M2"), 24.6)
        self.assertEqual(self.test_file.metrics.get("M3"), 16.3)
        self.assertEqual(self.test_file.metrics.get("M4"), 6)
        self.assertEqual(self.test_file.metrics.get("M5"), 42.7)
        self.assertEqual(self.test_file.metrics.get("M6"), 88)
        self.assertEqual(
            self.test_file.metrics.get("M7"), "progexplttpdsext()"
        )
        self.assertEqual(self.test_file.metrics.get("M8"), 78)
        self.assertEqual(self.test_file.metrics.get("M9"), 328)
        self.assertEqual(self.test_file.metrics.get("M10"), "9+")
        self.assertEqual(self.test_file.metrics.get("M11"), 5.51)
        self.assertEqual(self.test_file.metrics.get("M12"), 17.0)