test : fixed failing unit tests
This commit is contained in:
parent
6f42dd556d
commit
726b350689
@ -168,32 +168,33 @@ def create(path, specs, **kwargs):
|
|||||||
pkg = spec.package
|
pkg = spec.package
|
||||||
tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("$_$@")))
|
tty.msg("Adding package {pkg} to mirror".format(pkg=spec.format("$_$@")))
|
||||||
try:
|
try:
|
||||||
for ii, stage in enumerate(pkg.stage):
|
with pkg.stage:
|
||||||
fetcher = stage.fetcher
|
for ii, stage in enumerate(pkg.stage):
|
||||||
if ii == 0:
|
fetcher = stage.fetcher
|
||||||
# create a subdirectory for the current package@version
|
if ii == 0:
|
||||||
archive_path = os.path.abspath(join_path(mirror_root, mirror_archive_path(spec, fetcher)))
|
# create a subdirectory for the current package@version
|
||||||
name = spec.format("$_$@")
|
archive_path = os.path.abspath(join_path(mirror_root, mirror_archive_path(spec, fetcher)))
|
||||||
else:
|
name = spec.format("$_$@")
|
||||||
resource = stage.resource
|
else:
|
||||||
archive_path = join_path(subdir, suggest_archive_basename(resource))
|
resource = stage.resource
|
||||||
name = "{resource} ({pkg}).".format(resource=resource.name, pkg=spec.format("$_$@"))
|
archive_path = join_path(subdir, suggest_archive_basename(resource))
|
||||||
subdir = os.path.dirname(archive_path)
|
name = "{resource} ({pkg}).".format(resource=resource.name, pkg=spec.format("$_$@"))
|
||||||
mkdirp(subdir)
|
subdir = os.path.dirname(archive_path)
|
||||||
|
mkdirp(subdir)
|
||||||
|
|
||||||
if os.path.exists(archive_path):
|
if os.path.exists(archive_path):
|
||||||
tty.msg("{name} : already added".format(name=name))
|
tty.msg("{name} : already added".format(name=name))
|
||||||
else:
|
else:
|
||||||
everything_already_exists = False
|
everything_already_exists = False
|
||||||
fetcher.fetch()
|
fetcher.fetch()
|
||||||
if not kwargs.get('no_checksum', False):
|
if not kwargs.get('no_checksum', False):
|
||||||
fetcher.check()
|
fetcher.check()
|
||||||
tty.msg("{name} : checksum passed".format(name=name))
|
tty.msg("{name} : checksum passed".format(name=name))
|
||||||
|
|
||||||
# Fetchers have to know how to archive their files. Use
|
# Fetchers have to know how to archive their files. Use
|
||||||
# that to move/copy/create an archive in the mirror.
|
# that to move/copy/create an archive in the mirror.
|
||||||
fetcher.archive(archive_path)
|
fetcher.archive(archive_path)
|
||||||
tty.msg("{name} : added".format(name=name))
|
tty.msg("{name} : added".format(name=name))
|
||||||
|
|
||||||
if everything_already_exists:
|
if everything_already_exists:
|
||||||
present.append(spec)
|
present.append(spec)
|
||||||
|
@ -404,10 +404,13 @@ def path(self):
|
|||||||
return self[0].path
|
return self[0].path
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self[0].__enter__()
|
for item in self:
|
||||||
|
item.__enter__()
|
||||||
|
return self
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
return self[0].__exit__(exc_type, exc_val, exc_tb)
|
for item in reversed(self):
|
||||||
|
item.__exit__(exc_type, exc_val, exc_tb)
|
||||||
|
|
||||||
def chdir_to_source(self):
|
def chdir_to_source(self):
|
||||||
return self[0].chdir_to_source()
|
return self[0].chdir_to_source()
|
||||||
|
@ -52,8 +52,6 @@ def setUp(self):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
shutil.rmtree(self.tmpdir, ignore_errors=True)
|
shutil.rmtree(self.tmpdir, ignore_errors=True)
|
||||||
if self.stage:
|
|
||||||
self.stage.destroy()
|
|
||||||
os.chdir(self.orig_dir)
|
os.chdir(self.orig_dir)
|
||||||
|
|
||||||
|
|
||||||
@ -64,12 +62,12 @@ def check_archive(self, filename, system):
|
|||||||
|
|
||||||
url = 'file://' + join_path(os.getcwd(), 'archive.tar.gz')
|
url = 'file://' + join_path(os.getcwd(), 'archive.tar.gz')
|
||||||
print url
|
print url
|
||||||
self.stage = Stage(url)
|
with Stage(url) as stage:
|
||||||
self.stage.fetch()
|
stage.fetch()
|
||||||
|
|
||||||
guesser = ConfigureGuesser()
|
guesser = ConfigureGuesser()
|
||||||
guesser(self.stage)
|
guesser(stage)
|
||||||
self.assertEqual(system, guesser.build_system)
|
self.assertEqual(system, guesser.build_system)
|
||||||
|
|
||||||
|
|
||||||
def test_python(self):
|
def test_python(self):
|
||||||
|
@ -76,26 +76,27 @@ def try_fetch(self, rev, test_file, args):
|
|||||||
"""
|
"""
|
||||||
self.pkg.versions[ver('git')] = args
|
self.pkg.versions[ver('git')] = args
|
||||||
|
|
||||||
self.pkg.do_stage()
|
with self.pkg.stage:
|
||||||
self.assert_rev(rev)
|
self.pkg.do_stage()
|
||||||
|
self.assert_rev(rev)
|
||||||
|
|
||||||
file_path = join_path(self.pkg.stage.source_path, test_file)
|
file_path = join_path(self.pkg.stage.source_path, test_file)
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
os.unlink(file_path)
|
os.unlink(file_path)
|
||||||
self.assertFalse(os.path.isfile(file_path))
|
self.assertFalse(os.path.isfile(file_path))
|
||||||
|
|
||||||
untracked_file = 'foobarbaz'
|
untracked_file = 'foobarbaz'
|
||||||
touch(untracked_file)
|
touch(untracked_file)
|
||||||
self.assertTrue(os.path.isfile(untracked_file))
|
self.assertTrue(os.path.isfile(untracked_file))
|
||||||
self.pkg.do_restage()
|
self.pkg.do_restage()
|
||||||
self.assertFalse(os.path.isfile(untracked_file))
|
self.assertFalse(os.path.isfile(untracked_file))
|
||||||
|
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
self.assert_rev(rev)
|
self.assert_rev(rev)
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_master(self):
|
def test_fetch_master(self):
|
||||||
|
@ -68,26 +68,27 @@ def try_fetch(self, rev, test_file, args):
|
|||||||
"""
|
"""
|
||||||
self.pkg.versions[ver('hg')] = args
|
self.pkg.versions[ver('hg')] = args
|
||||||
|
|
||||||
self.pkg.do_stage()
|
with self.pkg.stage:
|
||||||
self.assertEqual(self.repo.get_rev(), rev)
|
self.pkg.do_stage()
|
||||||
|
self.assertEqual(self.repo.get_rev(), rev)
|
||||||
|
|
||||||
file_path = join_path(self.pkg.stage.source_path, test_file)
|
file_path = join_path(self.pkg.stage.source_path, test_file)
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
os.unlink(file_path)
|
os.unlink(file_path)
|
||||||
self.assertFalse(os.path.isfile(file_path))
|
self.assertFalse(os.path.isfile(file_path))
|
||||||
|
|
||||||
untracked = 'foobarbaz'
|
untracked = 'foobarbaz'
|
||||||
touch(untracked)
|
touch(untracked)
|
||||||
self.assertTrue(os.path.isfile(untracked))
|
self.assertTrue(os.path.isfile(untracked))
|
||||||
self.pkg.do_restage()
|
self.pkg.do_restage()
|
||||||
self.assertFalse(os.path.isfile(untracked))
|
self.assertFalse(os.path.isfile(untracked))
|
||||||
|
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
self.assertEqual(self.repo.get_rev(), rev)
|
self.assertEqual(self.repo.get_rev(), rev)
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_default(self):
|
def test_fetch_default(self):
|
||||||
|
@ -38,6 +38,8 @@ class LinkTreeTest(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.stage = Stage('link-tree-test')
|
self.stage = Stage('link-tree-test')
|
||||||
|
# FIXME : possibly this test needs to be refactored to avoid the explicit call to __enter__ and __exit__
|
||||||
|
self.stage.__enter__()
|
||||||
|
|
||||||
with working_dir(self.stage.path):
|
with working_dir(self.stage.path):
|
||||||
touchp('source/1')
|
touchp('source/1')
|
||||||
@ -51,10 +53,8 @@ def setUp(self):
|
|||||||
source_path = os.path.join(self.stage.path, 'source')
|
source_path = os.path.join(self.stage.path, 'source')
|
||||||
self.link_tree = LinkTree(source_path)
|
self.link_tree = LinkTree(source_path)
|
||||||
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if self.stage:
|
self.stage.__exit__(None, None, None)
|
||||||
self.stage.destroy()
|
|
||||||
|
|
||||||
|
|
||||||
def check_file_link(self, filename):
|
def check_file_link(self, filename):
|
||||||
|
@ -74,14 +74,14 @@ def set_up_package(self, name, MockRepoClass, url_attr):
|
|||||||
|
|
||||||
|
|
||||||
def check_mirror(self):
|
def check_mirror(self):
|
||||||
stage = Stage('spack-mirror-test')
|
with Stage('spack-mirror-test') as stage:
|
||||||
mirror_root = join_path(stage.path, 'test-mirror')
|
mirror_root = join_path(stage.path, 'test-mirror')
|
||||||
|
|
||||||
|
# register mirror with spack config
|
||||||
|
mirrors = { 'spack-mirror-test' : 'file://' + mirror_root }
|
||||||
|
spack.config.update_config('mirrors', mirrors)
|
||||||
|
|
||||||
# register mirror with spack config
|
|
||||||
mirrors = { 'spack-mirror-test' : 'file://' + mirror_root }
|
|
||||||
spack.config.update_config('mirrors', mirrors)
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.chdir(stage.path)
|
os.chdir(stage.path)
|
||||||
spack.mirror.create(
|
spack.mirror.create(
|
||||||
mirror_root, self.repos, no_checksum=True)
|
mirror_root, self.repos, no_checksum=True)
|
||||||
@ -97,38 +97,36 @@ def check_mirror(self):
|
|||||||
files = os.listdir(subdir)
|
files = os.listdir(subdir)
|
||||||
self.assertEqual(len(files), 1)
|
self.assertEqual(len(files), 1)
|
||||||
|
|
||||||
# Now try to fetch each package.
|
# Now try to fetch each package.
|
||||||
for name, mock_repo in self.repos.items():
|
for name, mock_repo in self.repos.items():
|
||||||
spec = Spec(name).concretized()
|
spec = Spec(name).concretized()
|
||||||
pkg = spec.package
|
pkg = spec.package
|
||||||
|
|
||||||
pkg._stage = None
|
saved_checksum_setting = spack.do_checksum
|
||||||
saved_checksum_setting = spack.do_checksum
|
with pkg.stage:
|
||||||
try:
|
try:
|
||||||
# Stage the archive from the mirror and cd to it.
|
# Stage the archive from the mirror and cd to it.
|
||||||
spack.do_checksum = False
|
spack.do_checksum = False
|
||||||
pkg.do_stage(mirror_only=True)
|
pkg.do_stage(mirror_only=True)
|
||||||
|
|
||||||
# Compare the original repo with the expanded archive
|
# Compare the original repo with the expanded archive
|
||||||
original_path = mock_repo.path
|
original_path = mock_repo.path
|
||||||
if 'svn' in name:
|
if 'svn' in name:
|
||||||
# have to check out the svn repo to compare.
|
# have to check out the svn repo to compare.
|
||||||
original_path = join_path(mock_repo.path, 'checked_out')
|
original_path = join_path(mock_repo.path, 'checked_out')
|
||||||
svn('checkout', mock_repo.url, original_path)
|
svn('checkout', mock_repo.url, original_path)
|
||||||
|
|
||||||
dcmp = dircmp(original_path, pkg.stage.source_path)
|
dcmp = dircmp(original_path, pkg.stage.source_path)
|
||||||
|
|
||||||
# make sure there are no new files in the expanded tarball
|
# make sure there are no new files in the expanded tarball
|
||||||
self.assertFalse(dcmp.right_only)
|
self.assertFalse(dcmp.right_only)
|
||||||
|
|
||||||
# and that all original files are present.
|
# and that all original files are present.
|
||||||
self.assertTrue(all(l in exclude for l in dcmp.left_only))
|
self.assertTrue(all(l in exclude for l in dcmp.left_only))
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
spack.do_checksum = saved_checksum_setting
|
spack.do_checksum = saved_checksum_setting
|
||||||
pkg.do_clean()
|
pkg.do_clean()
|
||||||
finally:
|
|
||||||
stage.destroy()
|
|
||||||
|
|
||||||
|
|
||||||
def test_git_mirror(self):
|
def test_git_mirror(self):
|
||||||
|
@ -82,26 +82,27 @@ def try_fetch(self, rev, test_file, args):
|
|||||||
"""
|
"""
|
||||||
self.pkg.versions[ver('svn')] = args
|
self.pkg.versions[ver('svn')] = args
|
||||||
|
|
||||||
self.pkg.do_stage()
|
with self.pkg.stage:
|
||||||
self.assert_rev(rev)
|
self.pkg.do_stage()
|
||||||
|
self.assert_rev(rev)
|
||||||
|
|
||||||
file_path = join_path(self.pkg.stage.source_path, test_file)
|
file_path = join_path(self.pkg.stage.source_path, test_file)
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
os.unlink(file_path)
|
os.unlink(file_path)
|
||||||
self.assertFalse(os.path.isfile(file_path))
|
self.assertFalse(os.path.isfile(file_path))
|
||||||
|
|
||||||
untracked = 'foobarbaz'
|
untracked = 'foobarbaz'
|
||||||
touch(untracked)
|
touch(untracked)
|
||||||
self.assertTrue(os.path.isfile(untracked))
|
self.assertTrue(os.path.isfile(untracked))
|
||||||
self.pkg.do_restage()
|
self.pkg.do_restage()
|
||||||
self.assertFalse(os.path.isfile(untracked))
|
self.assertFalse(os.path.isfile(untracked))
|
||||||
|
|
||||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||||
self.assertTrue(os.path.isfile(file_path))
|
self.assertTrue(os.path.isfile(file_path))
|
||||||
|
|
||||||
self.assert_rev(rev)
|
self.assert_rev(rev)
|
||||||
|
|
||||||
|
|
||||||
def test_fetch_default(self):
|
def test_fetch_default(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user