def test_get_commit_details(self): git_executor = MockGitExecutor('''log --show-notes=test-ref -n 1 --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N" 1111''', ['hash,1111,shorthash,2222,commiter,Unit Test <*****@*****.**>,date,1371047821|__NOTE__|test note']) git_utils = GitUtils(git_executor) commit_details = git_utils.get_commit_details('test-ref', '1111') expected_details = {'date': '1371047821', 'note': 'test note', 'commiter': 'Unit Test <*****@*****.**>', 'shorthash': '2222', 'hash': '1111'}; self.assertDictEqual(expected_details, commit_details)
def test_get_notes_with_commit_when_git_fails(self): git_executor = MockGitExecutor('notes --ref=test-ref show notes_commit1', ['error: No note found for object notes_commit1.'], 1) git_utils = GitUtils(git_executor) self.assertRaisesRegex(MockedGitException, 'Return code expected to be 0 but was 1.', git_utils.get_notes,'test-ref', 'notes_commit1')
def test_get_notes_with_commit(self): test_note = 'test note' git_executor = MockGitExecutor('notes --ref=test-ref show notes_commit1',[test_note]) git_utils = GitUtils(git_executor) retrieved_note = git_utils.get_notes('test-ref', 'notes_commit1') self.assertEqual(test_note, retrieved_note)
def test_get_config_by_key(self): git_log_cmd = 'config --get {}' key = 'just.a.key' git_executor = MockGitExecutor() \ .expect_call(git_log_cmd.format(key), ['a value']) git_utils = GitUtils(git_executor) data = git_utils.get_config_by_key(key) self.assertEqual('a value', data)
def test_get_latest_annotated_commit(self): git_log_cmd = 'log --show-notes=test-ref -n {0} --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N"' git_executor = MockGitExecutor() \ .expect_call(git_log_cmd.format(30000), ['', 'key01,value01,key02,value02|__NOTE__|note01', 'ignore me', 'no,note,here,dude|__NOTE__|', 'key11,value11,key12,value12|__NOTE__|note02']) git_utils = GitUtils(git_executor) commit = git_utils.latest_annotated_commit_with_details('test-ref') self.assertDictEqual({'note': 'note01', 'key01':'value01', 'key02': 'value02'}, commit)
def test_generate_annotated_commits_with_details(self): git_log_cmd = 'log --show-notes=test-ref -n {0} --pretty=format:"hash,%H,shorthash,%h,commiter,%an <%ae>,date,%at|__NOTE__|%N"' git_executor = MockGitExecutor()\ .expect_call(git_log_cmd.format(100), ['key01,value01,key02,value02|__NOTE__|note01', 'key11,value11,key12,value12|__NOTE__|note02']) git_utils = GitUtils(git_executor) commits_generator = git_utils.generate_annotated_commits_with_details('test-ref', 100) self.assertDictEqual({'note': 'note01', 'key01':'value01', 'key02': 'value02'}, next(commits_generator)) self.assertDictEqual({'note': 'note02', 'key11':'value11', 'key12': 'value12'}, next(commits_generator)) self.assertIteratorFinished(commits_generator)
def __init__(self, git: GitUtils = GitUtils(), fs: FileUtils = FileUtils(), metrics_processor=MetricsProcessor(), json_writer=JsonWriter()): super().__init__() self.command = 'eh-metrics' self.prevent_post_diagnostics = True self.description = 'Gathers engineering health metrics from the JIRA code. If any violations occur, you will be ' \ 'able to add exclusion information interactively. You should pull all latest changes ' \ 'before you run this.' self.git = git self.fs = fs self.metrics_processor = metrics_processor self.json_writer = json_writer