summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-05-22 14:25:08 +0200
committerRaphaël Barrois <raphael.barrois@polyconseil.fr>2012-05-22 14:25:08 +0200
commit7eeee04cfaf7997fc9bcbb7c9f08ebf99ac94e30 (patch)
tree3a6d61b0065d3e90ab00f9a6538772812828718f
parent9e58282b8baf892b8eea19d3d232f96017e42a0b (diff)
downloadsemantic-version-7eeee04cfaf7997fc9bcbb7c9f08ebf99ac94e30.tar.gz
Cleanup __repr__ of Version()
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
-rw-r--r--README6
-rw-r--r--doc/index.rst2
-rw-r--r--doc/reference.rst22
-rw-r--r--src/semantic_version/base.py10
-rwxr-xr-xtests/test_base.py10
5 files changed, 21 insertions, 29 deletions
diff --git a/README b/README
index 4f8403f..989f5b6 100644
--- a/README
+++ b/README
@@ -25,9 +25,7 @@ Compare it to other versions::
>>> v < Version('0.1.2')
True
>>> sorted([Version('0.1.1'), Version('0.11.1'), Version('0.1.1-alpha')])
- [<Version(0, 1, 1, ('alpha',), ())>,
- <Version(0, 1, 1, (), ())>,
- <Version(0, 11, 1, (), ())>]
+ [Version('0.1.1-alpha'), Version('0.1.1'), Version('0.11.1')]
Define a simple specification::
@@ -53,7 +51,7 @@ Select the best compatible version from a list::
>>> s = Spec('>=0.1.1,<0.2.0')
>>> s.select([Version('0.1.1'), Version('0.1.9-alpha'), Version('0.1.9-alpha+1'))
- <Version(0, 1, 9, ('alpha',), (1,))>
+ Version('0.1.9-alpha+1')
Framework integration
diff --git a/doc/index.rst b/doc/index.rst
index 17e8f3c..c119e2f 100644
--- a/doc/index.rst
+++ b/doc/index.rst
@@ -134,7 +134,7 @@ It is also possible to select the 'best' version from such iterables::
>>> s = Spec('>=0.1.0,<0.4.0')
>>> versions = (Version('0.%d.0' % i) for i in range(6))
>>> s.select(versions)
- <Version(0, 3, 0, (), ())>
+ Version('0.3.0')
Including pre-release identifiers in specifications
"""""""""""""""""""""""""""""""""""""""""""""""""""
diff --git a/doc/reference.rst b/doc/reference.rst
index bd11189..bff0863 100644
--- a/doc/reference.rst
+++ b/doc/reference.rst
@@ -53,7 +53,7 @@ Representing a version (the Version class)
Constructed from a textual version string::
>>> Version('1.1.1')
- <Version(1, 1, 1, [], [])>
+ Version('1.1.1')
>>> str(Version('1.1.1'))
'1.1.1'
@@ -156,7 +156,7 @@ Representing a version (the Version class)
>>> v = Version('0.1.1-rc2+build4.4')
>>> v
- <Version(0, 1, 1, ['rc2'], ['build4', '4'])>
+ Version('0.1.1-rc2+build4.4')
>>> str(v)
'0.1.1-rc2+build4.4'
@@ -252,19 +252,19 @@ rules apply:
>>> Spec('>=1.0.0,<1.2.0,!=1.1.4')
<Spec: (
- <SpecItem: >= <~Version(1 0 0 None None)>>,
- <SpecItem: < <~Version(1 2 0 None None)>>,
- <SpecItem: != <~Version(1 1 4 None None)>>
+ <SpecItem: >= Version('1.0.0', partial=True)>,
+ <SpecItem: < Version('1.2.0', partial=True)>,
+ <SpecItem: != Version('1.1.4', partial=True)>
)>
Version specifications may also be passed in separated arguments::
>>> Spec('>=1.0.0', '<1.2.0', '!=1.1.4,!=1.1.13')
<Spec: (
- <SpecItem: >= <~Version(1 0 0 None None)>>,
- <SpecItem: < <Version(1 2 0 None None)>>,
- <SpecItem: != <~Version(1 1 4 None None)>>
- <SpecItem: != <~Version(1 1 13 None None)>>
+ <SpecItem: >= Version('1.0.0', partial=True)>,
+ <SpecItem: < Version('1.2.0', partial=True)>,
+ <SpecItem: != Version('1.1.4', partial=True)>,
+ <SpecItem: != Version('1.1.13', partial=True)>,
)>
@@ -312,7 +312,7 @@ rules apply:
>>> s.select([])
None
>>> s.select([Version('0.1.0'), Version('0.1.3'), Version('0.1.1')])
- <Version(0, 1, 3, (), ())>
+ Version('0.1.3')
:param versions: The versions to filter
:type versions: iterable of :class:`Version`
@@ -371,7 +371,7 @@ rules apply:
Stores a version specification, defined from a string::
>>> SpecItem('>=0.1.1')
- <SpecItem: >= <Version(0, 1, 1, [], [])>>
+ <SpecItem: >= Version('0.1.1', partial=True)>
This allows to test :class:`Version` objects against the :class:`SpecItem`::
diff --git a/src/semantic_version/base.py b/src/semantic_version/base.py
index ba37f27..66ab382 100644
--- a/src/semantic_version/base.py
+++ b/src/semantic_version/base.py
@@ -127,13 +127,9 @@ class Version(object):
return version
def __repr__(self):
- return '<%sVersion(%s, %s, %s, %r, %r)>' % (
- '~' if self.partial else '',
- self.major,
- self.minor,
- self.patch,
- self.prerelease,
- self.build,
+ return 'Version(%r%s)' % (
+ str(self),
+ ', partial=True' if self.partial else '',
)
def __hash__(self):
diff --git a/tests/test_base.py b/tests/test_base.py
index 6ea832a..ea1d8e9 100755
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -119,11 +119,10 @@ class VersionTestCase(unittest.TestCase):
self.assertEqual(expected_fields, actual_fields)
def test_str(self):
- for text, fields in self.versions.items():
+ for text in self.versions:
version = base.Version(text)
self.assertEqual(text, str(version))
- for field in fields:
- self.assertIn(repr(field), repr(version))
+ self.assertEqual("Version('%s')" % text, repr(version))
def test_compare_to_self(self):
for text in self.versions:
@@ -162,11 +161,10 @@ class VersionTestCase(unittest.TestCase):
self.assertTrue(version.partial, "%r should have partial=True" % version)
def test_str_partials(self):
- for text, fields in self.partial_versions.items():
+ for text in self.partial_versions:
version = base.Version(text, partial=True)
self.assertEqual(text, str(version))
- for field in fields:
- self.assertIn(repr(field), repr(version))
+ self.assertEqual("Version('%s', partial=True)" % text, repr(version))
def test_compare_partial_to_self(self):
for text in self.partial_versions: