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)
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)
def get_complexity(self): """Factor retrieval of complexity""" project = scm.Project() with mock.patch.object( scm.Project, "download", autospec=True, side_effect=[ scm.DownloadResult("r1", "f.py", self.file_content_1), scm.DownloadResult("r2", "f.py", self.file_content_2), ], ) as download: df = self.log.groupby(["revision", "path"]).apply( cm.get_complexity, project ) self.assertEqual( download.call_args_list, [mock.call(project, mock.ANY)] * 2 ) return df
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)
def test_project_download_returns_none(self): """scm.Project download() method returns None.""" download_result = scm.Project(".").download(pd.DataFrame()) self.assertIsNone(download_result)
def test_project_get_log_returns_expected_columns(self): """scm.Project.get_log() method returns a pd.DataFrame with the right columns.""" actual = cm.get_log(scm.Project(".")) self.assertIsInstance(actual, pd.DataFrame) self.assertEqual(actual.columns.tolist(), scm.LogEntry.__slots__)
def setUp(self): self.project = scm.Project()