summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Green <greenc@fnal.gov>2018-04-26 17:38:43 -0500
committerbecker33 <becker33@llnl.gov>2018-04-26 15:38:43 -0700
commit6cc79f81420a2b576999007c7132e58e92041ce7 (patch)
treedebd263c10cf8bf522dab2d92f7886289aaf7f8b /lib
parent310addea9160b45a22c3d74cdf57006836b75922 (diff)
downloadspack-6cc79f81420a2b576999007c7132e58e92041ce7.tar.gz
spack-6cc79f81420a2b576999007c7132e58e92041ce7.tar.bz2
spack-6cc79f81420a2b576999007c7132e58e92041ce7.tar.xz
spack-6cc79f81420a2b576999007c7132e58e92041ce7.zip
Allow len(Version) to return number of split components. (#7918)
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/versions.py8
-rw-r--r--lib/spack/spack/version.py3
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py
index e89d39553f..50c1dcb83a 100644
--- a/lib/spack/spack/test/versions.py
+++ b/lib/spack/spack/test/versions.py
@@ -488,6 +488,14 @@ def test_repr_and_str():
check_repr_and_str('R2016a.2-3_4')
+def test_len():
+ a = Version('1.2.3.4')
+ assert len(a) == len(a.version)
+ assert(len(a) == 4)
+ b = Version('2018.0')
+ assert(len(b) == 2)
+
+
def test_get_item():
a = Version('0.1_2-3')
assert isinstance(a[1], int)
diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py
index 59041d8009..c863f52525 100644
--- a/lib/spack/spack/version.py
+++ b/lib/spack/spack/version.py
@@ -253,6 +253,9 @@ class Version(object):
def __iter__(self):
return iter(self.version)
+ def __len__(self):
+ return len(self.version)
+
def __getitem__(self, idx):
cls = type(self)