Repository: enthought/okonomiyaki

Issue:
RuntimeVersion does not offer a repr 
Simple objects like RuntimeVersion should offer a repr to help debuging

Discussion:

Patch:
diff --git a/okonomiyaki/versions/pep440.py b/okonomiyaki/versions/pep440.py
index 77f437a..8481b2c 100644
--- a/okonomiyaki/versions/pep440.py
+++ b/okonomiyaki/versions/pep440.py
@@ -190,7 +190,7 @@ class PEP440Version(object):
         return self._parts > other._parts
 
     def __repr__(self):
-        return "{0}('{1}')".format(self.__class__.__name__, str(self))
+        return "{0}.from_string('{1!s}')".format(self.__class__.__name__, self)
 
     def __str__(self):
         if self._string is None:
diff --git a/okonomiyaki/versions/runtime_version.py b/okonomiyaki/versions/runtime_version.py
index bcce8bc..00e4dd9 100644
--- a/okonomiyaki/versions/runtime_version.py
+++ b/okonomiyaki/versions/runtime_version.py
@@ -48,6 +48,9 @@ class RuntimeVersion(object):
     def __str__(self):
         return str(self._pep440_version)
 
+    def __repr__(self):
+        return "{0}.from_string('{1!s}')".format(self.__class__.__name__, self)
+
     def __hash__(self):
         return hash(self._pep440_version)
 


Test patch:
diff --git a/okonomiyaki/versions/tests/test_pep440.py b/okonomiyaki/versions/tests/test_pep440.py
index 088dc8b..8079362 100644
--- a/okonomiyaki/versions/tests/test_pep440.py
+++ b/okonomiyaki/versions/tests/test_pep440.py
@@ -185,6 +185,17 @@ class TestPEP440Version(unittest.TestCase):
         # When/Then
         self.assertEqual(hash(v1), hash(v2))
 
+    def test_repr(self):
+        # Given
+        v1 = V("1.2.0")
+
+        # When
+        result = repr(v1)
+
+        # Then
+        self.assertEqual(result, "PEP440Version.from_string('1.2.0')")
+        self.assertEqual(eval(result), v1)
+
     def test_invalid(self):
         # Given
         left = V("1.0")
diff --git a/okonomiyaki/versions/tests/test_runtime_version.py b/okonomiyaki/versions/tests/test_runtime_version.py
index 838b9b3..868db2f 100644
--- a/okonomiyaki/versions/tests/test_runtime_version.py
+++ b/okonomiyaki/versions/tests/test_runtime_version.py
@@ -55,6 +55,17 @@ class TestRuntimeVersion(unittest.TestCase):
         self.assertEqual(str(V("1.2.0")), "1.2.0")
         self.assertEqual(V("1.2.0").normalized_string, "1.2")
 
+    def test_repr(self):
+        # given
+        v1 = V("1.2.0")
+
+        # when
+        result = repr(v1)
+
+        # then
+        self.assertEqual(result, "RuntimeVersion.from_string('1.2.0')")
+        self.assertEqual(eval(result), v1)
+
     def test_simple(self):
         self.assertTrue(V("1.2.0") == V("1.2"))
         self.assertFalse(V("1.2.0") == V("1.2.3"))