示例#1
0
 def test_path(self, mock_subproc_call):
     """ Function to test the path setting """
     mock_subproc_call.return_value = True
     cycloeagleobj = CyclomaticEagle()
     cycloeagleobj.orchestrate_cyclomatic(TestResource.input_json)
     cycloeagleobj.orchestrate_cyclomatic(TestResource.input_json)
     self.assertEqual(
         cycloeagleobj.report_path,
         os.path.join(TestResource.report, "cyclomatic_report"))
     self.assertTrue(mock_subproc_call.called)
示例#2
0
 def test_cmd_no_exclude(self, mock_subproc_call):
     """ Function to verify the command generation with out excludes """
     mock_subproc_call.return_value = False
     cycloeagleobj = CyclomaticEagle()
     data = {**TestResource.input_json, 'cyclo_exclude': [None]}
     cycloeagleobj.orchestrate_cyclomatic(data)
     self.assertTrue(mock_subproc_call.called)
     self.assertEqual(
         cycloeagleobj.cmd.replace("/", os.sep),
         'python -m lizard "%s" -l java  -l python  --csv' %
         TestResource.tst_resource_folder)
示例#3
0
 def test_fail(self, mock_subproc_call):
     """ Function to test the  subprocess command fail """
     mock_subproc_call.return_value = True
     cycloeagleobj = CyclomaticEagle()
     cycloeagleobj.orchestrate_cyclomatic(TestResource.input_json)
     out_str = (sys.stdout.getvalue().split('\n'))
     matches = [
         c for c in out_str
         if 'There was error while processing the sub process command' in c
     ]
     self.assertEqual(
         matches[0],
         'There was error while processing the sub process command')
     self.assertEqual(
         False,
         os.path.isfile(
             os.path.join(TestResource.report, "cyclomatic_report",
                          "cyclomatic-complexity-report.html")))
示例#4
0
    def test__init_cmd_path(self, mock_subproc_call):
        """ Function to test the default init , command forming, and path creation"""
        mock_subproc_call.return_value = False
        self.dummy_dataf()
        cycloeagleobj = CyclomaticEagle()

        self.assertEqual(cycloeagleobj.cmd, "")
        self.assertEqual(cycloeagleobj.report_path, None)

        cycloeagleobj.orchestrate_cyclomatic(TestResource.input_json)

        self.assertEqual(
            cycloeagleobj.cmd.replace("/", os.sep),
            'python -m lizard "%s" -l java  -l python  -x "*.cpp", -x "*.java" --csv'
            % TestResource.tst_resource_folder)
        self.assertEqual(
            cycloeagleobj.report_path,
            os.path.join(TestResource.report, "cyclomatic_report"))
        self.assertTrue(mock_subproc_call.called)
示例#5
0
    def test_report_file_generation_content(self):
        """ Function to test the report file generation from the csv generated from command out """
        cycloeagleobj = CyclomaticEagle()
        self.dummy_dataf()
        with mock.patch.object(CyclomaticEagle,
                               '_CyclomaticEagle__subprocess_out',
                               return_value=False):
            mock.return_value = False
            cycloeagleobj.orchestrate_cyclomatic(TestResource.input_json)

            self.assertEqual(
                True,
                os.path.isfile(
                    os.path.join(TestResource.report, "cyclomatic_report",
                                 "cyclomatic-complexity-report.html")))
            self.assertEqual(
                True,
                os.path.isfile(
                    os.path.join(TestResource.report, "cyclomatic_report",
                                 "cyclomatic-complexity.csv")))
            data_frame = pd.read_html(
                os.path.join(TestResource.report, "cyclomatic_report",
                             "cyclomatic-complexity-report.html"))
            data_frame = pd.concat(data_frame)
            data_frame.drop(data_frame.columns[0], axis=1, inplace=True)
            data_frame_report = self.dummy_dataf()
            data_frame_report.columns = [
                "NLOC", "CCN", "Token", "Param", "Length", "Location", "Path",
                "Function", "Args", "Row", "Col"
            ]
            data_frame_report.sort_values('CCN', ascending=False, inplace=True)
            data_frame_report.drop(['Path', 'Function', 'Row', 'Col'],
                                   axis=1,
                                   inplace=True)
            self.assertTrue(
                np.array_equal(data_frame.values, data_frame_report.values))
示例#6
0
 def __eaglewatch_cyclo__(json):
     """ Function which invokes the Cyclomatic complexity class for analysis """
     cyclomaticeagleobj = CyclomaticEagle()
     cyclomaticeagleobj.orchestrate_cyclomatic(json)