Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compatibility matrix #149

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@ jobs:
matrix:
include:
# Django 3.2: Python 3.8, 3.9, 3.10
- python-version: "3.8"
django-family: 32
- python-version: "3.9"
django-family: 32
- python-version: "3.10"
django-family: 32

# Django 4.1: Python 3.9, 3.10, 3.11
# Django 4.2: Python 3.9, 3.10, 3.11
- python-version: "3.9"
django-family: 41
django-family: 42
- python-version: "3.10"
django-family: 41
django-family: 42
- python-version: "3.11"
django-family: 41
django-family: 42

env:
TOXENV: django${{ matrix.django-family }}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ testall:

# DOC: Run tests for the currently installed version
test:
python -Wdefault -m nose2
python -Werr -m nose2

# DOC: Perform code quality tasks
lint: check-manifest flake8
Expand Down
2 changes: 1 addition & 1 deletion semantic_version/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def compare(v1, v2):


def match(spec, version):
return Spec(spec).match(Version(version))
return SimpleSpec(spec).match(Version(version))


def validate(version_string):
Expand Down
33 changes: 15 additions & 18 deletions tests/django_test_app/models.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright (c) The python-semanticversion project

try:
from django.db import models
django_loaded = True
except ImportError:
django_loaded = False
from django.db import models

from semantic_version import django_fields as semver_fields

if django_loaded:
from semantic_version import django_fields as semver_fields

class VersionModel(models.Model):
version = semver_fields.VersionField(verbose_name='my version')
spec = semver_fields.SpecField(verbose_name='my spec')
npm_spec = semver_fields.SpecField(syntax='npm', blank=True, verbose_name='npm spec')
class VersionModel(models.Model):
version = semver_fields.VersionField(verbose_name='my version')
spec = semver_fields.SpecField(verbose_name='my spec')
npm_spec = semver_fields.SpecField(syntax='npm', blank=True, verbose_name='npm spec')

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)
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)
16 changes: 7 additions & 9 deletions tests/setup_django.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# -*- coding: utf-8 -*-
# Copyright (c) The python-semanticversion project

try: # pragma: no cover
import django
django_loaded = True
except ImportError: # pragma: no cover
django_loaded = False
django = None

import django
from django.apps import apps
from django.conf import settings

if django_loaded:
from django.conf import settings

def configure_django():
if not settings.configured:
settings.configure(
DATABASES={
Expand All @@ -24,6 +21,7 @@
],
MIDDLEWARE_CLASSES=[],
)

django.setup()
from django.apps import apps

apps.populate(settings.INSTALLED_APPS)
84 changes: 35 additions & 49 deletions tests/test_base.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@

from semantic_version import base

from . import testing

class TopLevelTestCase(unittest.TestCase):
"""Test module-level functions."""

if sys.version_info[0] <= 2:
import contextlib

@contextlib.contextmanager
def subTest(self, **kwargs):
yield
class TopLevelTestCase(testing.TestCase):
"""Test module-level functions."""

versions = (
('0.1.0', '0.1.1', -1),
Expand Down Expand Up @@ -96,13 +91,7 @@ def test_validate_invalid(self):
"%r should not be a valid version" % (version,))


class VersionTestCase(unittest.TestCase):
if sys.version_info[0] <= 2:
import contextlib

@contextlib.contextmanager
def subTest(self, **kwargs):
yield
class VersionTestCase(testing.TestCase):

versions = {
'1.0.0-alpha': (1, 0, 0, ('alpha',), ()),
Expand Down Expand Up @@ -171,6 +160,7 @@ def test_compare_to_self(self):
(1, 1, 3, (), ('build', '2012-04-13', 'HUY', 'alpha-12', '1')),
}

@testing.expect_warning(testing.WARN_SPEC_PARTIAL)
def test_parsing_partials(self):
for text, expected_fields in self.partial_versions.items():
with self.subTest(text=text):
Expand All @@ -181,13 +171,15 @@ def test_parsing_partials(self):
self.assertEqual(expected_fields, actual_fields)
self.assertTrue(version.partial, "%r should have partial=True" % version)

@testing.expect_warning(testing.WARN_SPEC_PARTIAL)
def test_str_partials(self):
for text in self.partial_versions:
with self.subTest(text=text):
version = base.Version(text, partial=True)
self.assertEqual(text, str(version))
self.assertEqual("Version('%s', partial=True)" % text, repr(version))

@testing.expect_warning(testing.WARN_SPEC_PARTIAL)
def test_compare_partial_to_self(self):
for text in self.partial_versions:
with self.subTest(text=text):
Expand All @@ -196,6 +188,7 @@ def test_compare_partial_to_self(self):
base.Version(text, partial=True))
self.assertNotEqual(text, base.Version(text, partial=True))

@testing.expect_warning(testing.WARN_SPEC_PARTIAL)
def test_hash(self):
self.assertEqual(
1,
Expand Down Expand Up @@ -415,20 +408,14 @@ class MyVersion(base.Version):
self.assertEqual(type(subv), MyVersion)


class SpecItemTestCase(unittest.TestCase):
if sys.version_info[0] <= 2:
import contextlib

@contextlib.contextmanager
def subTest(self, **kwargs):
yield

class SpecItemTestCase(testing.TestCase):
invalids = [
'<=0.1.1+build3',
'<=0.1.1+',
'>0.2.3-rc2+',
]

@testing.expect_warning(testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_invalids(self):
for invalid in self.invalids:
with self.subTest(invalid=invalid):
Expand All @@ -453,6 +440,7 @@ def test_invalids(self):
'^0.1.3': (base.SpecItem.KIND_CARET, 0, 1, 3, None, None),
}

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_components(self):
for spec_text, components in self.components.items():
with self.subTest(spec_text=spec_text):
Expand Down Expand Up @@ -561,6 +549,7 @@ def test_components(self):
),
}

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_matches(self):
for spec_text, versions in self.matches.items():
spec = base.SpecItem(spec_text)
Expand All @@ -578,30 +567,27 @@ def test_matches(self):
spec.match(version),
"%r should not match %r" % (version, spec))

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_equality(self):
spec1 = base.SpecItem('==0.1.0')
spec2 = base.SpecItem('==0.1.0')
self.assertEqual(spec1, spec2)
self.assertFalse(spec1 == '==0.1.0')

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_to_string(self):
spec = base.SpecItem('==0.1.0')
self.assertEqual('==0.1.0', str(spec))
self.assertEqual(base.SpecItem.KIND_EQUAL, spec.kind)

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_PARTIAL, testing.WARN_SPECITEM)
def test_hash(self):
self.assertEqual(
1,
len(set([base.SpecItem('==0.1.0'), base.SpecItem('==0.1.0')])))


class CoerceTestCase(unittest.TestCase):
if sys.version_info[0] <= 2:
import contextlib

@contextlib.contextmanager
def subTest(self, **kwargs):
yield
class CoerceTestCase(testing.TestCase):

examples = {
# Dict of target: [list of equivalents]
Expand All @@ -626,21 +612,7 @@ def test_invalid(self):
self.assertRaises(ValueError, base.Version.coerce, 'v1')


class SpecTestCase(unittest.TestCase):
if sys.version_info[0] <= 2:
import contextlib

@contextlib.contextmanager
def subTest(self, **kwargs):
yield

def assertCountEqual(self, a, b):
import collections

self.assertEqual(
collections.Counter(a),
collections.Counter(b),
)
class SpecTestCase(testing.TestCase):

examples = {
'>=0.1.1,<0.1.2': ['>=0.1.1', '<0.1.2'],
Expand All @@ -651,6 +623,7 @@ def assertCountEqual(self, a, b):
'~=1.2.3': ['>=1.2.3', '<1.3.0'],
}

@testing.expect_warning(testing.WARN_SPEC_CLASS, testing.WARN_SPEC_ITER, testing.WARN_SPEC_PARTIAL)
def test_parsing(self):
for spec_list_text, specs in self.examples.items():
with self.subTest(spec=spec_list_text):
Expand All @@ -665,6 +638,13 @@ def test_parsing(self):
('>=0.1.0', '!=0.1.3-rc1,<0.1.3'): ['>=0.1.0', '!=0.1.3-rc1', '<0.1.3'],
}

@testing.expect_warning(
testing.WARN_SIMPLESPEC_MANY,
testing.WARN_SPECITEM,
testing.WARN_SPEC_CLASS,
testing.WARN_SPEC_ITER,
testing.WARN_SPEC_PARTIAL,
)
def test_parsing_split(self):
for spec_list_texts, specs in self.split_examples.items():
with self.subTest(spec=spec_list_texts):
Expand Down Expand Up @@ -703,6 +683,7 @@ def test_parsing_split(self):
),
}

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_matches(self):
for spec_list_text, versions in self.matches.items():
spec_list = base.Spec(spec_list_text)
Expand All @@ -728,6 +709,7 @@ def test_matches(self):
spec_list.match(version),
"%r should not match %r" % (version, spec_list))

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_equality(self):
for spec_list_text in self.examples:
with self.subTest(spec=spec_list_text):
Expand All @@ -736,11 +718,13 @@ def test_equality(self):
self.assertEqual(slist1, slist2)
self.assertFalse(slist1 == spec_list_text)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_filter_empty(self):
s = base.Spec('>=0.1.1')
res = tuple(s.filter(()))
self.assertEqual((), res)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_filter_incompatible(self):
s = base.Spec('>=0.1.1,!=0.1.4')
res = tuple(s.filter([
Expand All @@ -750,6 +734,7 @@ def test_filter_incompatible(self):
]))
self.assertEqual((), res)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_filter_compatible(self):
s = base.Spec('>=0.1.1,!=0.1.4,<0.2.0')
res = tuple(s.filter([
Expand All @@ -770,10 +755,12 @@ def test_filter_compatible(self):

self.assertEqual(expected, res)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_select_empty(self):
s = base.Spec('>=0.1.1')
self.assertIsNone(s.select(()))

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_select_incompatible(self):
s = base.Spec('>=0.1.1,!=0.1.4')
res = s.select([
Expand All @@ -783,6 +770,7 @@ def test_select_incompatible(self):
])
self.assertIsNone(res)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_select_compatible(self):
s = base.Spec('>=0.1.1,!=0.1.4,<0.2.0')
res = s.select([
Expand All @@ -797,14 +785,12 @@ def test_select_compatible(self):

self.assertEqual(base.Version('0.1.5'), res)

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_contains(self):
self.assertFalse('ii' in base.Spec('>=0.1.1'))

@testing.expect_warning(testing.WARN_SPEC_CLASS)
def test_hash(self):
self.assertEqual(
1,
len(set([base.Spec('>=0.1.1'), base.Spec('>=0.1.1')])))


if __name__ == '__main__': # pragma: no cover
unittest.main()
Loading