Cleanup __repr__ of Version()
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
This commit is contained in:
6
README
6
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
|
||||
|
||||
@@ -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
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
@@ -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`::
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user