add tests for svn fetching.
This commit is contained in:
parent
da84764e97
commit
faae720c36
@ -209,11 +209,18 @@ def reset(self):
|
||||
self.expand()
|
||||
|
||||
|
||||
def __str__(self):
|
||||
def __repr__(self):
|
||||
url = self.url if self.url else "no url"
|
||||
return "URLFetchStrategy<%s>" % url
|
||||
|
||||
|
||||
def __str__(self):
|
||||
if self.url:
|
||||
return self.url
|
||||
else:
|
||||
return "URLFetchStrategy<no url>"
|
||||
|
||||
|
||||
class VCSFetchStrategy(FetchStrategy):
|
||||
def __init__(self, name, *rev_types, **kwargs):
|
||||
super(VCSFetchStrategy, self).__init__()
|
||||
@ -245,6 +252,10 @@ def expand(self):
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return self.url
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "%s<%s>" % (self.__class__, self.url)
|
||||
|
||||
|
||||
@ -359,6 +370,8 @@ def __init__(self, **kwargs):
|
||||
super(SvnFetchStrategy, self).__init__(
|
||||
'svn', 'revision', **kwargs)
|
||||
self._svn = None
|
||||
if self.revision is not None:
|
||||
self.revision = str(self.revision)
|
||||
|
||||
|
||||
@property
|
||||
@ -381,6 +394,7 @@ def fetch(self):
|
||||
args = ['checkout', '--force']
|
||||
if self.revision:
|
||||
args += ['-r', self.revision]
|
||||
args.append(self.url)
|
||||
|
||||
self.svn(*args)
|
||||
self.stage.chdir_to_source()
|
||||
@ -388,12 +402,16 @@ def fetch(self):
|
||||
|
||||
def _remove_untracked_files(self):
|
||||
"""Removes untracked files in an svn repository."""
|
||||
status = self.svn('status', '--no-ignore', check_output=True)
|
||||
status = self.svn('status', '--no-ignore', return_output=True)
|
||||
self.svn('status', '--no-ignore')
|
||||
for line in status.split('\n'):
|
||||
if not re.match('^[I?]'):
|
||||
if not re.match('^[I?]', line):
|
||||
continue
|
||||
path = line[8:].strip()
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
if os.path.isfile(path):
|
||||
os.unlink(path)
|
||||
elif os.path.isdir(path):
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
|
||||
|
||||
def reset(self):
|
||||
|
@ -643,7 +643,7 @@ def do_stage(self):
|
||||
archive_dir = self.stage.source_path
|
||||
if not archive_dir:
|
||||
self.stage.expand_archive()
|
||||
tty.msg("Created stage directory in %s." % self.stage.path)
|
||||
tty.msg("Created stage in %s." % self.stage.path)
|
||||
else:
|
||||
tty.msg("Already staged %s in %s." % (self.name, self.stage.path))
|
||||
self.stage.chdir_to_source()
|
||||
|
@ -254,7 +254,7 @@ def fetch(self):
|
||||
fetcher.fetch()
|
||||
break
|
||||
except spack.error.SpackError, e:
|
||||
tty.msg("Download from %s failed." % fetcher)
|
||||
tty.msg("Fetching %s failed." % fetcher)
|
||||
continue
|
||||
|
||||
|
||||
|
@ -48,7 +48,8 @@
|
||||
'config',
|
||||
'directory_layout',
|
||||
'python_version',
|
||||
'git_fetch']
|
||||
'git_fetch',
|
||||
'svn_fetch']
|
||||
|
||||
|
||||
def list_tests():
|
||||
|
150
lib/spack/spack/test/svn_fetch.py
Normal file
150
lib/spack/spack/test/svn_fetch.py
Normal file
@ -0,0 +1,150 @@
|
||||
##############################################################################
|
||||
# Copyright (c) 2013, Lawrence Livermore National Security, LLC.
|
||||
# Produced at the Lawrence Livermore National Laboratory.
|
||||
#
|
||||
# This file is part of Spack.
|
||||
# Written by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
|
||||
# LLNL-CODE-647188
|
||||
#
|
||||
# For details, see https://scalability-llnl.github.io/spack
|
||||
# Please also see the LICENSE file for our notice and the LGPL.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License (as published by
|
||||
# the Free Software Foundation) version 2.1 dated February 1999.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
|
||||
# conditions of the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
##############################################################################
|
||||
import os
|
||||
import re
|
||||
import unittest
|
||||
import shutil
|
||||
import tempfile
|
||||
from contextlib import closing
|
||||
|
||||
from llnl.util.filesystem import *
|
||||
|
||||
import spack
|
||||
from spack.version import ver
|
||||
from spack.stage import Stage
|
||||
from spack.util.executable import which
|
||||
from spack.test.mock_packages_test import *
|
||||
|
||||
test_repo_path = 'test-repo'
|
||||
|
||||
test_import_path = 'test-import'
|
||||
test_file_name = 'test-file.txt'
|
||||
test_rev_file_name = 'test-rev-file'
|
||||
|
||||
untracked = 'foobarbaz'
|
||||
|
||||
svn = which('svn', required=True)
|
||||
svnadmin = which('svnadmin', required=True)
|
||||
|
||||
|
||||
class SvnFetchTest(MockPackagesTest):
|
||||
"""Tests fetching from a dummy git repository."""
|
||||
|
||||
def setUp(self):
|
||||
"""Create an svn repository with two revisions."""
|
||||
super(SvnFetchTest, self).setUp()
|
||||
self.stage = Stage('fetch-test')
|
||||
self.stage.chdir()
|
||||
|
||||
repo_path = join_path(self.stage.path, test_repo_path)
|
||||
svnadmin('create', repo_path)
|
||||
self.repo_url = 'file://' + repo_path
|
||||
|
||||
self.import_path = join_path(self.stage.path, test_import_path)
|
||||
mkdirp(self.import_path)
|
||||
with working_dir(self.import_path):
|
||||
touch(test_file_name)
|
||||
|
||||
svn('import', self.import_path, self.repo_url, '-m', 'Initial import')
|
||||
|
||||
shutil.rmtree(self.import_path)
|
||||
svn('checkout', self.repo_url, self.import_path)
|
||||
with working_dir(self.import_path):
|
||||
touch(test_rev_file_name)
|
||||
svn('add', test_rev_file_name)
|
||||
svn('ci', '-m', 'second revision')
|
||||
|
||||
spec = Spec('svn-test')
|
||||
spec.concretize()
|
||||
self.pkg = spack.db.get(spec, new=True)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
"""Destroy the stage space used by this test."""
|
||||
super(SvnFetchTest, self).tearDown()
|
||||
|
||||
if self.stage is not None:
|
||||
self.stage.destroy()
|
||||
|
||||
self.pkg.do_clean_dist()
|
||||
|
||||
|
||||
def assert_rev(self, rev):
|
||||
"""Check that the current revision is equal to the supplied rev."""
|
||||
def get_rev():
|
||||
output = svn('info', return_output=True)
|
||||
self.assertTrue("Revision" in output)
|
||||
for line in output.split('\n'):
|
||||
match = re.match(r'Revision: (\d+)', line)
|
||||
if match:
|
||||
return int(match.group(1))
|
||||
self.assertEqual(get_rev(), rev)
|
||||
|
||||
|
||||
def try_fetch(self, rev, test_file, args):
|
||||
"""Tries to:
|
||||
1. Fetch the repo using a fetch strategy constructed with
|
||||
supplied args.
|
||||
2. Check if the test_file is in the checked out repository.
|
||||
3. Assert that the repository is at the revision supplied.
|
||||
4. Add and remove some files, then reset the repo, and
|
||||
ensure it's all there again.
|
||||
"""
|
||||
self.pkg.versions[ver('svn')] = args
|
||||
|
||||
self.pkg.do_stage()
|
||||
self.assert_rev(rev)
|
||||
|
||||
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.isfile(file_path))
|
||||
|
||||
os.unlink(file_path)
|
||||
self.assertFalse(os.path.isfile(file_path))
|
||||
|
||||
touch(untracked)
|
||||
self.assertTrue(os.path.isfile(untracked))
|
||||
self.pkg.do_clean_work()
|
||||
self.assertFalse(os.path.isfile(untracked))
|
||||
|
||||
self.assertTrue(os.path.isdir(self.pkg.stage.source_path))
|
||||
self.assertTrue(os.path.isfile(file_path))
|
||||
|
||||
self.assert_rev(rev)
|
||||
|
||||
|
||||
def test_fetch_default(self):
|
||||
"""Test a default checkout and make sure it's on rev 1"""
|
||||
self.try_fetch(2, test_rev_file_name, {
|
||||
'svn' : self.repo_url
|
||||
})
|
||||
|
||||
|
||||
def test_fetch_r1(self):
|
||||
"""Test fetching an older revision (0)."""
|
||||
self.try_fetch(1, test_file_name, {
|
||||
'svn' : self.repo_url,
|
||||
'revision' : 1
|
||||
})
|
10
var/spack/mock_packages/svn-test/package.py
Normal file
10
var/spack/mock_packages/svn-test/package.py
Normal file
@ -0,0 +1,10 @@
|
||||
from spack import *
|
||||
|
||||
class SvnTest(Package):
|
||||
"""Mock package that uses svn for fetching."""
|
||||
url = "http://www.example.com/svn-test-1.0.tar.gz"
|
||||
|
||||
version('svn', 'to-be-filled-in-by-test')
|
||||
|
||||
def install(self, spec, prefix):
|
||||
pass
|
Loading…
Reference in New Issue
Block a user