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 check_repr_and_str(vrs): 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 @@ def satisfies(self, other): def __iter__(self): return iter(self.version) + def __len__(self): + return len(self.version) + def __getitem__(self, idx): cls = type(self)