summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-07-06 15:24:10 +0200
committeralalazo <massimiliano.culpo@googlemail.com>2016-07-06 15:24:10 +0200
commit32e086f44adb88bfe11fe73a9c4b69a1dff862cf (patch)
tree103a98f50be6d11f0f395889c5f142ce877878cb
parentd687e332ad41cd7c84bf0007f8c331e56470da18 (diff)
downloadspack-32e086f44adb88bfe11fe73a9c4b69a1dff862cf.tar.gz
spack-32e086f44adb88bfe11fe73a9c4b69a1dff862cf.tar.bz2
spack-32e086f44adb88bfe11fe73a9c4b69a1dff862cf.tar.xz
spack-32e086f44adb88bfe11fe73a9c4b69a1dff862cf.zip
version : modified __repr__ to return a string representation of the object + unit tests
-rw-r--r--lib/spack/spack/test/versions.py8
-rw-r--r--lib/spack/spack/version.py2
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/spack/spack/test/versions.py b/lib/spack/spack/test/versions.py
index 4624f901c8..5f7d57b4e4 100644
--- a/lib/spack/spack/test/versions.py
+++ b/lib/spack/spack/test/versions.py
@@ -389,3 +389,11 @@ class VersionsTest(unittest.TestCase):
self.assertEqual(v.dotted, '1.2.3')
self.assertEqual(v.dashed, '1-2-3')
self.assertEqual(v.underscored, '1_2_3')
+
+ def test_repr_and_str(self):
+ a = Version('1.2.3')
+ self.assertEqual(repr(a), 'Version(\'1.2.3\')')
+ b = eval(repr(a))
+ self.assertEqual(a, b)
+ self.assertEqual(str(a), '1.2.3')
+ self.assertEqual(str(a), str(b))
diff --git a/lib/spack/spack/version.py b/lib/spack/spack/version.py
index 858d581472..6f95e8a2f3 100644
--- a/lib/spack/spack/version.py
+++ b/lib/spack/spack/version.py
@@ -197,7 +197,7 @@ class Version(object):
return tuple(self.version[idx])
def __repr__(self):
- return self.string
+ return 'Version(' + repr(self.string) + ')'
def __str__(self):
return self.string