forked from hydralabs/pyamf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged version-605: Supply a versatile
version
attribute, useful pr…
…ogramatically and stringified. Fixes: #605 Author: thijs, nick Reviewer: nick, thijs git-svn-id: https://svn.pyamf.org/pyamf/trunk@3063 2dde4cc4-cf3c-0410-b1a3-a9b8ff274da5
- Loading branch information
Showing
9 changed files
with
132 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
:mod:`pyamf` --- pyamf | ||
============================================= | ||
|
||
.. automodule:: pyamf | ||
:members: | ||
:synopsis: AMF support for Python. | ||
|
||
.. data:: version | ||
|
||
PyAMF version number. | ||
|
||
>>> import pyamf | ||
>>> pyamf.__version__ is pyamf.version | ||
True | ||
>>> pyamf.version | ||
(0, 6, 1, 'rc1') | ||
>>> str(pyamf.version) | ||
'0.6.1rc1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Tests for L{pyamf.version} | ||
""" | ||
|
||
import unittest | ||
|
||
from pyamf import versions | ||
|
||
|
||
class VersionTestCase(unittest.TestCase): | ||
""" | ||
Tests for L{pyamf.version.get_version} | ||
""" | ||
|
||
def test_version(self): | ||
self.assertEquals(versions.get_version((0, 0)), '0.0') | ||
self.assertEquals(versions.get_version((0, 1)), '0.1') | ||
self.assertEquals(versions.get_version((3, 2)), '3.2') | ||
self.assertEquals(versions.get_version((3, 2, 1)), '3.2.1') | ||
|
||
self.assertEquals(versions.get_version((3, 2, 1, 'alpha')), '3.2.1alpha') | ||
self.assertEquals(versions.get_version((3, 2, 1, 'alpha', 0)), '3.2.1 pre-alpha') | ||
|
||
self.assertEquals(versions.get_version((3, 2, 1, 'final')), '3.2.1final') | ||
self.assertEquals(versions.get_version((3, 2, 1, 'beta', 1234)), '3.2.1beta1234') | ||
|
||
def test_class(self): | ||
V = versions.Version | ||
|
||
v1 = V(0, 1) | ||
|
||
self.assertEquals(v1, (0, 1)) | ||
self.assertEquals(str(v1), '0.1') | ||
|
||
v2 = V(3, 2, 1, 'final') | ||
|
||
self.assertEquals(v2, (3, 2, 1, 'final')) | ||
self.assertEquals(str(v2), '3.2.1final') | ||
|
||
self.assertTrue(v2 > v1) | ||
|
||
|
||
def suite(): | ||
suite = unittest.TestSuite() | ||
|
||
test_cases = [ | ||
VersionTestCase, | ||
] | ||
|
||
for tc in test_cases: | ||
suite.addTest(unittest.makeSuite(tc)) | ||
|
||
return suite | ||
|
||
if __name__ == '__main__': | ||
unittest.main(defaultTest='suite') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Because there is disparity between Python packaging (and it is being sorted | ||
out ...) we currently provide our own way to get the string of a version tuple. | ||
""" | ||
|
||
|
||
class Version(tuple): | ||
""" | ||
""" | ||
|
||
_version = None | ||
|
||
def __new__(cls, *args): | ||
x = tuple.__new__(cls, args) | ||
|
||
return x | ||
|
||
def __str__(self): | ||
if not self._version: | ||
self._version = get_version(self) | ||
|
||
return self._version | ||
|
||
|
||
def get_version(v): | ||
version = '%s.%s' % (v[0], v[1]) | ||
|
||
try: | ||
if v[2]: | ||
version = '%s.%s' % (version, v[2]) | ||
if v[3:] == ('alpha', 0): | ||
version = '%s pre-alpha' % version | ||
else: | ||
version = '%s%s' % (version, v[3]) | ||
if v[3] != 'final': | ||
version = '%s%s' % (version, v[4]) | ||
except IndexError: | ||
pass | ||
|
||
return version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters