Update test for version string.

This commit is contained in:
Norman Jäckel 2012-12-01 13:39:29 +01:00
parent 343710ad1a
commit 4410e454c8
2 changed files with 23 additions and 11 deletions

View File

@ -9,13 +9,15 @@ VERSION = (1, 3, 0, 'final', 0) # During development it is the next release
RELEASE = False
def get_version(version=None):
def get_version(version=None, release=None):
"""
Derives a PEP386-compliant version number from VERSION. Adds id of
the current git commit.
"""
if version is None:
version = VERSION
if release is None:
release = RELEASE
assert len(version) == 5
assert version[3] in ('alpha', 'beta', 'rc', 'final')
# Now build the two parts of the version number:
@ -29,7 +31,7 @@ def get_version(version=None):
sub = mapping[version[3]] + str(version[4])
else:
sub = ''
if not RELEASE:
if not release:
sub += '-dev'
return main + sub

View File

@ -9,15 +9,25 @@
from django.test import TestCase
from openslides import get_version
from openslides import get_version, get_git_commit_id
class InitTest(TestCase):
def test_get_version(self):
self.assertEqual(get_version((1, 3, 0, 'beta', 2)), '1.3-beta2')
self.assertEqual(get_version((1, 0, 0, 'final', 0)), '1.0')
self.assertEqual(get_version((2, 5, 3, 'alpha', 0)), '2.5.3-alpha0')
git_version = get_version((2, 5, 0, 'dev', 0))
if 'unknown' in git_version:
self.assertEqual(len(git_version), 14)
else:
self.assertEqual(len(git_version), 47)
"""
Tests the method during development process and for releases.
"""
self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=False), '1.3b2-dev')
self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=False), '1.0-dev')
self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=False), '2.5.3a0-dev')
self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=True), '1.3b2')
self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=True), '1.0')
self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=True), '2.5.3a0')
self.assertEqual(get_version(version=(2, 5, 3, 'final', 0), release=True), '2.5.3')
def test_get_git_commit_id(self):
"""
Tests the lenght of the git commit id.
"""
git_commit_id = get_git_commit_id()
if not git_commit_id == 'unknown':
self.assertEqual(len(git_commit_id), 40)