def test_cloc_runs_from_root(self, path_glob): """Make sure that command line call checks it is run from the root.""" self.check_patcher.stop() with self.assertRaises(ValueError) as context: loc.get_cloc() path_glob.assert_called() self.assertIn('git or svn root', str(context.exception))
def test_cloc_reads_files(self): """cloc is called and reads the output csv file.""" actual = loc.get_cloc() self.run_.assert_called_with('cloc --csv --by-file .') usecols = 'language,filename,blank,comment,code'.split(',') expected = pd.read_csv(io.StringIO(self.run_output), usecols=usecols).\ rename(columns={'filename': 'path'}) self.assertEqual(expected, actual)
def test_cloc_reads_files(self): """cloc is called and reads the output csv file.""" actual = loc.get_cloc(utils.FakeProject()) self.run_.assert_called_with("cloc --csv --by-file .".split(), cwd=pl.Path(".")) expected = pd.read_csv( io.StringIO( textwrap.dedent("""\ language,path,blank,comment,code Python,internals.py,55,50,130 Python,tests.py,29,92,109 Python,setup.py,4,2,30 C#,".NETFramework,Version=v4.7.2.AssemblyAttributes.cs",0,1,3 """)), dtype={ "path": "string", "language": "string" }, ) self.assertEqual(expected, actual)
def test_cloc_not_found(self): """Clean error message when cloc is not found in the path.""" self.run_.side_effect = [FileNotFoundError] with self.assertRaises(FileNotFoundError) as context: _ = loc.get_cloc() self.assertIn('cloc', str(context.exception))
def test_cloc_called_with_path(self, run, _): """Make sure the path is passed as argument to cloc when passed to the function.""" loc.get_cloc(utils.FakeProject(), path="some-path") run.assert_called_with(["cloc", "--csv", "--by-file", "some-path"], cwd=pl.Path("."))
def test_cloc_fails_if_not_in_root(self, path_glob): """Make sure that command line call checks it is run from the root.""" with self.assertRaises(ValueError) as context: loc.get_cloc(utils.FakeProject()) path_glob.assert_called_with(pattern=".svn") self.assertIn("git or svn root", str(context.exception))