コード例 #1
0
 def test_analysis_empty_input_return_empty_output(self, _):
     """Empty input returns and empty dataframe."""
     self.log = self.log.iloc[:0]
     actual = cm.get_complexity(self.log, scm.Project())
     # Length may be at the end or in the middle dependeding on the version of lizard.
     self.assertEqual(sorted(actual.columns), sorted(self.expected.columns))
     self.assertEqual(len(actual), 0)
コード例 #2
0
 def test_use_default_download(self):
     """When the context.downlad_funcc is defined, use it."""
     project = scm.Project()
     with mock.patch.object(
         scm.Project, "download", return_value=scm.DownloadResult(1, "/", "")
     ) as download:
         _ = cm.get_complexity(self.log, project)
         download.assert_called_with(self.log)
コード例 #3
0
    def test_handles_no_function(self):
        """Handles files with no function well."""
        file_name, rev = 'f.py', 1

        def scm_download_files(path_rev_df):
            return [cm.scm.FileDownloadResult(file_name, rev, '')]

        sublog = pd.DataFrame({'revision': [rev], 'path': [file_name]})
        actual = cm.get_complexity(sublog, download_func=scm_download_files)
        expected_fields = cm.core._lizard_fields + \
                          'file_tokens file_nloc path revision'.split()
        expected = pd.DataFrame(data={k: [] for k in expected_fields})
        self.assertEqual(expected, actual)
コード例 #4
0
 def test_handles_no_function(self):
     """Handles files with no function well."""
     columns = (
         "function".split()
         + cm.core._lizard_fields
         + "file_tokens file_nloc length".split()
     )
     project = scm.Project()
     with mock.patch.object(
         scm.Project,
         "download",
         autospec=True,
         return_value=scm.DownloadResult(1, "f.py", ""),
     ) as download:
         actual = (
             cm.get_complexity(self.log, project)
             .reset_index()
             .pipe(pd.Series.astype, "string")
         )
         download.assert_called_with(project, self.log)
     expected = pd.DataFrame(data={k: [] for k in columns}, dtype="string")
     self.assertEqual(expected, actual)
コード例 #5
0
    def test_simple_analysis(self):
        """Runs complexity trend analysis on this file."""
        def scm_download_files(path_revision_df):
            return [
                cm.scm.FileDownloadResult('f.py', 1, self.file_content_1),
                cm.scm.FileDownloadResult('f.py', 2, self.file_content_2)
            ]

        sublog = pd.read_csv(
            io.StringIO(
                textwrap.dedent("""\
        revision,author,date,textmods,kind,action,propmods,path,message
        1,elmotec,2018-02-26T10:28:00Z,true,file,M,false,f.py,again
        2,elmotec,2018-02-24T11:14:11Z,true,file,M,false,f.py,modified""")))
        actual = cm.get_complexity(sublog, download_func=scm_download_files)
        expected = pd.read_csv(
            io.StringIO(
                textwrap.dedent("""\
        cyclomatic_complexity,nloc,token_count,name,long_name,start_line,end_line,top_nesting_level,length,fan_in,fan_out,general_fan_out,file_tokens,file_nloc,path,revision
        2,4,16,test,test( ),1,4,0,4,0,0,0,17,4,f.py,1
        1,2,8,test,test( ),1,2,0,2,0,0,0,9,2,f.py,2""")))
        self.assertEqual(expected.columns.tolist(), actual.columns.tolist())
        self.assertEqual(expected, actual)
コード例 #6
0
 def test_analysis_empty_input_return_empty_output(self, _):
     """Empty input returns and empty dataframe."""
     self.log = self.log.iloc[:0]
     actual = cm.get_complexity(self.log, utils.FakeProject())
     self.assertEqual(list(actual.columns), list(self.expected.columns))
     self.assertEqual(len(actual), 0)