summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-10-02 01:14:00 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-10-03 16:55:53 -0700
commitfaae720c3693733ac272c191b7c3ab4908b02b6b (patch)
treed812677faca519b12a4fe33cc81cd2976d6e9494 /lib
parentda84764e97ead919bee7fb02d469c25a6b03ab63 (diff)
downloadspack-faae720c3693733ac272c191b7c3ab4908b02b6b.tar.gz
spack-faae720c3693733ac272c191b7c3ab4908b02b6b.tar.bz2
spack-faae720c3693733ac272c191b7c3ab4908b02b6b.tar.xz
spack-faae720c3693733ac272c191b7c3ab4908b02b6b.zip
add tests for svn fetching.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/fetch_strategy.py26
-rw-r--r--lib/spack/spack/package.py2
-rw-r--r--lib/spack/spack/stage.py2
-rw-r--r--lib/spack/spack/test/__init__.py3
-rw-r--r--lib/spack/spack/test/svn_fetch.py150
5 files changed, 176 insertions, 7 deletions
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 328f45c3d6..411c8cc276 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -209,11 +209,18 @@ class URLFetchStrategy(FetchStrategy):
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 @@ class VCSFetchStrategy(FetchStrategy):
def __str__(self):
+ return self.url
+
+
+ def __repr__(self):
return "%s<%s>" % (self.__class__, self.url)
@@ -359,6 +370,8 @@ class SvnFetchStrategy(VCSFetchStrategy):
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 @@ class SvnFetchStrategy(VCSFetchStrategy):
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 @@ class SvnFetchStrategy(VCSFetchStrategy):
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):
diff --git a/lib/spack/spack/package.py b/lib/spack/spack/package.py
index c6e1fd90ef..59bfafa241 100644
--- a/lib/spack/spack/package.py
+++ b/lib/spack/spack/package.py
@@ -643,7 +643,7 @@ class Package(object):
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()
diff --git a/lib/spack/spack/stage.py b/lib/spack/spack/stage.py
index ed92fb17f7..0d684df92d 100644
--- a/lib/spack/spack/stage.py
+++ b/lib/spack/spack/stage.py
@@ -254,7 +254,7 @@ class Stage(object):
fetcher.fetch()
break
except spack.error.SpackError, e:
- tty.msg("Download from %s failed." % fetcher)
+ tty.msg("Fetching %s failed." % fetcher)
continue
diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py
index b00f9a31ce..61464293d2 100644
--- a/lib/spack/spack/test/__init__.py
+++ b/lib/spack/spack/test/__init__.py
@@ -48,7 +48,8 @@ test_names = ['versions',
'config',
'directory_layout',
'python_version',
- 'git_fetch']
+ 'git_fetch',
+ 'svn_fetch']
def list_tests():
diff --git a/lib/spack/spack/test/svn_fetch.py b/lib/spack/spack/test/svn_fetch.py
new file mode 100644
index 0000000000..e253f21921
--- /dev/null
+++ b/lib/spack/spack/test/svn_fetch.py
@@ -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
+ })