Basic tests for import and fix for additional branches
Some simple tests to ensure the basic command line behaviour of the import sub-command is correct and also fix the failure to detect the dropped additional branch on next import. Change rebaseeditor script to ensure that exceptions from running git-var are ignored. Change-Id: I23f7e0798130335cac5882f4357eb8094f72f7af
This commit is contained in:
@@ -589,12 +589,12 @@ def do_import(args):
|
|||||||
# merged.
|
# merged.
|
||||||
prev_import_merge = strategy[-1]
|
prev_import_merge = strategy[-1]
|
||||||
if len(prev_import_merge.parents) > 1:
|
if len(prev_import_merge.parents) > 1:
|
||||||
idx = next((idx for idx, commit in enumerate(prev_import_merge.parents)
|
idxs = [idx for idx, commit in enumerate(prev_import_merge.parents)
|
||||||
if commit.hexsha == strategy.searcher.commit.hexsha), None)
|
if commit.hexsha != strategy.searcher.commit.hexsha]
|
||||||
|
|
||||||
if idx:
|
if idxs:
|
||||||
additional_commits = prev_import_merge.parents[idx + 1:]
|
additional_commits = [prev_import_merge.parents[i] for i in idxs]
|
||||||
if additional_commits and not args.branches:
|
if additional_commits and len(args.branches) == 0:
|
||||||
logger.warning("""\
|
logger.warning("""\
|
||||||
**************** WARNING ****************
|
**************** WARNING ****************
|
||||||
Previous import merged additional branches but non have
|
Previous import merged additional branches but non have
|
||||||
|
@@ -193,4 +193,6 @@ class RebaseEditor(GitMixin, LogDedentMixin):
|
|||||||
@property
|
@property
|
||||||
def git_editor(self):
|
def git_editor(self):
|
||||||
|
|
||||||
return os.environ.get("GIT_EDITOR", self.git.var("GIT_EDITOR"))
|
return os.environ.get("GIT_EDITOR",
|
||||||
|
self.git.var("GIT_EDITOR",
|
||||||
|
with_exceptions=False))
|
||||||
|
160
git_upstream/tests/test_import_cmd.py
Normal file
160
git_upstream/tests/test_import_cmd.py
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
# Copyright (c) 2012, 2013, 2014 Hewlett-Packard Development Company, L.P.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
# implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
"""Tests for the 'import' command"""
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
|
||||||
|
import mock
|
||||||
|
from testtools.matchers import Equals
|
||||||
|
|
||||||
|
from git_upstream import main
|
||||||
|
from git_upstream.tests.base import BaseTestCase
|
||||||
|
|
||||||
|
from string import lower
|
||||||
|
|
||||||
|
|
||||||
|
class SubstringMatcher():
|
||||||
|
def __init__(self, containing):
|
||||||
|
self.containing = lower(containing)
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return lower(other).find(self.containing) > -1
|
||||||
|
|
||||||
|
def __unicode__(self):
|
||||||
|
return 'a string containing "%s"' % self.containing
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return unicode(self).encode('utf-8')
|
||||||
|
|
||||||
|
__repr__ = __unicode__
|
||||||
|
|
||||||
|
|
||||||
|
class TestImportCommand(BaseTestCase):
|
||||||
|
|
||||||
|
commands, parser = main.get_parser()
|
||||||
|
|
||||||
|
def test_basic(self):
|
||||||
|
"""Test that default behaviour and options work
|
||||||
|
|
||||||
|
Repository layout being checked (assumed already replayed)
|
||||||
|
|
||||||
|
C---D local/master
|
||||||
|
/
|
||||||
|
A---B---E---F upstream/master
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
tree = [
|
||||||
|
('A', []),
|
||||||
|
('B', ['A']),
|
||||||
|
('C', ['B']),
|
||||||
|
('D', ['C']),
|
||||||
|
('E', ['B']),
|
||||||
|
('F', ['E'])
|
||||||
|
]
|
||||||
|
|
||||||
|
branches = {
|
||||||
|
'head': ('master', 'D'),
|
||||||
|
'upstream': ('upstream/master', 'F')
|
||||||
|
}
|
||||||
|
|
||||||
|
self._build_git_tree(tree, branches.values())
|
||||||
|
self.git.tag(inspect.currentframe().f_code.co_name, 'upstream/master')
|
||||||
|
args = self.parser.parse_args(['-q', 'import', 'upstream/master'])
|
||||||
|
self.assertThat(args.func(args), Equals(True),
|
||||||
|
"import command failed to complete succesfully")
|
||||||
|
|
||||||
|
def test_basic_additional(self):
|
||||||
|
"""Test that default behaviour and options work
|
||||||
|
|
||||||
|
Repository layout being checked (assumed already replayed)
|
||||||
|
|
||||||
|
C---D packaging/master
|
||||||
|
\
|
||||||
|
E---F local/master
|
||||||
|
/
|
||||||
|
A---B---G---H upstream/master
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
tree = [
|
||||||
|
('A', []),
|
||||||
|
('B', ['A']),
|
||||||
|
('C', []),
|
||||||
|
('D', ['C']),
|
||||||
|
('E', ['B', 'D']),
|
||||||
|
('F', ['E']),
|
||||||
|
('G', ['B']),
|
||||||
|
('H', ['G'])
|
||||||
|
]
|
||||||
|
|
||||||
|
branches = {
|
||||||
|
'head': ('master', 'F'),
|
||||||
|
'upstream': ('upstream/master', 'H'),
|
||||||
|
'packaging': ('packaging/master', 'D')
|
||||||
|
}
|
||||||
|
|
||||||
|
self._build_git_tree(tree, branches.values())
|
||||||
|
self.git.tag(inspect.currentframe().f_code.co_name, 'upstream/master')
|
||||||
|
args = self.parser.parse_args(['-q', 'import', 'upstream/master',
|
||||||
|
'packaging/master'])
|
||||||
|
self.assertThat(args.func(args), Equals(True),
|
||||||
|
"import command failed to complete succesfully")
|
||||||
|
|
||||||
|
def test_basic_additional_missed(self):
|
||||||
|
"""Test that forgetting an additional branch that was previously
|
||||||
|
included results in a warning to the user.
|
||||||
|
|
||||||
|
Repository layout being checked (assumed already replayed)
|
||||||
|
|
||||||
|
C---D packaging/master
|
||||||
|
\
|
||||||
|
E---F local/master
|
||||||
|
/
|
||||||
|
A---B---G---H upstream/master
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
tree = [
|
||||||
|
('A', []),
|
||||||
|
('B', ['A']),
|
||||||
|
('C', []),
|
||||||
|
('D', ['C']),
|
||||||
|
('E', ['B', 'D']),
|
||||||
|
('F', ['E']),
|
||||||
|
('G', ['B']),
|
||||||
|
('H', ['G'])
|
||||||
|
]
|
||||||
|
|
||||||
|
branches = {
|
||||||
|
'head': ('master', 'F'),
|
||||||
|
'upstream': ('upstream/master', 'H'),
|
||||||
|
'packaging': ('packaging/master', 'D')
|
||||||
|
}
|
||||||
|
|
||||||
|
self._build_git_tree(tree, branches.values())
|
||||||
|
self.git.tag(inspect.currentframe().f_code.co_name, 'upstream/master')
|
||||||
|
args = self.parser.parse_args(['import', 'upstream/master'])
|
||||||
|
|
||||||
|
mock_logger = mock.MagicMock()
|
||||||
|
with mock.patch('git_upstream.log.get_logger',
|
||||||
|
return_value=mock_logger):
|
||||||
|
self.assertThat(args.func(args), Equals(True),
|
||||||
|
"import command failed to complete succesfully")
|
||||||
|
|
||||||
|
mock_logger.warning.assert_called_with(
|
||||||
|
SubstringMatcher(
|
||||||
|
containing="Previous import merged additional"))
|
@@ -1,5 +1,5 @@
|
|||||||
hacking>=0.5.6,<0.8
|
hacking>=0.5.6,<0.8
|
||||||
|
mock
|
||||||
Sphinx>=1.1.2,<1.2
|
Sphinx>=1.1.2,<1.2
|
||||||
discover
|
discover
|
||||||
fixtures>=0.3.14
|
fixtures>=0.3.14
|
||||||
|
Reference in New Issue
Block a user