summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-20 02:02:26 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-20 02:02:26 +0100
commit712d74f87c07c60f2e1d27b44915d5d4bb941fe7 (patch)
treec0263f7f74b56895fb6b36fd89316a61238cd795 /tests
parentf84d754af1ae86aaa9a891445d6ae5be36668a85 (diff)
downloadsemantic-version-712d74f87c07c60f2e1d27b44915d5d4bb941fe7.tar.gz
Add Version.coerce.
Some people don't use semver yet...
Diffstat (limited to 'tests')
-rw-r--r--tests/django_test_app/models.py5
-rwxr-xr-xtests/test_base.py19
-rw-r--r--tests/test_django.py25
3 files changed, 49 insertions, 0 deletions
diff --git a/tests/django_test_app/models.py b/tests/django_test_app/models.py
index 9c44a29..f36c385 100644
--- a/tests/django_test_app/models.py
+++ b/tests/django_test_app/models.py
@@ -14,3 +14,8 @@ class PartialVersionModel(models.Model):
partial = semver_fields.VersionField(partial=True, verbose_name='partial version')
optional = semver_fields.VersionField(verbose_name='optional version', blank=True, null=True)
optional_spec = semver_fields.SpecField(verbose_name='optional spec', blank=True, null=True)
+
+
+class CoerceVersionModel(models.Model):
+ version = semver_fields.VersionField(verbose_name='my version', coerce=True)
+ partial = semver_fields.VersionField(verbose_name='partial version', coerce=True, partial=True)
diff --git a/tests/test_base.py b/tests/test_base.py
index 90dbe96..3e10a83 100755
--- a/tests/test_base.py
+++ b/tests/test_base.py
@@ -301,6 +301,25 @@ class SpecItemTestCase(unittest.TestCase):
len(set([base.SpecItem('==0.1.0'), base.SpecItem('==0.1.0')])))
+class CoerceTestCase(unittest.TestCase):
+ examples = {
+ # Dict of target: [list of equivalents]
+ '0.1.0': ('0.1', '0.1+', '0.1-', '0.1.0', '0.000001.000000000000'),
+ '0.1.0+2': ('0.1.0+2', '0.1.0.2'),
+ '0.1.0+2.3.4': ('0.1.0+2.3.4', '0.1.0+2+3+4', '0.1.0.2+3+4'),
+ '0.1.0+2-3.4': ('0.1.0+2-3.4', '0.1.0+2-3+4', '0.1.0.2-3+4', '0.1.0.2_3+4'),
+ '0.1.0-a2.3': ('0.1.0-a2.3', '0.1.0a2.3', '0.1.0_a2.3'),
+ '0.1.0-a2.3+4.5-6': ('0.1.0-a2.3+4.5-6', '0.1.0a2.3+4.5-6', '0.1.0a2.3+4.5_6', '0.1.0a2.3+4+5/6'),
+ }
+
+ def test_coerce(self):
+ for equivalent, samples in self.examples.items():
+ target = base.Version(equivalent)
+ for sample in samples:
+ v_sample = base.Version.coerce(sample)
+ self.assertEqual(target, v_sample)
+
+
class SpecTestCase(unittest.TestCase):
examples = {
'>=0.1.1,<0.1.2': ['>=0.1.1', '<0.1.2'],
diff --git a/tests/test_django.py b/tests/test_django.py
index a2d4c9b..f3eac10 100644
--- a/tests/test_django.py
+++ b/tests/test_django.py
@@ -61,6 +61,15 @@ class DjangoFieldTestCase(unittest.TestCase):
self.assertEqual(semantic_version.Version('0.1.1'), obj.version)
self.assertEqual(semantic_version.Spec('==0,!=0.2'), obj.spec)
+ def test_coerce(self):
+ obj = models.CoerceVersionModel(version='0.1.1a+2', partial='23')
+ self.assertEqual(semantic_version.Version('0.1.1-a+2'), obj.version)
+ self.assertEqual(semantic_version.Version('23', partial=True), obj.partial)
+
+ obj2 = models.CoerceVersionModel(version='23', partial='0.1.2.3.4.5/6')
+ self.assertEqual(semantic_version.Version('23.0.0'), obj2.version)
+ self.assertEqual(semantic_version.Version('0.1.2+3.4.5-6', partial=True), obj2.partial)
+
def test_invalid_input(self):
self.assertRaises(ValueError, models.VersionModel,
version='0.1.1', spec='blah')
@@ -135,6 +144,15 @@ class SouthTestCase(unittest.TestCase):
self.assertEqual(frozen['optional_spec'],
('semantic_version.django_fields.SpecField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+ def test_freezing_coerce_version_model(self):
+ frozen = south.modelsinspector.get_model_fields(models.CoerceVersionModel)
+
+ self.assertEqual(frozen['version'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'coerce': 'True'}))
+
+ self.assertEqual(frozen['partial'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'partial': 'True', 'coerce': 'True'}))
+
def test_freezing_app(self):
frozen = south.creator.freezer.freeze_apps('django_test_app')
@@ -155,6 +173,13 @@ class SouthTestCase(unittest.TestCase):
self.assertEqual(frozen['django_test_app.partialversionmodel']['optional_spec'],
('semantic_version.django_fields.SpecField', [], {'max_length': '200', 'blank': 'True', 'null': 'True'}))
+ # Test CoerceVersionModel
+ self.assertEqual(frozen['django_test_app.coerceversionmodel']['version'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'coerce': 'True'}))
+
+ self.assertEqual(frozen['django_test_app.coerceversionmodel']['partial'],
+ ('semantic_version.django_fields.VersionField', [], {'max_length': '200', 'partial': 'True', 'coerce': 'True'}))
+
if django_loaded:
from django.test import TestCase