Files
git-upstream/git_upstream/tests/test_import.py
Darragh Bailey f37890bb31 Add tool to recreate git repo from test scenarios
Provides a simple tool 'build-test-tree' and adds a tox environment
command 'build-tree' which takes as arguments a list of yaml files
separated by spaces of test trees to recreate for the developer to
experiment with different layouts and commands.

This simplifies the creation for development purposes some of the
complex scenarios that need to be tested, to provide a mechanism for
any developer to quickly exercise various git commands directly to
understand the impact before trying to apply such changes to the
existing code.

Example execution:

  tox -e build-tree -- git_upstream/tests/commands/import/scenarios/\
import_switch_branches_search_ref_custom_namespace.yaml

Change-Id: I801bc3e05197d1ce41e703876ce6f46a705ad935
2016-06-30 17:54:05 +00:00

105 lines
3.3 KiB
Python

# 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' module"""
from git_upstream.tests import base
import_command = __import__("git_upstream.commands.import", globals(),
locals(), ['ImportUpstream'])
ImportUpstream = import_command.ImportUpstream
class TestImport(base.BaseTestCase):
def test_import_finish_merge_clean(self):
"""Test that after finishing the import merge that the users working
tree is correctly updated to avoid it looking like there are
uncommitted changes
Repository layout being checked (assumed already replayed)
B---C local/master
/
/ C1 import
/ /
A---D---E upstream/master
Test that ImportUpstream.finish() results in a clean working tree and
index
"""
tree = [
('A', []),
('B', ['A']),
('C', ['B']),
('D', ['A']),
('E', ['D']),
('C1', ['E'])
]
branches = {
'head': ('master', 'C'),
'upstream': ('upstream/master', 'E'),
'import': ('import', 'C1')
}
self.gittree = base.BuildTree(self.testrepo, tree, branches.values())
iu = ImportUpstream("master", "upstream/master", "import")
iu.finish()
self.assertEqual("", self.git.status(porcelain=True),
"ImportUpstream.finish() failed to result in a "
"clean working tree and index")
def test_import_finish_merge_extra_files(self):
"""Test that after finishing the import merge when the users working
tree is updated that any additional files not being managed by git are
left untouched
Repository layout being checked (assumed already replayed)
B---C local/master
/
/ C1 import
/ /
A---D---E upstream/master
"""
tree = [
('A', []),
('B', ['A']),
('C', ['B']),
('D', ['A']),
('E', ['D']),
('C1', ['E'])
]
branches = {
'head': ('master', 'C'),
'upstream': ('upstream/master', 'E'),
'import': ('import', 'C1')
}
self.gittree = base.BuildTree(self.testrepo, tree, branches.values())
iu = ImportUpstream("master", "upstream/master", "import")
# create a dummy file
open('dummy-file', 'a').close()
iu.finish()
self.assertEqual("?? dummy-file", self.git.status(porcelain=True),
"ImportUpstream.finish() failed to leave user "
"files not managed untouched.")