summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTodd Gamblin <tgamblin@llnl.gov>2014-08-10 11:46:14 -0700
committerTodd Gamblin <tgamblin@llnl.gov>2014-08-10 11:46:14 -0700
commit17895bd6fda34ec10b46a339bf2210fee5a17723 (patch)
tree5e7c2c556a0d4faa23e2e758af4a4a350058913c /lib
parent8ab793a3a67a6ef4573b0b2b1e68b293b6d9fd2e (diff)
downloadspack-17895bd6fda34ec10b46a339bf2210fee5a17723.tar.gz
spack-17895bd6fda34ec10b46a339bf2210fee5a17723.tar.bz2
spack-17895bd6fda34ec10b46a339bf2210fee5a17723.tar.xz
spack-17895bd6fda34ec10b46a339bf2210fee5a17723.zip
Add a test case to ensure that Spack is v2.6 compliant.
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/__init__.py3
-rw-r--r--lib/spack/spack/test/python_version.py96
2 files changed, 98 insertions, 1 deletions
diff --git a/lib/spack/spack/test/__init__.py b/lib/spack/spack/test/__init__.py
index c2dfc51aa3..4479c45d77 100644
--- a/lib/spack/spack/test/__init__.py
+++ b/lib/spack/spack/test/__init__.py
@@ -46,7 +46,8 @@ test_names = ['versions',
'install',
'package_sanity',
'config',
- 'directory_layout']
+ 'directory_layout',
+ 'python_version']
def list_tests():
diff --git a/lib/spack/spack/test/python_version.py b/lib/spack/spack/test/python_version.py
new file mode 100644
index 0000000000..f814df3226
--- /dev/null
+++ b/lib/spack/spack/test/python_version.py
@@ -0,0 +1,96 @@
+##############################################################################
+# 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
+##############################################################################
+"""
+This test ensures that all Spack files are Python version 2.6 or less.
+
+Spack was originally 2.7, but enough systems in 2014 are still using
+2.6 on their frontend nodes that we need 2.6 to get adopted.
+"""
+import unittest
+import os
+import re
+from contextlib import closing
+
+import llnl.util.tty as tty
+
+from external import pyqver2
+import spack
+
+spack_max_version = (2,6)
+
+class PythonVersionTest(unittest.TestCase):
+
+ def spack_python_files(self):
+ # first file is the spack script.
+ yield spack.spack_file
+
+ # Next files are all the source files and package files.
+ search_paths = [spack.lib_path, spack.var_path]
+
+ # Iterate through the whole spack source tree.
+ for path in search_paths:
+ for root, dirnames, filenames in os.walk(path):
+ for filename in filenames:
+ if re.match(r'^[^.#].*\.py$', filename):
+ yield os.path.join(root, filename)
+
+
+ def test_python_versions(self):
+ # dict version -> filename -> reasons
+ all_issues = {}
+
+ for fn in self.spack_python_files():
+ with closing(open(fn)) as pyfile:
+ versions = pyqver2.get_versions(pyfile.read())
+ for ver, reasons in versions.items():
+ if ver > spack_max_version:
+ if not ver in all_issues:
+ all_issues[ver] = {}
+ all_issues[ver][fn] = reasons
+
+ if all_issues:
+ tty.error("Spack must run on Python version %d.%d"
+ % spack_max_version)
+
+ for v in sorted(all_issues.keys(), reverse=True):
+ msgs = []
+ for fn in sorted(all_issues[v].keys()):
+ short_fn = fn
+ if fn.startswith(spack.prefix):
+ short_fn = fn[len(spack.prefix):]
+
+ reasons = [r for r in set(all_issues[v][fn]) if r]
+ for r in reasons:
+ msgs.append(("%s:%s" % ('spack' + short_fn, r[0]), r[1]))
+
+ tty.error("These files require version %d.%d:" % v)
+ maxlen = max(len(f) for f, prob in msgs)
+ fmt = "%%-%ds%%s" % (maxlen+3)
+ print fmt % ('File', 'Reason')
+ print fmt % ('-' * (maxlen), '-' * 20)
+ for msg in msgs:
+ print fmt % msg
+
+ self.assertTrue(len(all_issues) == 0)