Пример #1
0
    def get_all_commits(self, target, settings):
        # git log --all --abbrev=7 --pretty=format:"%h|%p|%an|%ai|%s"
        try:
            merges_map = GitWrapper.get_merges_map()

            format_str = GitWrapper.LOG_SEPARATOR.join(GitWrapper.LOG_FORMAT)
            git_cmd = ['git', 'log', '--all', '--abbrev={}'.format(GitWrapper.COMMIT_LEN),
                       '--pretty=format:{}'.format(format_str)]
            lines = Executor.exec_cmd_only_success(git_cmd).split('\n')

            branches_multimap = GitWrapper.branches_multimap()

            wf = Workflow(target, merges_map, branches_multimap)
            for line in lines:
                items = line.split(GitWrapper.LOG_SEPARATOR, len(GitWrapper.LOG_FORMAT))
                assert len(items) == 5, 'Git wrapper: git log format has {} items, 5 expected'.format(len(items))
                hash, parent_hash, name, date, comment = items

                commit = Commit(hash, parent_hash, name, date, comment,
                                *self.was_target_changed(hash, target, settings),
                                branch_tips=branches_multimap.get(hash))
                wf.add_commit(commit)

            return wf
        except ExecutorError:
            raise
Пример #2
0
    def collapse_metric_commit_test(self):
        value = 0.812345
        branches = ['master', 'try_smth']
        metric_commit2 = Commit('2', '1', 'name1', 'today', 'DVC repro-run ...',
                                True, value, branch_tips=branches)

        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(metric_commit2)
        wf.add_commit(self._commit3)

        self.assertEqual(len(wf._commits), 3)
        wf.collapse_commits(CollapseDvcReproCommitsStrategy(wf))
        self.assertEqual(len(wf._commits), 2)

        self.assertEqual(wf._commits['3']._target_metric, value)
        self.assertEqual(wf._commits['3'].branch_tips, branches)
        pass
Пример #3
0
    def collapse_at_dead_end_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3)  # Dead end which cannot be collapsed

        self.assertEqual(len(wf._commits), 3)
        wf.collapse_repro_commits()
        self.assertEqual(len(wf._commits), 2)

        self.assertEqual(wf._commits[self._commit1.hash].text,
                         self._commit1._comment + '\n' + self._commit1.hash)
        self.assertEqual(wf._commits[self._commit3.hash].text,
                         Commit.COLLAPSED_TEXT)
        self.assertTrue('2' not in wf._commits)
        pass
Пример #4
0
    def collapse_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3)
        wf.add_commit(self._commit4)

        wf.collapse_commits(CollapseDvcReproCommitsStrategy(wf))

        self.assertEqual(len(wf._commits), 3)
        self.assertEqual(wf._commits[self._commit1.hash].text(), self._showed_text1)
        self.assertEqual(wf._commits[self._commit3.hash].text(), self._showed_text3_collapsed)
        self.assertTrue('2' not in wf._commits)

        self.assertFalse('2' in wf._edges)
        self.assertFalse('2' in wf._back_edges)
        pass
Пример #5
0
    def collapse_at_dead_end_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3) # Dead end which cannot be collapsed

        self.assertEqual(len(wf._commits), 3)
        wf.collapse_commits(CollapseDvcReproCommitsStrategy(wf))
        self.assertEqual(len(wf._commits), 2)

        self.assertTrue('1' in wf._commits)
        self.assertTrue('3' in wf._commits)
        self.assertFalse('2' in wf._commits)

        self.assertEqual(wf._commits[self._commit1.hash].text(), self._showed_text1)
        self.assertEqual(wf._commits[self._commit3.hash].text(), self._showed_text3)
        self.assertTrue('2' not in wf._commits)
        pass
Пример #6
0
    def collapse_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3)
        wf.add_commit(self._commit4)

        wf.collapse_repro_commits()

        self.assertEqual(len(wf._commits), 3)
        self.assertEqual(wf._commits[self._commit1.hash].text,
                         self._commit1._comment + '\n' + self._commit1.hash)
        self.assertEqual(wf._commits[self._commit3.hash].text,
                         Commit.COLLAPSED_TEXT)
        self.assertTrue('2' not in wf._commits)

        self.assertFalse('2' in wf._edges)
        self.assertFalse('2' in wf._back_edges)
        pass
Пример #7
0
    def workflow_basic_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3)
        wf.add_commit(self._commit4)

        self.assertEqual(len(wf._commits), 4)

        self.assertEqual(wf._commits['1'].text(), self._showed_text1)
        self.assertEqual(wf._commits['2'].text(), self._showed_text2)
        self.assertEqual(wf._commits['3'].text(), self._showed_text3)
        self.assertEqual(wf._commits['4'].text(), self._showed_text4)
        pass
Пример #8
0
    def workflow_basic_test(self):
        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(self._commit2)
        wf.add_commit(self._commit3)
        wf.add_commit(self._commit4)

        self.assertEqual(len(wf._commits), 4)

        self.assertEqual(wf._commits['1'].text,
                         self._commit1._comment + '\n' + self._commit1.hash)
        self.assertEqual(wf._commits['2'].text,
                         self._commit2._comment + '\n' + self._commit2.hash)
        self.assertEqual(wf._commits['3'].text,
                         self._commit3._comment + '\n' + self._commit3.hash)
        self.assertEqual(wf._commits['4'].text,
                         self._commit4._comment + '\n' + self._commit4.hash)
        pass
Пример #9
0
    def collapse_all_commits_test(self):
        value = 0.812345
        branches = ['master', 'try_smth']
        not_metric_commit2 = Commit('2', '1', 'name1', 'today', 'change smth 2...',
                                    True, branch_tips=branches)
        metric_commit3 = Commit('3', '2', 'name3', 'today3', 'hello3',
                                True, value)

        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(not_metric_commit2)
        wf.add_commit(metric_commit3)
        wf.add_commit(self._commit4)

        self.assertEqual(len(wf._commits), 4)
        wf.collapse_commits(CollapseDvcReproCommitsStrategy(wf))
        self.assertEqual(len(wf._commits), 4)
        wf.collapse_commits(CollapseNotMeticsCommitsStrategy(wf))
        self.assertEqual(len(wf._commits), 2)

        self.assertEqual(wf._commits['3']._target_metric, value)
        self.assertEqual(wf._commits['3'].branch_tips, branches)
        self.assertTrue('4' in wf._commits)
        pass
Пример #10
0
    def collapsed_all_commits_comments_test(self):
        value = 0.812345
        branches = ['master', 'try_smth']
        not_metric_commit2 = Commit('2', '1', 'name1', 'today', 'change smth 2...',
                                    True, branch_tips=branches)
        metric_commit3 = Commit('3', '2', 'name3', 'today3', 'hello3',
                                True, value)

        wf = Workflow('', '')
        wf.add_commit(self._commit1)
        wf.add_commit(not_metric_commit2)
        wf.add_commit(metric_commit3)
        wf.add_commit(self._commit4)

        wf.collapse_commits(CollapseDvcReproCommitsStrategy(wf))
        wf.collapse_commits(CollapseNotMeticsCommitsStrategy(wf))
        self.assertEqual(len(wf._commits), 2)

        def is_collapsed_commit_presented(self, commit, collapsed_commit):
            self.assertTrue('[' + collapsed_commit.hash + ']' in commit.text())
            self.assertTrue(collapsed_commit._comment in commit.text())

        is_collapsed_commit_presented(self, wf._commits['3'], metric_commit3)
        is_collapsed_commit_presented(self, wf._commits['3'], not_metric_commit2)
        is_collapsed_commit_presented(self, wf._commits['3'], self._commit1)
        pass