Skip to content

Commit

Permalink
add a test for nested repo checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Sep 18, 2020
1 parent 75c5353 commit 7c9f3c6
Showing 1 changed file with 92 additions and 3 deletions.
95 changes: 92 additions & 3 deletions test/test_sys_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
CFG_SUB_NAME = 'sub-externals.cfg'
README_NAME = 'readme.txt'
REMOTE_BRANCH_FEATURE2 = 'feature2'
NESTED_NAME = ['./fred', './fred/wilma', './fred/wilma/barney']


SVN_TEST_REPO = 'https://github.com/escomp/cesm'

Expand Down Expand Up @@ -160,6 +162,23 @@ def container_simple_required(self, dest_dir):

self.write_config(dest_dir)

def container_nested_required(self, dest_dir, order=[0,1,2]):
"""Create a container externals file with only simple externals.
"""
self.create_config()
self.create_section(SIMPLE_REPO_NAME, 'simp_tag', nested=True,
tag='tag1', path=NESTED_NAME[order[0]])

self.create_section(SIMPLE_REPO_NAME, 'simp_branch', nested=True,
branch=REMOTE_BRANCH_FEATURE2, path=NESTED_NAME[order[1]])

self.create_section(SIMPLE_REPO_NAME, 'simp_hash', nested=True,
ref_hash='60b1cc1a38d63',path=NESTED_NAME[order[2]])

self.write_config(dest_dir)


def container_simple_optional(self, dest_dir):
"""Create a container externals file with optional simple externals
Expand Down Expand Up @@ -261,7 +280,7 @@ def create_metadata(self):
def create_section(self, repo_type, name, tag='', branch='',
ref_hash='', required=True, path=EXTERNALS_NAME,
externals='', repo_path=None, from_submodule=False,
sparse=''):
sparse='', nested=False):
# pylint: disable=too-many-branches
"""Create a config section with autofilling some items and handling
optional items.
Expand All @@ -270,8 +289,11 @@ def create_section(self, repo_type, name, tag='', branch='',
# pylint: disable=R0913
self._config.add_section(name)
if not from_submodule:
self._config.set(name, ExternalsDescription.PATH,
os.path.join(path, name))
if nested:
self._config.set(name, ExternalsDescription.PATH, path)
else:
self._config.set(name, ExternalsDescription.PATH,
os.path.join(path, name))

self._config.set(name, ExternalsDescription.PROTOCOL,
ExternalsDescription.PROTOCOL_GIT)
Expand Down Expand Up @@ -671,10 +693,16 @@ def _check_simple_tag_empty(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_tag'.format(directory)
self._check_generic_empty_default_required(tree, name)

def _check_nested_tag_empty(self, tree, name=EXTERNALS_NAME):
self._check_generic_empty_default_required(tree, name)

def _check_simple_tag_ok(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_tag'.format(directory)
self._check_generic_ok_clean_required(tree, name)

def _check_nested_tag_ok(self, tree, name=EXTERNALS_NAME):
self._check_generic_ok_clean_required(tree, name)

def _check_simple_tag_dirty(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_tag'.format(directory)
self._check_generic_ok_dirty_required(tree, name)
Expand All @@ -687,10 +715,16 @@ def _check_simple_branch_empty(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_branch'.format(directory)
self._check_generic_empty_default_required(tree, name)

def _check_nested_branch_empty(self, tree, name=EXTERNALS_NAME):
self._check_generic_empty_default_required(tree, name)

def _check_simple_branch_ok(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_branch'.format(directory)
self._check_generic_ok_clean_required(tree, name)

def _check_nested_branch_ok(self, tree, name=EXTERNALS_NAME):
self._check_generic_ok_clean_required(tree, name)

def _check_simple_branch_modified(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_branch'.format(directory)
self._check_generic_modified_ok_required(tree, name)
Expand All @@ -699,10 +733,16 @@ def _check_simple_hash_empty(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_hash'.format(directory)
self._check_generic_empty_default_required(tree, name)

def _check_nested_hash_empty(self, tree, name=EXTERNALS_NAME):
self._check_generic_empty_default_required(tree, name)

def _check_simple_hash_ok(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_hash'.format(directory)
self._check_generic_ok_clean_required(tree, name)

def _check_nested_hash_ok(self, tree, name=EXTERNALS_NAME):
self._check_generic_ok_clean_required(tree, name)

def _check_simple_hash_modified(self, tree, directory=EXTERNALS_NAME):
name = './{0}/simp_hash'.format(directory)
self._check_generic_modified_ok_required(tree, name)
Expand Down Expand Up @@ -754,19 +794,38 @@ def _check_container_simple_required_pre_checkout(self, overall, tree):
self._check_simple_branch_empty(tree)
self._check_simple_hash_empty(tree)

def _check_container_nested_required_pre_checkout(self, overall, tree, order=[0,1,2]):
self.assertEqual(overall, 0)
self._check_nested_tag_empty(tree, name=NESTED_NAME[order[0]])
self._check_nested_branch_empty(tree, name=NESTED_NAME[order[1]])
self._check_nested_hash_empty(tree, name=NESTED_NAME[order[2]])

def _check_container_simple_required_checkout(self, overall, tree):
# Note, this is the internal tree status just before checkout
self.assertEqual(overall, 0)
self._check_simple_tag_empty(tree)
self._check_simple_branch_empty(tree)
self._check_simple_hash_empty(tree)

def _check_container_nested_required_checkout(self, overall, tree, order=[0,1,2]):
# Note, this is the internal tree status just before checkout
self.assertEqual(overall, 0)
self._check_nested_tag_empty(tree, name=NESTED_NAME[order[0]])
self._check_nested_branch_empty(tree, name=NESTED_NAME[order[1]])
self._check_nested_hash_empty(tree, name=NESTED_NAME[order[2]])

def _check_container_simple_required_post_checkout(self, overall, tree):
self.assertEqual(overall, 0)
self._check_simple_tag_ok(tree)
self._check_simple_branch_ok(tree)
self._check_simple_hash_ok(tree)

def _check_container_nested_required_post_checkout(self, overall, tree, order=[0,1,2]):
self.assertEqual(overall, 0)
self._check_nested_tag_ok(tree, name=NESTED_NAME[order[0]])
self._check_nested_branch_ok(tree, name=NESTED_NAME[order[1]])
self._check_nested_hash_ok(tree, name=NESTED_NAME[order[2]])

def _check_container_simple_required_out_of_sync(self, overall, tree):
self.assertEqual(overall, 0)
self._check_simple_tag_modified(tree)
Expand Down Expand Up @@ -964,6 +1023,36 @@ def test_container_simple_required(self):
self.status_args)
self._check_container_simple_required_post_checkout(overall, tree)

def test_container_nested_required(self):
"""Verify that a container with nested subrepos
generates the correct initial status.
Tests over all possible permutations
"""

orders = [[0,1,2], [1,2,0], [2,0,1], [0,2,1], [2,1,0], [1,0,2]]
for n, order in enumerate(orders):
# create repo
dest_dir=os.path.join(os.environ[MANIC_TEST_TMP_REPO_ROOT],
self._test_id,"test"+str(n))
under_test_dir = self.setup_test_repo(CONTAINER_REPO_NAME,
dest_dir_in=dest_dir)
self._generator.container_nested_required(under_test_dir, order=order)

# status of empty repo
overall, tree = self.execute_cmd_in_dir(under_test_dir,
self.status_args)
self._check_container_nested_required_pre_checkout(overall, tree, order=order)

# checkout
overall, tree = self.execute_cmd_in_dir(under_test_dir,
self.checkout_args)
self._check_container_nested_required_checkout(overall, tree, order=order)

# status clean checked out
overall, tree = self.execute_cmd_in_dir(under_test_dir,
self.status_args)
self._check_container_nested_required_post_checkout(overall, tree, order=order)

def test_container_simple_optional(self):
"""Verify that container with an optional simple subrepos
generates the correct initial status.
Expand Down

0 comments on commit 7c9f3c6

Please sign in to comment.