def test_master_changes(self): opts = __parse_arguments__(args=[ '--silent', '--branch', 'master', 'build/tests/basic-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) r.process() # Test number of commits self.assertEqual(len(r.changes.all_commits()), 4) # 4 commits, no merges self.assertEqual(len(r.changes.relevant_commits()), 4) self.assertEqual(len(r.changes.merge_commits()), 0) l_commits = [ c for c in r.changes.all_commits() if c.author == "Abraham Lincoln" ] self.assertEqual(len(l_commits), 1) # 1 commits j_commits = [ c for c in r.changes.all_commits() if c.author == "Andrew Johnson" ] self.assertEqual(len(j_commits), 3) # 3 commits # Test insertions and deletions authorinfos = r.changes.get_authorinfo_list() self.assertEqual(len(authorinfos), 2) # 2 authors abe_commits = authorinfos[('Abraham Lincoln', '*****@*****.**')] self.assertEqual(abe_commits.commits, 1) self.assertEqual(abe_commits.insertions, 1) # 1 self.assertEqual(abe_commits.deletions, 0) and_commits = authorinfos[('Andrew Johnson', '*****@*****.**')] self.assertEqual(and_commits.commits, 3) self.assertEqual(and_commits.insertions, 50) # 10 + 34 + 6 self.assertEqual(and_commits.deletions, 0)
def test_all_blames_with_spaces(self): opts = __parse_arguments__(args=[ '--silent', # '-b', 'master' '-W', 'build/tests/trie-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) r.process() # Count the blames in the README r_blames = r.blames.blames_for_file("README") self.assertEqual(len(r_blames), 1) r_blames_1 = r_blames[0] self.assertEqual(r_blames_1[0][0], "Frodo Baggins") self.assertEqual(r_blames_1[1], 8) # 8 lines from Frodo # Count the blames in src/trie.c t_blames = r.blames.blames_for_file("src/trie.c") self.assertEqual(len(t_blames), 5) # 5 authors t_blames_1 = [t for t in t_blames if t[0][0] == "Frodo Baggins"][0] self.assertEqual(t_blames_1[1], 41) t_blames_2 = [t for t in t_blames if t[0][0] == "Peregrin Took"][0] self.assertEqual(t_blames_2[1], 56) t_blames_3 = [t for t in t_blames if t[0][0] == "Bilbo Baggins"][0] self.assertEqual(t_blames_3[1], 109)
def test_process(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--branch', 'master', '--file-types', '*.c,*.txt,Make*', '--exclude', 'author:Abraham Lincoln,file_out:Makefile', '--since', '2001-01-01', '--until', '2020-01-01', '--silent', 'build/tests/basic-repository' ]) opts.progress = False # 1 commit is excluded from the author "Abraham Lincoln" # 1 file is filtered because it only applies to the "Makefile" # Launch runner r = Runner(opts, None) r.process() # Check the repositories self.assertEqual(len(r.repos), 1) self.assertEqual(r.repos[0].name, "basic-repository") self.assertTrue( r.repos[0].location.endswith("build/tests/basic-repository")) authors = r.repos[0].authors() authors.sort() self.assertEqual( authors, ['Abraham Lincoln <*****@*****.**>', 'Andrew Johnson <*****@*****.**>']) # Check the commits rel_commits = r.changes.relevant_commits() self.assertEqual(len(rel_commits), 3) # 4 commits, 1 excluded all_commits = r.changes.all_commits() self.assertEqual(len(all_commits), 4) # 4 commits, 1 excluded authors = sorted(list(map(lambda c: c.author, rel_commits))) self.assertEqual(authors[0], "Andrew Johnson") filtered_files = r.changes.filtered_files( ('Andrew Johnson', '*****@*****.**')) self.assertEqual(len(filtered_files), 1) self.assertEqual(list(filtered_files)[0], "Makefile") # Check the blames blames = r.blames.all_blames() self.assertEqual(len(blames.keys()), 1) blame_keys = sorted(list(blames.keys())) self.assertEqual(blame_keys[0], (('Andrew Johnson', '*****@*****.**'), 'file.c')) self.assertEqual(blames[blame_keys[0]].rows, 40) # file.c is 40 lines long # Check the metrics self.assertEqual(r.metrics.eloc, {}) # Both files are too short, no metrics to report
def test_process(self): # Set options opts = __parse_arguments__(args=['--grading', '--legacy', '--file-types', '*.c,*.h', '--silent', 'build/tests/trie-repository']) opts.progress = False # Launch runner r = Runner(opts, None) r.process()
def test_process(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--branch', 'master', '--file-types', '*.c,*.txt,Makefile', '--exclude', 'author:John Doe', '--silent', 'build/tests/basic-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) r.process() # Check the repositories self.assertEqual(len(r.repos), 1) self.assertEqual(r.repos[0].name, "basic-repository") self.assertTrue( r.repos[0].location.endswith("build/tests/basic-repository")) authors = r.repos[0].authors() authors.sort() self.assertEqual( authors, ['Abraham Lincoln <*****@*****.**>', 'Andrew Johnson <*****@*****.**>']) # Check the commits self.assertEqual(len(r.changes.all_commits()), 4) authors = sorted(list(map(lambda c: c.author, r.changes.all_commits()))) self.assertEqual(authors[0], "Abraham Lincoln") self.assertEqual(authors[1], "Andrew Johnson") # Check the blames blames = r.blames.all_blames() self.assertEqual(len(blames.keys()), 3) blame_keys = sorted(list(blames.keys())) self.assertEqual(blame_keys[0], (('Abraham Lincoln', '*****@*****.**'), 'README.txt')) self.assertEqual(blame_keys[1], (('Andrew Johnson', '*****@*****.**'), 'Makefile')) self.assertEqual(blame_keys[2], (('Andrew Johnson', '*****@*****.**'), 'file.c')) self.assertEqual(blames[blame_keys[0]].rows, 1) # README.txt is 1 line long self.assertEqual(blames[blame_keys[1]].rows, 10) # Makefile is 10 lines long self.assertEqual(blames[blame_keys[2]].rows, 40) # file.c is 40 lines long # Check the metrics self.assertEqual(r.metrics.eloc, {}) # Both files are too short, no metrics to report
def test_small_changes(self): opts = __parse_arguments__(args=[ '--silent', '--since=2015-10-20', '--until=2015-10-22', 'build/tests/trie-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) # Test number of commits r.process() self.assertEqual(len(r.changes.all_commits()), 5) # 4 commits + 1 merge self.assertEqual(len(r.changes.code_commits()), 4) self.assertEqual(len(r.changes.merge_commits()), 1) b_commits = [ c for c in r.changes.all_commits() if c.author == "Bilbo Baggins" ] self.assertEqual(len(b_commits), 4) # 3 commits + 1 merge self.assertEqual( len([c for c in b_commits if c.type == CommitType.CODE]), 3) self.assertEqual( len([c for c in b_commits if c.type == CommitType.MERGE]), 1) f_commits = [ c for c in r.changes.all_commits() if c.author == "Frodo Baggins" ] self.assertEqual(len(f_commits), 0) # 0 commits s_commits = [ c for c in r.changes.all_commits() if c.author == "Samwise Gamgee" ] self.assertEqual(len(s_commits), 1) # 1 commits # Test insertions and deletions authorinfos = r.changes.get_authorinfo_list() bilbo_commits = authorinfos[('Bilbo Baggins', '*****@*****.**')] self.assertEqual(bilbo_commits.commits, 4) self.assertEqual(bilbo_commits.insertions, 14) # 3 + 7 + 4 self.assertEqual(bilbo_commits.deletions, 8) # 4 + 0 + 4 sam_commits = authorinfos[('Samwise Gamgee', '*****@*****.**')] self.assertEqual(sam_commits.commits, 1) self.assertEqual(sam_commits.insertions, 41) # 41 (22+19) self.assertEqual(sam_commits.deletions, 0)
def test_output_html(self): # Set options opts = __parse_arguments__(args=['--grading', '--legacy', '--file-types', '*.c,*.h', '--format', 'html', 'build/tests/trie-repository']) opts.progress = False # Launch runner localization.init_null() file = tempfile.NamedTemporaryFile('w', delete=False) r = Runner(opts, FileWriter(file)) r.process() with open(file.name, 'r') as f: contents = f.read() self.assertTrue("Statistical information" in contents) self.assertTrue("The following history timeline" in contents) os.remove(file.name)
def test_output_json(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--file-types', '*.py', '--format', 'json', 'build/tests/pelican-repository' ]) opts.progress = False # Launch runner localization.init_null() file = tempfile.NamedTemporaryFile('w', delete=False) r = Runner(opts, FileWriter(file)) r.process() with open(file.name, 'r') as f: contents = f.read() self.assertTrue("The following historical commit" in contents) self.assertTrue("Below are the number of rows" in contents) self.assertTrue("The following history timeline" in contents) os.remove(file.name)
def test_output_xml(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--file-types', '*.c,*.txt', '--exclude', 'author:Abraham Lincoln', '--since', '2001-01-01', '--until', '2020-01-01', '--format', 'xml', 'build/tests/basic-repository' ]) opts.progress = False # Launch runner localization.init_null() file = tempfile.NamedTemporaryFile('w', delete=False) r = Runner(opts, FileWriter(file)) r.process() with open(file.name, 'r') as f: contents = f.read() self.assertTrue("The following historical commit" in contents) self.assertTrue("Below are the number of rows" in contents) self.assertTrue("The following history timeline" in contents) os.remove(file.name)
def test_output_text(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--file-types', '.*\.c,.*\.txt', '--exclude', 'author:John Doe', '--format', 'text', 'build/tests/basic-repository' ]) opts.progress = False # Launch runner localization.init_null() file = tempfile.NamedTemporaryFile('w', delete=False) r = Runner(opts, FileWriter(file)) r.process() with open(file.name, 'r') as f: contents = f.read() self.assertTrue("Statistical information" in contents) self.assertTrue("The following historical commit" in contents) self.assertTrue("Below are the number of rows" in contents) os.remove(file.name)
def test_all_changes(self): opts = __parse_arguments__( args=['--silent', 'build/tests/trie-repository']) opts.progress = False # Launch runner r = Runner(opts, None) r.process() self.assertEqual(len(r.changes.commits), 29) # 29 commits + 2 merges b_commits = [ c for c in r.changes.commits if c.author == "Bilbo Baggins" ] self.assertEqual(len(b_commits), 11) # 11 commits + 1 merge f_commits = [ c for c in r.changes.commits if c.author == "Frodo Baggins" ] self.assertEqual(len(f_commits), 6) # 6 commits s_commits = [ c for c in r.changes.commits if c.author == "Samwise Gamgee" ] self.assertEqual(len(s_commits), 6) # 6 commits + 1 merge
def test_process(self): # Set options opts = __parse_arguments__(args=[ '--grading', '--legacy', '--branch', 'master', '--file-types', '*.c,*.txt', '--exclude', 'author:Abraham Lincoln,message:README', '--since', '2001-01-01', '--until', '2020-01-01', '--silent', 'build/tests/basic-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) r.process() # Check the repositories self.assertEqual(len(r.repos), 1) self.assertEqual(r.repos[0].name, "basic-repository") self.assertTrue( r.repos[0].location.endswith("build/tests/basic-repository")) self.assertEqual( r.repos[0].authors(), ['Abraham Lincoln <*****@*****.**>', 'Andrew Johnson <*****@*****.**>']) # Check the commits self.assertEqual(len(r.changes.commits), 1) authors = sorted(list(map(lambda c: c.author, r.changes.commits))) self.assertEqual(authors[0], "Andrew Johnson") # Check the blames self.assertEqual(len(r.blames.blames.keys()), 1) blame_keys = sorted(list(r.blames.blames.keys())) self.assertEqual(blame_keys[0], (('Andrew Johnson', '*****@*****.**'), 'file.c')) self.assertEqual(r.blames.blames[blame_keys[0]].rows, 6) # main.c is 6 lines long # Check the metrics self.assertEqual(r.metrics.eloc, {}) # Both files are too short, no metrics to report
def test_small_changes(self): opts = __parse_arguments__(args=[ '--silent', '--since=2015-10-20', '--until=2015-10-22', 'build/tests/trie-repository' ]) opts.progress = False # Launch runner r = Runner(opts, None) r.process() self.assertEqual(len(r.changes.commits), 4) # 4 commits + 1 merge b_commits = [ c for c in r.changes.commits if c.author == "Bilbo Baggins" ] self.assertEqual(len(b_commits), 3) # 3 commits + 1 merge f_commits = [ c for c in r.changes.commits if c.author == "Frodo Baggins" ] self.assertEqual(len(f_commits), 0) # 0 commits s_commits = [ c for c in r.changes.commits if c.author == "Samwise Gamgee" ] self.assertEqual(len(s_commits), 1) # 1 commits
def test_all_changes(self): opts = __parse_arguments__( args=['--silent', 'build/tests/trie-repository']) opts.progress = False # Launch runner r = Runner(opts, None) r.process() # Test number of commits self.assertEqual(len(r.changes.all_commits()), 31) # 29 commits + 2 merges self.assertEqual(len(r.changes.code_commits()), 29) self.assertEqual(len(r.changes.merge_commits()), 2) b_commits = [ c for c in r.changes.all_commits() if c.author == "Bilbo Baggins" ] self.assertEqual(len(b_commits), 12) # 11 commits + 1 merge self.assertEqual( len([c for c in b_commits if c.type == CommitType.CODE]), 11) self.assertEqual( len([c for c in b_commits if c.type == CommitType.MERGE]), 1) f_commits = [ c for c in r.changes.all_commits() if c.author == "Frodo Baggins" ] self.assertEqual(len(f_commits), 6) # 6 commits s_commits = [ c for c in r.changes.all_commits() if c.author == "Samwise Gamgee" ] self.assertEqual(len(s_commits), 7) # 6 commits + 1 merge self.assertEqual( len([c for c in s_commits if c.type == CommitType.CODE]), 6) # Test insertions and deletions authorinfos = r.changes.get_authorinfo_list() self.assertEqual(len(authorinfos), 5) # 5 authors