def test_append(self): #lines 118, 119 appended. actual = [ LineChange(line_number=118, commit_sha=self.new_sha, file_path=self.file_path, change_type=LineChange.ChangeType.added), LineChange(line_number=119, commit_sha=self.new_sha, file_path=self.file_path, change_type=LineChange.ChangeType.added) ] for lc in actual: self.assertIn(lc, self.file_changes)
def test_modify(self): #line 58 (now 59) modified actual = LineChange(line_number=59, commit_sha=self.new_sha, file_path=self.file_path, change_type=LineChange.ChangeType.modified) self.assertIn(actual, self.file_changes)
def test_prepend(self): # First line prepended actual = LineChange(line_number=1, commit_sha=self.new_sha, file_path=self.file_path, change_type=LineChange.ChangeType.added) self.assertIn(actual, self.file_changes)
def test_changes_file2(self): file = "README.md" new_sha = None single_file_changes = [ c for c in self.file_changes if c.file_path == file ] # Inserted lines 25 and 26 expected = [ LineChange(line_number=25, commit_sha=new_sha, file_path=file, change_type=LineChange.ChangeType.added), LineChange(line_number=26, commit_sha=new_sha, file_path=file, change_type=LineChange.ChangeType.added) ] for e in expected: self.assertIn(e, single_file_changes)
def test_changes_file1(self): file = "Gemfile" new_sha = None single_file_changes = [ c for c in self.file_changes if c.file_path == file ] # line 1 prepended, line 37 (now 38) and line 40 (now 41) modified expected = [ LineChange(line_number=1, commit_sha=new_sha, file_path=file, change_type=LineChange.ChangeType.added), LineChange(line_number=38, commit_sha=new_sha, file_path=file, change_type=LineChange.ChangeType.modified), LineChange(line_number=41, commit_sha=new_sha, file_path=file, change_type=LineChange.ChangeType.modified) ] for e in expected: self.assertIn(e, single_file_changes)
def _find_intersing_line(self, file, line_n, linechange, offset, step): p = offset while not self.has_been_changed(line_n + p, file, linechange.commit_sha) and \ not self.is_interesting(self.blame_data[file][linechange.commit_sha].file_data[line_n + p]): p += step if line_n + p < 1 or line_n + p > len( self.blame_data[file][linechange.commit_sha].file_data): return None if not self.has_been_changed(line_n + p, file, linechange.commit_sha): return LineChange(line_n + p, LineChange.ChangeType.interesting, file, linechange.commit_sha) else: return None
def test_custom_ne(self): self.assertNotEqual(LineChange(), LineChange(line_number='1'))
def test_custom_eq(self): self.assertEqual(LineChange(), LineChange())