diff options
author | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-05-21 18:26:49 +0200 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polyconseil.fr> | 2012-05-21 18:26:49 +0200 |
commit | f8b74524f09e00d36c7b5295295e4eeb43d46179 (patch) | |
tree | 95a1b63546cde5375667233f74babd1554196f45 | |
parent | a19fc38739611c33232e575a4c609a39ba07f932 (diff) | |
download | semantic-version-f8b74524f09e00d36c7b5295295e4eeb43d46179.tar.gz |
Rename Spec to SpecItem and SpecList to SpecItem.
Signed-off-by: Raphaël Barrois <raphael.barrois@polyconseil.fr>
-rw-r--r-- | doc/django.rst | 10 | ||||
-rw-r--r-- | doc/index.rst | 32 | ||||
-rw-r--r-- | doc/reference.rst | 114 | ||||
-rw-r--r-- | src/semantic_version/__init__.py | 2 | ||||
-rw-r--r-- | src/semantic_version/base.py | 14 | ||||
-rw-r--r-- | src/semantic_version/django_fields.py | 16 | ||||
-rw-r--r-- | tests/django_test_app/models.py | 8 | ||||
-rwxr-xr-x | tests/test_base.py | 60 | ||||
-rw-r--r-- | tests/test_django.py | 8 |
9 files changed, 132 insertions, 132 deletions
diff --git a/doc/django.rst b/doc/django.rst index 2084659..2117c21 100644 --- a/doc/django.rst +++ b/doc/django.rst @@ -6,8 +6,8 @@ Interaction with Django The ``python-semanticversion`` package provides three custom fields for Django: - :class:`VersionField`: stores a :class:`semantic_version.Version` object +- :class:`SpecItemField`: stores a :class:`semantic_version.SpecItem` object - :class:`SpecField`: stores a :class:`semantic_version.Spec` object -- :class:`SpecListField`: stores a :class:`semantic_version.SpecList` object Those fields are :class:`django.db.models.CharField` subclasses, with their :attr:`~django.db.models.CharField.max_length` defaulting to 200. @@ -22,11 +22,11 @@ with their :attr:`~django.db.models.CharField.max_length` defaulting to 200. Boolean; whether :attr:`~semantic_version.Version.partial` versions are allowed. -.. class:: SpecField +.. class:: SpecItemField - Stores a :class:`semantic_version.Spec` as its string representation. + Stores a :class:`semantic_version.SpecItem` as its string representation. -.. class:: SpecListField +.. class:: SpecField - Stores a :class:`semantic_version.SpecList` as its comma-separated string representation. + Stores a :class:`semantic_version.Spec` as its comma-separated string representation. diff --git a/doc/index.rst b/doc/index.rst index 704393f..cae45f5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -29,7 +29,7 @@ Import it in your code:: This module provides two classes to handle semantic versions: - :class:`Version` represents a version number (``0.1.1-alpha+build.2012-05-15``) -- :class:`Spec` represents a requirement specification (``>=0.1.1``) +- :class:`Spec` represents a requirement specification (``>=0.1.1,<0.3.0``) Versions -------- @@ -82,9 +82,9 @@ Obviously, :class:`Versions <Version>` can be compared:: Requirement specification ------------------------- -The :class:`Spec` object describes a range of accepted versions:: +The :class:`SpecItem` object describes a range of accepted versions:: - >>> s = Spec('>=0.1.1') # At least 0.1.1 + >>> s = SpecItem('>=0.1.1') # At least 0.1.1 >>> s.match(Version('0.1.1')) True >>> s.match(Version('0.1.1-alpha1')) # pre-release satisfy version spec @@ -94,7 +94,7 @@ The :class:`Spec` object describes a range of accepted versions:: Simpler test syntax is also available using the ``in`` keyword:: - >>> s = Spec('==0.1.1') + >>> s = SpecItem('==0.1.1') >>> Version('0.1.1-alpha1') in s True >>> Version('0.1.2') in s @@ -104,40 +104,40 @@ Simpler test syntax is also available using the ``in`` keyword:: Including pre-release identifiers in specifications """"""""""""""""""""""""""""""""""""""""""""""""""" -When testing a :class:`Version` against a :class:`Spec`, comparisons are only -performed for components defined in the :class:`Spec`; thus, a pre-release +When testing a :class:`Version` against a :class:`SpecItem`, comparisons are only +performed for components defined in the :class:`SpecItem`; thus, a pre-release version (``1.0.0-alpha``), while not strictly equal to the non pre-release -version (``1.0.0``), satisfies the ``==1.0.0`` :class:`Spec`. +version (``1.0.0``), satisfies the ``==1.0.0`` :class:`SpecItem`. -Pre-release identifiers will only be compared if included in the :class:`Spec` +Pre-release identifiers will only be compared if included in the :class:`SpecItem` definition or (for the empty pre-release number) if a single dash is appended (``1.0.0-``):: - >>> Version('0.1.0-alpha') in Spec('>=0.1.0') # No pre-release identifier + >>> Version('0.1.0-alpha') in SpecItem('>=0.1.0') # No pre-release identifier True - >>> Version('0.1.0-alpha') in Spec('>=0.1.0-') # Include pre-release in checks + >>> Version('0.1.0-alpha') in SpecItem('>=0.1.0-') # Include pre-release in checks False Including build identifiers in specifications """"""""""""""""""""""""""""""""""""""""""""" The same rule applies for the build identifier: comparisons will include it only -if it was included in the :class:`Spec` definition, or - for the unnumbered build +if it was included in the :class:`SpecItem` definition, or - for the unnumbered build version - if a single + is appended to the definition(``1.0.0+``, ``1.0.0-alpha+``):: - >>> Version('1.0.0+build2') in Spec('<=1.0.0') # Build identifier ignored + >>> Version('1.0.0+build2') in SpecItem('<=1.0.0') # Build identifier ignored True - >>> Version('1.0.0+build2') in Spec('<=1.0.0+') # Include build in checks + >>> Version('1.0.0+build2') in SpecItem('<=1.0.0+') # Include build in checks False Combining requirements ====================== -In order to express complex version specifications, use the :class:`SpecList` class:: +In order to express complex version specifications, use the :class:`Spec` class:: >>> # At least 0.1.1, not 0.2.0, avoid broken 0.1.5-alpha. - >>> sl = SpecList('>=0.1.1,<0.2.0,!=0.1.5-alpha') + >>> sl = Spec('>=0.1.1,<0.2.0,!=0.1.5-alpha') >>> sl.match(Version('0.1.1')) True >>> Version('0.1.1-rc1') in sl @@ -156,7 +156,7 @@ Using with Django ================= The :mod:`semantic_version.django_fields` module provides django fields to -store :class:`Version`, :class:`Spec` or :class:`SpecList` objects. +store :class:`Version`, :class:`SpecItem` or :class:`Spec` objects. More documentation is available in the :doc:`django` section. diff --git a/doc/reference.rst b/doc/reference.rst index 922bdf1..e785aa9 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -189,8 +189,8 @@ Representing a version (the Version class) :rtype: (major, minor, patch, prerelease, build) -Version specifications (the Spec class) ---------------------------------------- +Version specifications (the SpecItem class) +------------------------------------------- Version specifications describe a 'range' of accepted versions: @@ -215,13 +215,13 @@ In order to have version specification behave naturally, the rules are the follo This means that:: - >>> Version('1.1.1-rc1') in Spec('<1.1.1') + >>> Version('1.1.1-rc1') in SpecItem('<1.1.1') False - >>> Version('1.1.1-rc1') in Spec('<1.1.1-rc4') + >>> Version('1.1.1-rc1') in SpecItem('<1.1.1-rc4') True - >>> Version('1.1.1-rc1+build4') in Spec('<=1.1.1-rc1') + >>> Version('1.1.1-rc1+build4') in SpecItem('<=1.1.1-rc1') True - >>> Version('1.1.1-rc1+build4') in Spec('<=1.1.1-rc1+build2') + >>> Version('1.1.1-rc1+build4') in SpecItem('<=1.1.1-rc1+build2') False In order to force matches to *strictly* compare version numbers, these additional @@ -230,39 +230,39 @@ rules apply: * Setting a pre-release separator without a pre-release identifier (``<=1.1.1-``) forces match to take into account pre-release version:: - >>> Version('1.1.1-rc1') in Spec('<1.1.1') + >>> Version('1.1.1-rc1') in SpecItem('<1.1.1') False - >>> Version('1.1.1-rc1') in Spec('<1.1.1-') + >>> Version('1.1.1-rc1') in SpecItem('<1.1.1-') True * Setting a build separator without a build identifier (``>1.1.1+``) forces satisfaction tests to include both prerelease and build identifiers:: - >>> Version('1.1.1+build2') in Spec('>1.1.1') + >>> Version('1.1.1+build2') in SpecItem('>1.1.1') False - >>> Version('1.1.1+build2') in Spec('>1.1.1+') + >>> Version('1.1.1+build2') in SpecItem('>1.1.1+') True -.. class:: Spec(spec_string) +.. class:: SpecItem(spec_string) Stores a version specification, defined from a string:: - >>> Spec('>=0.1.1') - <Spec: >= <SemVer(0, 1, 1, [], [])>> + >>> SpecItem('>=0.1.1') + <SpecItem: >= <SemVer(0, 1, 1, [], [])>> - This allows to test :class:`Version` objects against the :class:`Spec`:: + This allows to test :class:`Version` objects against the :class:`SpecItem`:: - >>> Spec('>=0.1.1').match(Version('0.1.1-rc1')) # pre-release satisfy conditions + >>> SpecItem('>=0.1.1').match(Version('0.1.1-rc1')) # pre-release satisfy conditions True - >>> Version('0.1.1+build2') in Spec('>=0.1.1') # build version satisfy specifications + >>> Version('0.1.1+build2') in SpecItem('>=0.1.1') # build version satisfy specifications True >>> >>> # Use the '-' marker to include the pre-release component in checks - >>> Spec('>=0.1.1-').match(Version('0.1.1-rc1') + >>> SpecItem('>=0.1.1-').match(Version('0.1.1-rc1') False >>> >>> # Use the '+' marker to include the build identifier in checks - >>> Spec('<=0.1.1-alpha+').match(Version('0.1.1-alpha+build1')) + >>> SpecItem('<=0.1.1-alpha+').match(Version('0.1.1-alpha+build1')) False @@ -276,7 +276,7 @@ rules apply: .. attribute:: spec - :class:`Version` in the :class:`Spec` description. + :class:`Version` in the :class:`SpecItem` description. It is alway a :attr:`~Version.partial` :class:`Version`. @@ -298,11 +298,11 @@ rules apply: .. method:: match(self, version) - Test whether a given :class:`Version` matches this :class:`Spec`:: + Test whether a given :class:`Version` matches this :class:`SpecItem`:: - >>> Spec('>=0.1.1').match(Version('0.1.1-alpha')) + >>> SpecItem('>=0.1.1').match(Version('0.1.1-alpha')) True - >>> Spec('>=0.1.1-').match(Version('0.1.1-alpha')) + >>> SpecItem('>=0.1.1-').match(Version('0.1.1-alpha')) False :param version: The version to test against the spec @@ -315,15 +315,15 @@ rules apply: Alias of the :func:`match` method; allows the use of the ``version in spec`` syntax:: - >>> Version('1.1.1') in Spec('<=1.1.2') + >>> Version('1.1.1') in SpecItem('<=1.1.2') True .. method:: __str__(self) - Converting a :class:`Spec` to a string returns the initial description string:: + Converting a :class:`SpecItem` to a string returns the initial description string:: - >>> str(Spec('>=0.1.1')) + >>> str(SpecItem('>=0.1.1')) '>=0.1.1' @@ -331,7 +331,7 @@ rules apply: Provides a hash based solely on the current kind and the specified version. - Allows using a :class:`Spec` as a dictionary key. + Allows using a :class:`SpecItem` as a dictionary key. .. rubric:: Class attributes @@ -341,42 +341,42 @@ rules apply: The kind of 'Less than' specifications:: - >>> Version('1.0.0-alpha') in Spec('<1.0.0') + >>> Version('1.0.0-alpha') in SpecItem('<1.0.0') False .. data:: KIND_LTE The kind of 'Less or equal to' specifications:: - >>> Version('1.0.0-alpha1+build999') in Spec('<=1.0.0-alpha1') + >>> Version('1.0.0-alpha1+build999') in SpecItem('<=1.0.0-alpha1') True .. data:: KIND_EQUAL The kind of 'equal to' specifications:: - >>> Version('1.0.0+build3.3') in Spec('==1.0.0') + >>> Version('1.0.0+build3.3') in SpecItem('==1.0.0') True .. data:: KIND_GTE The kind of 'Greater or equal to' specifications:: - >>> Version('1.0.0') in Spec('>=1.0.0') + >>> Version('1.0.0') in SpecItem('>=1.0.0') True .. data:: KIND_GT The kind of 'Greater than' specifications:: - >>> Version('1.0.0+build667') in Spec('>1.0.1') + >>> Version('1.0.0+build667') in SpecItem('>1.0.1') False .. data:: KIND_NEQ The kind of 'Not equal to' specifications:: - >>> Version('1.0.1') in Spec('!=1.0.1') + >>> Version('1.0.1') in SpecItem('!=1.0.1') False The kind of 'Almost equal to' specifications @@ -384,37 +384,37 @@ rules apply: -Combining version specifications (the SpecList class) ------------------------------------------------------ +Combining version specifications (the Spec class) +------------------------------------------------- It may be useful to define a rule such as "Accept any version between the first 1.0.0 (incl. pre-release) and strictly before 1.2.0; ecluding 1.1.4 which was broken.". -This is possible with the :class:`SpecList` class. +This is possible with the :class:`Spec` class. -.. class:: SpecList(spec_string[, spec_string[, ...]]) +.. class:: Spec(spec_string[, spec_string[, ...]]) - Stores a list of :class:`Spec` and matches any :class:`Version` against all - contained :class:`specs <Spec>`. + Stores a list of :class:`SpecItem` and matches any :class:`Version` against all + contained :class:`specs <SpecItem>`. It is build from a comma-separated list of version specifications:: - >>> SpecList('>=1.0.0,<1.2.0,!=1.1.4') - <SpecList: ( - <Spec: >= <~SemVer: 1 0 0 None None>>, - <Spec: < <~SemVer: 1 2 0 None None>>, - <Spec: != <~SemVer: 1 1 4 None None>> + >>> Spec('>=1.0.0,<1.2.0,!=1.1.4') + <Spec: ( + <SpecItem: >= <~SemVer: 1 0 0 None None>>, + <SpecItem: < <~SemVer: 1 2 0 None None>>, + <SpecItem: != <~SemVer: 1 1 4 None None>> )> Version specifications may also be passed in separated arguments:: - >>> SpecList('>=1.0.0', '<1.2.0', '!=1.1.4,!=1.1.13') - <SpecList: ( - <Spec: >= <~SemVer: 1 0 0 None None>>, - <Spec: < <SemVer: 1 2 0 None None>>, - <Spec: != <~SemVer: 1 1 4 None None>> - <Spec: != <~SemVer: 1 1 13 None None>> + >>> Spec('>=1.0.0', '<1.2.0', '!=1.1.4,!=1.1.13') + <Spec: ( + <SpecItem: >= <~SemVer: 1 0 0 None None>>, + <SpecItem: < <SemVer: 1 2 0 None None>>, + <SpecItem: != <~SemVer: 1 1 4 None None>> + <SpecItem: != <~SemVer: 1 1 13 None None>> )> @@ -423,7 +423,7 @@ This is possible with the :class:`SpecList` class. .. attribute:: specs - Tuple of :class:`Spec`, the included specifications. + Tuple of :class:`SpecItem`, the included specifications. .. rubric:: Methods @@ -431,9 +431,9 @@ This is possible with the :class:`SpecList` class. .. method:: match(self, version) - Test whether a given :class:`Version` matches all included :class:`Spec`:: + Test whether a given :class:`Version` matches all included :class:`SpecItem`:: - >>> SpecList('>=1.1.0,<1.1.2').match(Version('1.1.1')) + >>> Spec('>=1.1.0,<1.1.2').match(Version('1.1.1')) True :param version: The version to test against the specs @@ -445,22 +445,22 @@ This is possible with the :class:`SpecList` class. Alias of the :func:`match` method; allows the use of the ``version in speclist`` syntax:: - >>> Version('1.1.1-alpha') in SpecList('>=1.1.0,<1.1.1') + >>> Version('1.1.1-alpha') in Spec('>=1.1.0,<1.1.1') True .. method:: __str__(self) - Converting a :class:`SpecList` returns the initial description string:: + Converting a :class:`Spec` returns the initial description string:: - >>> str(SpecList('>=0.1.1,!=0.1.2')) + >>> str(Spec('>=0.1.1,!=0.1.2')) '>=0.1.1,!=0.1.2' .. method:: __iter__(self) Returns an iterator over the contained specs:: - >>> for spec in SpecList('>=0.1.1,!=0.1.2'): + >>> for spec in Spec('>=0.1.1,!=0.1.2'): ... print spec >=0.1.1 !=0.1.2 @@ -469,7 +469,7 @@ This is possible with the :class:`SpecList` class. Provides a hash based solely on the hash of contained specs. - Allows using a :class:`SpecList` as a dictionary key. + Allows using a :class:`Spec` as a dictionary key. .. rubric:: Class methods diff --git a/src/semantic_version/__init__.py b/src/semantic_version/__init__.py index fb4cf2f..9075b70 100644 --- a/src/semantic_version/__init__.py +++ b/src/semantic_version/__init__.py @@ -5,4 +5,4 @@ __version__ = '1.3.0-alpha' -from .base import compare, match, Version, Spec, SpecList +from .base import compare, match, Version, Spec, SpecItem diff --git a/src/semantic_version/base.py b/src/semantic_version/base.py index 7b26981..4f177b2 100644 --- a/src/semantic_version/base.py +++ b/src/semantic_version/base.py @@ -235,7 +235,7 @@ class Version(object): return 0 -class Spec(object): +class SpecItem(object): """A requirement specification.""" KIND_LT = '<' @@ -299,10 +299,10 @@ class Spec(object): return '%s%s' % (self.kind, self.spec) def __repr__(self): - return '<Spec: %s %r>' % (self.kind, self.spec) + return '<SpecItem: %s %r>' % (self.kind, self.spec) def __eq__(self, other): - if not isinstance(other, Spec): + if not isinstance(other, SpecItem): return NotImplemented return self.kind == other.kind and self.spec == other.spec @@ -310,7 +310,7 @@ class Spec(object): return hash((self.kind, self.spec)) -class SpecList(object): +class Spec(object): def __init__(self, *specs_strings): subspecs = [self.parse(spec) for spec in specs_strings] self.specs = sum(subspecs, ()) @@ -318,7 +318,7 @@ class SpecList(object): @classmethod def parse(self, specs_string): spec_texts = specs_string.split(',') - return tuple(Spec(spec_text) for spec_text in spec_texts) + return tuple(SpecItem(spec_text) for spec_text in spec_texts) def match(self, version): return all(spec.match(version) for spec in self.specs) @@ -335,10 +335,10 @@ class SpecList(object): return ','.join(str(spec) for spec in self.specs) def __repr__(self): - return '<SpecList: %r>' % (self.specs,) + return '<Spec: %r>' % (self.specs,) def __eq__(self, other): - if not isinstance(other, SpecList): + if not isinstance(other, Spec): return NotImplemented return set(self.specs) == set(other.specs) diff --git a/src/semantic_version/django_fields.py b/src/semantic_version/django_fields.py index 1495bd1..7cc5d44 100644 --- a/src/semantic_version/django_fields.py +++ b/src/semantic_version/django_fields.py @@ -46,31 +46,31 @@ class VersionField(BaseSemVerField): return base.Version(value, partial=self.partial) -class SpecField(BaseSemVerField): +class SpecItemField(BaseSemVerField): default_error_messages = { 'invalid': _(u"Enter a valid version number spec in ==X.Y.Z format."), } description = _(u"Version specification") def to_python(self, value): - """Converts any value to a base.Spec field.""" + """Converts any value to a base.SpecItem field.""" if value is None or value == '': return value - if isinstance(value, base.Spec): + if isinstance(value, base.SpecItem): return value - return base.Spec(value) + return base.SpecItem(value) -class SpecListField(BaseSemVerField): +class SpecField(BaseSemVerField): default_error_messages = { 'invalid': _(u"Enter a valid version number spec list in ==X.Y.Z,>=A.B.C format."), } description = _(u"Version specification list") def to_python(self, value): - """Converts any value to a base.SpecList field.""" + """Converts any value to a base.Spec field.""" if value is None or value == '': return value - if isinstance(value, base.SpecList): + if isinstance(value, base.Spec): return value - return base.SpecList(value) + return base.Spec(value) diff --git a/tests/django_test_app/models.py b/tests/django_test_app/models.py index df654e2..8e1f2ce 100644 --- a/tests/django_test_app/models.py +++ b/tests/django_test_app/models.py @@ -7,13 +7,13 @@ 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') - speclist = semver_fields.SpecListField(verbose_name='my spec list') + spec = semver_fields.SpecItemField(verbose_name='my spec') + speclist = semver_fields.SpecField(verbose_name='my spec list') 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) - optional_speclist = semver_fields.SpecListField(verbose_name='optional spec list', + optional_spec = semver_fields.SpecItemField(verbose_name='optional spec', blank=True, null=True) + optional_speclist = semver_fields.SpecField(verbose_name='optional spec list', blank=True, null=True) diff --git a/tests/test_base.py b/tests/test_base.py index 49133c1..41ec6cf 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -161,25 +161,25 @@ class VersionTestCase(unittest.TestCase): ) -class SpecTestCase(unittest.TestCase): +class SpecItemTestCase(unittest.TestCase): components = { - '==0.1.0': (base.Spec.KIND_EQUAL, 0, 1, 0, None, None), - '==0.1.2-rc3': (base.Spec.KIND_EQUAL, 0, 1, 2, ('rc3',), None), - '==0.1.2+build3.14': (base.Spec.KIND_EQUAL, 0, 1, 2, (), ('build3', '14')), - '<=0.1.1+': (base.Spec.KIND_LTE, 0, 1, 1, (), ()), - '<0.1.1': (base.Spec.KIND_LT, 0, 1, 1, None, None), - '<=0.1.1': (base.Spec.KIND_LTE, 0, 1, 1, None, None), - '>=0.2.3-rc2': (base.Spec.KIND_GTE, 0, 2, 3, ('rc2',), None), - '>0.2.3-rc2+': (base.Spec.KIND_GT, 0, 2, 3, ('rc2',), ()), - '>=2.0.0': (base.Spec.KIND_GTE, 2, 0, 0, None, None), - '!=0.1.1+': (base.Spec.KIND_NEQ, 0, 1, 1, (), ()), - '!=0.3.0': (base.Spec.KIND_NEQ, 0, 3, 0, None, None), + '==0.1.0': (base.SpecItem.KIND_EQUAL, 0, 1, 0, None, None), + '==0.1.2-rc3': (base.SpecItem.KIND_EQUAL, 0, 1, 2, ('rc3',), None), + '==0.1.2+build3.14': (base.SpecItem.KIND_EQUAL, 0, 1, 2, (), ('build3', '14')), + '<=0.1.1+': (base.SpecItem.KIND_LTE, 0, 1, 1, (), ()), + '<0.1.1': (base.SpecItem.KIND_LT, 0, 1, 1, None, None), + '<=0.1.1': (base.SpecItem.KIND_LTE, 0, 1, 1, None, None), + '>=0.2.3-rc2': (base.SpecItem.KIND_GTE, 0, 2, 3, ('rc2',), None), + '>0.2.3-rc2+': (base.SpecItem.KIND_GT, 0, 2, 3, ('rc2',), ()), + '>=2.0.0': (base.SpecItem.KIND_GTE, 2, 0, 0, None, None), + '!=0.1.1+': (base.SpecItem.KIND_NEQ, 0, 1, 1, (), ()), + '!=0.3.0': (base.SpecItem.KIND_NEQ, 0, 3, 0, None, None), } def test_components(self): for spec_text, components in self.components.items(): kind, major, minor, patch, prerelease, build = components - spec = base.Spec(spec_text) + spec = base.SpecItem(spec_text) self.assertEqual(kind, spec.kind) self.assertEqual(major, spec.spec.major) @@ -244,7 +244,7 @@ class SpecTestCase(unittest.TestCase): def test_matches(self): for spec_text, versions in self.matches.items(): - spec = base.Spec(spec_text) + spec = base.SpecItem(spec_text) matching, failing = versions for version_text in matching: @@ -260,22 +260,22 @@ class SpecTestCase(unittest.TestCase): "%r should not match %r" % (version, spec)) def test_equality(self): - spec1 = base.Spec('==0.1.0') - spec2 = base.Spec('==0.1.0') + spec1 = base.SpecItem('==0.1.0') + spec2 = base.SpecItem('==0.1.0') self.assertEqual(spec1, spec2) self.assertFalse(spec1 == '==0.1.0') def test_to_string(self): - spec = base.Spec('==0.1.0') + spec = base.SpecItem('==0.1.0') self.assertEqual('==0.1.0', str(spec)) - self.assertEqual(base.Spec.KIND_EQUAL, spec.kind) + self.assertEqual(base.SpecItem.KIND_EQUAL, spec.kind) def test_hash(self): self.assertEqual(1, - len(set([base.Spec('==0.1.0'), base.Spec('==0.1.0')]))) + len(set([base.SpecItem('==0.1.0'), base.SpecItem('==0.1.0')]))) -class SpecListTestCase(unittest.TestCase): +class SpecTestCase(unittest.TestCase): examples = { '>=0.1.1,<0.1.2': ['>=0.1.1', '<0.1.2'], '>=0.1.0,!=0.1.3-rc1,<0.1.3': ['>=0.1.0', '!=0.1.3-rc1', '<0.1.3'], @@ -283,14 +283,14 @@ class SpecListTestCase(unittest.TestCase): def test_parsing(self): for spec_list_text, specs in self.examples.items(): - spec_list = base.SpecList(spec_list_text) + spec_list = base.Spec(spec_list_text) self.assertEqual(spec_list_text, str(spec_list)) self.assertNotEqual(spec_list_text, spec_list) self.assertEqual(specs, [str(spec) for spec in spec_list]) for spec_text in specs: - self.assertTrue(repr(base.Spec(spec_text)) in repr(spec_list)) + self.assertTrue(repr(base.SpecItem(spec_text)) in repr(spec_list)) split_examples = { ('>=0.1.1', '<0.1.2', '!=0.1.1+build1'): ['>=0.1.1', '<0.1.2', '!=0.1.1+build1'], @@ -299,14 +299,14 @@ class SpecListTestCase(unittest.TestCase): def test_parsing_split(self): for spec_list_texts, specs in self.split_examples.items(): - spec_list = base.SpecList(*spec_list_texts) + spec_list = base.Spec(*spec_list_texts) self.assertEqual(','.join(spec_list_texts), str(spec_list)) self.assertEqual(specs, [str(spec) for spec in spec_list]) - self.assertEqual(spec_list, base.SpecList(','.join(spec_list_texts))) + self.assertEqual(spec_list, base.Spec(','.join(spec_list_texts))) for spec_text in specs: - self.assertTrue(repr(base.Spec(spec_text)) in repr(spec_list)) + self.assertTrue(repr(base.SpecItem(spec_text)) in repr(spec_list)) matches = { '>=0.1.1,<0.1.2': ( @@ -322,7 +322,7 @@ class SpecListTestCase(unittest.TestCase): def test_matches(self): for spec_list_text, versions in self.matches.items(): - spec_list = base.SpecList(spec_list_text) + spec_list = base.Spec(spec_list_text) matching, failing = versions for version_text in matching: @@ -341,17 +341,17 @@ class SpecListTestCase(unittest.TestCase): def test_equality(self): for spec_list_text in self.examples: - slist1 = base.SpecList(spec_list_text) - slist2 = base.SpecList(spec_list_text) + slist1 = base.Spec(spec_list_text) + slist2 = base.Spec(spec_list_text) self.assertEqual(slist1, slist2) self.assertFalse(slist1 == spec_list_text) def test_contains(self): - self.assertFalse('ii' in base.SpecList('>=0.1.1')) + self.assertFalse('ii' in base.Spec('>=0.1.1')) def test_hash(self): self.assertEqual(1, - len(set([base.SpecList('>=0.1.1'), base.SpecList('>=0.1.1')]))) + len(set([base.Spec('>=0.1.1'), base.Spec('>=0.1.1')]))) if __name__ == '__main__': # pragma: no cover diff --git a/tests/test_django.py b/tests/test_django.py index d8eef7d..5768c47 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -38,14 +38,14 @@ class DjangoFieldTestCase(unittest.TestCase): obj = models.VersionModel(version='0.1.1', spec='>0.1.0', speclist='==0.1.1,!=0.1.1-alpha') self.assertEqual(semantic_version.Version('0.1.1'), obj.version) - self.assertEqual(semantic_version.Spec('>0.1.0'), obj.spec) - self.assertEqual(semantic_version.SpecList('==0.1.1,!=0.1.1-alpha'), obj.speclist) + self.assertEqual(semantic_version.SpecItem('>0.1.0'), obj.spec) + self.assertEqual(semantic_version.Spec('==0.1.1,!=0.1.1-alpha'), obj.speclist) alt_obj = models.VersionModel(version=obj.version, spec=obj.spec, speclist=obj.speclist) self.assertEqual(semantic_version.Version('0.1.1'), alt_obj.version) - self.assertEqual(semantic_version.Spec('>0.1.0'), alt_obj.spec) - self.assertEqual(semantic_version.SpecList('==0.1.1,!=0.1.1-alpha'), alt_obj.speclist) + self.assertEqual(semantic_version.SpecItem('>0.1.0'), alt_obj.spec) + self.assertEqual(semantic_version.Spec('==0.1.1,!=0.1.1-alpha'), alt_obj.speclist) self.assertEqual(obj.spec, alt_obj.spec) self.assertEqual(obj.version, alt_obj.version) self.assertEqual(obj.speclist, alt_obj.speclist) |