Ejemplo n.º 1
0
    def test_mergeBranch_fails_on_source_fetch(self):
        with mock.patch('subprocess.check_output',
                        side_effect=['origin /dev/null/target/Trilinos',
                                      'df324ae']) as m_check_out, \
            mock.patch('subprocess.check_call',
                       side_effect=[None,
                                    CalledProcessError(-1, 'cmd'),
                                    CalledProcessError(-2, 'cmd'),
                                    CalledProcessError(-3, 'cmd')]) as m_check_call:
            if sys.version_info.major is not 3:
                with self.assertRaisesRegexp(SystemExit, '12'):
                    PullRequestLinuxDriverMerge.merge_branch(
                        os.path.join(os.path.sep, 'dev', 'null', 'source',
                                     'Trilinos.git'), 'neverland',
                        'fake_develop', 'df324ae')
            else:
                with self.assertRaisesRegex(SystemExit, '12'):
                    PullRequestLinuxDriverMerge.merge_branch(
                        os.path.join(os.path.sep, 'dev', 'null', 'source',
                                     'Trilinos.git'), 'neverland',
                        'fake_develop', 'df324ae')
        m_check_out.assert_has_calls([mock.call(['git', 'remote', '-v'])])

        m_check_call.assert_has_calls([
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
        ])
Ejemplo n.º 2
0
    def test_mergeBranch_fails_on_SHA_mismatch(self):
        with mock.patch('subprocess.check_output',
                        side_effect=['origin /dev/null/target/Trilinos',
                                      'df324ae']) as m_check_out, \
            mock.patch('subprocess.check_call') as m_check_call, \
            mock.patch('sys.stdout', new_callable=StringIO) as m_stdout:
            if sys.version_info.major is not 3:
                with self.assertRaisesRegexp(SystemExit, '-1'):
                    PullRequestLinuxDriverMerge.merge_branch(
                        os.path.join(os.path.sep, 'dev', 'null', 'source',
                                     'Trilinos.git'), 'neverland',
                        'fake_develop', 'foobar')
            else:
                with self.assertRaisesRegex(SystemExit, '-1'):
                    PullRequestLinuxDriverMerge.merge_branch(
                        os.path.join(os.path.sep, 'dev', 'null', 'source',
                                     'Trilinos.git'), 'neverland',
                        'fake_develop', 'foobar')
        m_check_out.assert_has_calls([
            mock.call(['git', 'remote', '-v']),
            mock.call(['git', 'rev-parse', 'source_remote/neverland'])
        ])

        m_check_call.assert_has_calls([
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
        ])
        self.assertEqual(
            '''The SHA (df324ae) for the last commit on branch neverland
  in repo /dev/null/source/Trilinos.git is different than the expected SHA,
  which is: foobar.\n''', m_stdout.getvalue())
Ejemplo n.º 3
0
    def test_mergeBranch_with_source_remote(self):
        with mock.patch('subprocess.check_output',
                        side_effect=['''origin /dev/null/target/Trilinos
    source_remote /dev/null/source12/Trilinos.git''', 'df324ae']) as m_check_out, \
            mock.patch('subprocess.check_call') as m_check_call, \
            mock.patch('sys.stdout', new_callable=StringIO) as m_stdout:
            PullRequestLinuxDriverMerge.merge_branch(
                os.path.join(os.path.sep, 'dev', 'null', 'source',
                             'Trilinos.git'), 'neverland', 'fake_develop',
                'df324ae')
        m_check_out.assert_has_calls([
            mock.call(['git', 'remote', '-v']),
            mock.call(['git', 'rev-parse', 'source_remote/neverland'])
        ])

        m_check_call.assert_has_calls([
            mock.call(['git', 'remote', 'rm', 'source_remote']),
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
            mock.call(['git', 'fetch', 'origin', 'fake_develop']),
            mock.call(['git', 'reset', '--hard', 'HEAD']),
            mock.call([
                'git', 'checkout', '-B', 'fake_develop', 'origin/fake_develop'
            ]),
            mock.call(['git', 'merge', '--no-edit',
                       'source_remote/neverland']),
        ])
        self.assertEqual("git remote exists, removing it\n",
                         m_stdout.getvalue())
Ejemplo n.º 4
0
    def test_mergeBranch_without_source_remote(self):
        with mock.patch('subprocess.check_output',
                        side_effect=['origin /dev/null/target/Trilinos',
                                      'df324ae']) as m_check_out, \
            mock.patch('subprocess.check_call') as m_check_call:
            PullRequestLinuxDriverMerge.merge_branch(
                os.path.join(os.path.sep, 'dev', 'null', 'source',
                             'Trilinos.git'), 'neverland', 'fake_develop',
                'df324ae')
        m_check_out.assert_has_calls([
            mock.call(['git', 'remote', '-v']),
            mock.call(['git', 'rev-parse', 'source_remote/neverland'])
        ])

        m_check_call.assert_has_calls([
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
            mock.call(['git', 'fetch', 'origin', 'fake_develop']),
            mock.call(['git', 'reset', '--hard', 'HEAD']),
            mock.call([
                'git', 'checkout', '-B', 'fake_develop', 'origin/fake_develop'
            ]),
            mock.call(['git', 'merge', '--no-edit',
                       'source_remote/neverland']),
        ])
Ejemplo n.º 5
0
    def test_mergeBranch_fails_on_source_fetch(self, m_check_out):
        """
        Tests that ``merge_branch`` should fail on source fetch if a failure
        occurrs in the *fetch* operation
        """
        tmp_path = os.path.join(os.path.sep, 'dev', 'null', 'source',
                                'Trilinos.git')

        side_effect_list = [
            None,
            CalledProcessError(-1, 'cmd'),
            CalledProcessError(-2, 'cmd'),
            CalledProcessError(-3, 'cmd')
        ]

        with self.assertRaises(SystemExit):
            with mock.patch('subprocess.check_call',
                            side_effect=side_effect_list) as m_check_call:
                PRMerge.merge_branch(tmp_path, 'neverland', 'fake_develop',
                                     'df324ae')

        expected_calls = []
        expected_calls.append(mock.call(['git', 'remote', '-v']))
        m_check_out.assert_has_calls(expected_calls)

        expected_calls = []
        expected_calls.append(
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]))
        expected_calls.append(
            mock.call(['git', 'fetch', 'source_remote', 'neverland']))
        expected_calls.append(
            mock.call(['git', 'fetch', 'source_remote', 'neverland']))
        expected_calls.append(
            mock.call(['git', 'fetch', 'source_remote', 'neverland']))
        m_check_call.assert_has_calls(expected_calls)

        return
Ejemplo n.º 6
0
    def test_mergeBranch_with_source_remote(self, m_check_call):
        """
        """
        tmp_path = os.path.join(os.path.sep, 'dev', 'null', 'source',
                                'Trilinos.git')

        side_effect_list = [
            "origin /dev/null/target/Trilinos\nsource_remote /dev/null/source12/Trilinos.git",
            'df324ae'
        ]

        with mock.patch('subprocess.check_output',
                        side_effect=side_effect_list) as m_check_out:
            with mock.patch('sys.stdout', new_callable=StringIO) as m_stdout:
                PRMerge.merge_branch(tmp_path, 'neverland', 'fake_develop',
                                     'df324ae')

        expected_calls = []
        expected_calls.append(mock.call(['git', 'remote', '-v']))
        expected_calls.append(
            mock.call(['git', 'rev-parse', 'source_remote/neverland']))
        m_check_out.assert_has_calls(expected_calls)

        m_check_call.assert_has_calls([
            mock.call(['git', 'remote', 'rm', 'source_remote']),
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]),
            mock.call(['git', 'fetch', 'source_remote', 'neverland']),
            mock.call(['git', 'fetch', 'origin', 'fake_develop']),
            mock.call(['git', 'reset', '--hard', 'HEAD']),
            mock.call([
                'git', 'checkout', '-B', 'fake_develop', 'origin/fake_develop'
            ]),
            mock.call(['git', 'merge', '--no-edit',
                       'source_remote/neverland']),
        ])
        self.assertIn("git remote exists, removing it", m_stdout.getvalue())
        return
Ejemplo n.º 7
0
    def test_mergeBranch_fails_on_SHA_mismatch(self, m_check_call,
                                               m_check_out):
        """
        Test that ``merge_branch`` will fail if a SHA mismatch detected.
        """
        with self.assertRaises(SystemExit):
            with mock.patch('sys.stdout', new_callable=StringIO) as m_stdout:
                tmp_path = os.path.join(os.path.sep, 'dev', 'null', 'source',
                                        'Trilinos.git')
                PRMerge.merge_branch(tmp_path, 'neverland', 'fake_develop',
                                     'foobar')

        expected_calls = []
        expected_calls.append(mock.call(['git', 'remote', '-v']))
        expected_calls.append(
            mock.call(['git', 'rev-parse', 'source_remote/neverland']))
        m_check_out.assert_has_calls(expected_calls)

        expected_calls = []
        expected_calls.append(
            mock.call([
                'git', 'remote', 'add', 'source_remote',
                '/dev/null/source/Trilinos.git'
            ]))
        expected_calls.append(
            mock.call(['git', 'fetch', 'source_remote', 'neverland']))
        m_check_call.assert_has_calls(expected_calls)

        stdout_actual = m_stdout.getvalue()
        stdout_expected_1 = "The SHA (df324ae) for the last commit on branch neverland"
        stdout_expected_2 = "is different from the expected SHA"
        stdout_expected_3 = "which is: foobar"

        self.assertIn(stdout_expected_1, stdout_actual)
        self.assertIn(stdout_expected_2, stdout_actual)
        self.assertIn(stdout_expected_3, stdout_actual)

        return