コード例 #1
0
    def test_upstream_includeRemote_wrongType(self, mock_isemptyrepository):

        # when
        with self.assertRaises(AssertionError) as context:
            upstream.upstream(include_remote='always')

        # then
        self.assertEqual(context.exception.message, "'include_remote' must be a {!r}. Given {!r}".format(upstream.IncludeRemote, str))
        mock_isemptyrepository.assert_not_called()
コード例 #2
0
    def test_upstream_notAValidReference(self, mock_error, mock_isvalidreference, mock_isemptyrepository):

        # when
        try:
            upstream.upstream(branch='bad-branch')
            self.fail('expected to exit but did not')  # pragma: no cover
        except SystemExit:
            pass

        mock_isvalidreference.assert_called_once_with('bad-branch')
        mock_error.assert_called_once_with("'bad-branch' is not a valid branch")
コード例 #3
0
    def test_upstream_notAValidReference(self, mock_error,
                                         mock_isvalidreference,
                                         mock_isemptyrepository):

        # when
        try:
            upstream.upstream(branch='bad-branch')
            self.fail('expected to exit but did not')  # pragma: no cover
        except SystemExit:
            pass

        mock_isvalidreference.assert_called_once_with('bad-branch')
        mock_error.assert_called_once_with(
            "'bad-branch' is not a valid branch")
コード例 #4
0
    def test_upstream_repositoryIsEmpty(self, mock_isemptyrepository):

        # setup
        mock_isemptyrepository.return_value = True

        # when
        upstream_result = upstream.upstream()

        # then
        self.assertEqual(upstream_result, None)
        mock_isemptyrepository.assert_called_once_with()
コード例 #5
0
    def test_upstream_repositoryIsEmpty(self, mock_isemptyrepository):

        # setup
        mock_isemptyrepository.return_value = True

        # when
        upstream_result = upstream.upstream()

        # then
        self.assertEqual(upstream_result, None)
        mock_isemptyrepository.assert_called_once_with()
コード例 #6
0
    def test_upstream_includeRemote_noUpstream(self, mock_popen, mock_currentbranch, mock_isemptyrepository):

        # setup
        mock_process = mock.Mock()
        mock_process.communicate.return_value = ['']
        mock_popen.return_value = mock_process

        # when
        actual_upstream = upstream.upstream()

        # then
        self.assertEqual(actual_upstream, '')

        mock_currentbranch.assert_called_once_with()
        mock_process.communicate.assert_called_once_with()
        mock_popen.assert_called_once_with('git config --local branch.the-branch.merge'.split(), stdout=PIPE)
コード例 #7
0
    def test_upstream_includeRemote_noUpstream(self, mock_stdout,
                                               mock_currentbranch,
                                               mock_isemptyrepository):

        # setup
        mock_stdout.return_value = ''

        # when
        actual_upstream = upstream.upstream()

        # then
        self.assertEqual(actual_upstream, '')

        mock_currentbranch.assert_called_once_with()
        mock_stdout.assert_called_once_with(
            'git config --local branch.the-branch.merge')
コード例 #8
0
    def test_upstream(self, mock_stdout, mock_currentbranch,
                      mock_isemptyrepository):

        # setup
        expected_upstream = "the-upstream"
        upstream_info = "refs/heads/{}\n".format(expected_upstream)
        mock_stdout.return_value = upstream_info

        # when
        actual_upstream = upstream.upstream()

        # then
        self.assertEqual(actual_upstream, expected_upstream)

        mock_isemptyrepository.assert_called_once_with()
        mock_currentbranch.assert_called_once_with()
        mock_stdout.assert_called_once_with(
            'git config --local branch.the-branch.merge')
コード例 #9
0
    def test_upstream_includeRemote_never(self, mock_popen, mock_currentbranch, mock_isemptyrepository):

        # setup
        expected_upstream = "the-upstream"
        upstream_info = "refs/heads/{}\n".format(expected_upstream)

        mock_process = mock.Mock()
        mock_process.communicate.return_value = [upstream_info]
        mock_popen.return_value = mock_process

        # when
        actual_upstream = upstream.upstream(include_remote=upstream.IncludeRemote.NEVER)

        # then
        self.assertEqual(actual_upstream, expected_upstream)

        mock_isemptyrepository.assert_called_once()
        mock_currentbranch.assert_called_once()
        mock_popen.assert_called_once_with('git config --local branch.the-branch.merge'.split(), stdout=PIPE)
コード例 #10
0
    def test_upstream_branchIncluded(self, mock_stdout, mock_isvalidreference,
                                     mock_currentbranch,
                                     mock_isemptyrepository):

        # setup
        branch_name = 'the-branch'
        expected_upstream = "the-upstream"
        upstream_info = "refs/heads/{}\n".format(expected_upstream)
        mock_stdout.return_value = upstream_info

        # when
        actual_upstream = upstream.upstream(branch=branch_name)

        # then
        self.assertEqual(actual_upstream, expected_upstream)

        mock_currentbranch.assert_not_called()
        mock_isvalidreference.assert_called_once_with(branch_name)
        mock_stdout.assert_called_once_with(
            'git config --local branch.the-branch.merge')
コード例 #11
0
    def test_upstream_branchIncluded(self, mock_popen, mock_isvalidreference, mock_currentbranch, mock_isemptyrepository):

        # setup
        branch_name = 'the-branch'
        expected_upstream = "the-upstream"
        upstream_info = "refs/heads/{}\n".format(expected_upstream)

        mock_process = mock.Mock()
        mock_process.communicate.return_value = [upstream_info]
        mock_popen.return_value = mock_process

        # when
        actual_upstream = upstream.upstream(branch=branch_name)

        # then
        self.assertEqual(actual_upstream, expected_upstream)

        mock_currentbranch.assert_not_called()
        mock_isvalidreference.assert_called_once_with(branch_name)
        mock_process.communicate.assert_called_once_with()
        mock_popen.assert_called_once_with('git config --local branch.the-branch.merge'.split(), stdout=PIPE)
コード例 #12
0
    def test_upstream_includeRemote_always(self, mock_checkoutput, mock_stdout,
                                           mock_currentbranch,
                                           mock_isemptyrepository):

        # setup
        expected_upstream = "the-upstream"
        upstream_info = "refs/heads/{}\n".format(expected_upstream)
        mock_stdout.return_value = upstream_info

        # when
        actual_upstream = upstream.upstream(
            include_remote=upstream.IncludeRemote.ALWAYS)

        # then
        self.assertEqual(actual_upstream, 'the-remote/' + expected_upstream)

        mock_isemptyrepository.assert_called_once()
        mock_currentbranch.assert_called_once()
        mock_stdout.assert_called_once_with(
            'git config --local branch.the-branch.merge')
        mock_checkoutput.assert_called_once_with(
            'git config --local branch.the-branch.remote')