예제 #1
0
class PgMajorVersion(Version):
    """A major PostgreSQL version.

    This version scheme has two segments that identify the major PostgreSQL
    version, which includes new features and requires a dump/reload of the
    database or use of the pg_upgrade module.  It is the base for the more
    detailed PostgreSQL version classes and is mostly only useful itself for
    comparison.  For example:

    >>> pg83 = PgMajorVersion(8.3)
    >>> my_version = PgVersion('8.3.4')
    >>> assert(my_version.major_version == pg83)

    """

    SEGMENT_DEFINITIONS = (
        SegmentDefinition(name='major1', ),
        SegmentDefinition(name='major2', ),
    )

    @property
    def major_version(self):
        """Return a new `PgMajorVersion` with the object's values.

        This is mainly useful in subclasses.

        """
        return PgMajorVersion(self[MAJOR1], self[MAJOR2])
예제 #2
0
 class Version1(Version):
     SEGMENT_DEFINITIONS = (
         SegmentDefinition(name='first'),
         SegmentDefinition(name='second', default=2),
         SegmentDefinition(name='third', optional=True, default=3),
         SegmentDefinition(name='fourth', optional=True, default=4),
         SegmentDefinition(name='fifth', optional=True, default=5),
     )
예제 #3
0
 class Version1(Version):
     SEGMENT_DEFINITIONS = (
         SegmentDefinition(
             optional=True,
             default=0,
         ),
         SegmentDefinition(separator='',
                           fields=SegmentField(type=str,
                                               re_pattern='[a-z]')),
     )
예제 #4
0
class PythonMinorVersion(PythonMajorVersion):
    """A minor Python version.

    This version scheme has two segments that identify the minor Python
    version, which is incremented for less earth-shattering changes in the
    language than a major version increment.  It is the base for the more
    detailed Python version classes and is mostly only useful itself for
    comparison.  For example:

    >>> python33 = PythonMinorVersion(3, 3)
    >>> my_python_version = PythonVersion(3, 4, 2)
    >>> assert(my_python_version.minor_version > python33)

    """

    SEGMENT_DEFINITIONS = PythonMajorVersion.SEGMENT_DEFINITIONS + (
        SegmentDefinition(name='minor', ), )

    @property
    def minor_version(self):
        """Return a new `PythonMinorVersion` with the object's values.

        This is mainly useful in subclasses.

        """
        return PythonMinorVersion(self[MAJOR], self[MINOR])
예제 #5
0
class PythonMicroVersion(PythonMinorVersion):
    """A micro Python version.

    This version scheme has three segments that identify the micro Python
    version, which is incremented for each bugfix release (see `PEP 6
    <http://legacy.python.org/dev/peps/pep-0006/>`_).  It is the base for the
    more detailed Python version classes and is mostly only useful itself for
    comparison.  For example:

    >>> python301 = PythonMicroVersion(3, 0, 1)
    >>> my_python_version = PythonVersion(3, 0, 1, ('b', 1))
    >>> assert(my_python_version.micro_version == python301)

    """

    SEGMENT_DEFINITIONS = PythonMinorVersion.SEGMENT_DEFINITIONS + (
        SegmentDefinition(
            name='micro',
            optional=True,
        ), )

    @property
    def micro_version(self):
        """Return a new `PythonMicroVersion` with the object's values.

        This is mainly useful in subclasses.

        """
        return PythonMicroVersion(self[MAJOR], self[MINOR], self[MICRO])
예제 #6
0
class PythonVersion(PythonMicroVersion):
    """A complete, specific Python version.

    This version scheme has four segments that identify a specific version of
    Python.  See the link in the module documentation for details about the
    Python version scheme.

    """

    SEGMENT_DEFINITIONS = PythonMicroVersion.SEGMENT_DEFINITIONS + (
        SegmentDefinition(
            name='suffix',
            optional=True,
            separator='',
            fields=(
                SegmentField(
                    type=str,
                    name='releaselevel',
                    re_pattern='[+abc]',
                ),
                SegmentField(
                    name='serial',
                    re_pattern='(?<=[+])|(?<![+])(?:0|[1-9][0-9]*)',
                    render=lambda x: "" if x is None else str(x),
                ),
            ),
        ), )

    @property
    def is_nondevelopment(self):
        """Whether this version represents a non-development release.

        This simply says whether it is equivalent to its `micro_version`; that
        is, whether the `SUFFIX`-index value is `None`.

        >>> assert(PythonVersion('3.4.1').is_nondevelopment)
        >>> assert(not PythonVersion('3.4.1c1').is_nondevelopment)
        >>> assert(not PythonVersion('3.4.1+').is_nondevelopment)

        """
        return self[SUFFIX] is None

    @property
    def is_release(self):
        """Whether this version represents a release.

        This simply says whether the `SUFFIX`-index value is not '+'.  A '+'
        indicates that it is an unreleased version, built directly from the
        Subversion trunk; anything else is a release (be it development or
        non-development).

        >>> assert(PythonVersion('3.4.1').is_release)
        >>> assert(PythonVersion('3.4.1c1').is_release)
        >>> assert(not PythonVersion('3.4.1+').is_release)

        """
        suffix = self[SUFFIX]
        return suffix is None or suffix.releaselevel != '+'
예제 #7
0
 def test_validate_value_partial(self):
     sd = SegmentDefinition(fields=(
         SegmentField(name='a'),
         SegmentField(name='b',
                      re_pattern='(?<=[0])|(?<![0])(?:0|[1-9][0-9]*)',
                      render=lambda x: "" if x is None else str(x))))
     self.assertEqual((0, None), sd.validate_value((0, None)))
     self.assertEqual((0, None), sd.validate_value((0, )))
     self.assertRaises(ValueError, sd.validate_value, (0, 3))
     self.assertEqual((1, 2), sd.validate_value((1, 2)))
     self.assertRaises(ValueError, sd.validate_value, (1, ))
예제 #8
0
 class Version1(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(optional=True, default=1),
                            SegmentDefinition(default=2),
                            SegmentDefinition(),
                            SegmentDefinition(optional=True, default=4),
                            SegmentDefinition(),
                            SegmentDefinition(optional=True))
예제 #9
0
class PgVersion(PgMajorVersion):
    """A complete, specific PostgreSQL version.

    This version scheme has three segments that identify a specific release of
    PostgreSQL.

    """

    SEGMENT_DEFINITIONS = PgMajorVersion.SEGMENT_DEFINITIONS + (
        SegmentDefinition(
            name='minor',
            optional=True,
            default=0,
        ), )
예제 #10
0
class PythonMajorVersion(Version):
    """A major Python version.

    This version scheme has one segment that identifies the major Python
    version, which is only incremented for really major changes in the
    language.  It is the base for the more detailed Python version classes and
    is mostly only useful itself for comparison.  For example:

    >>> python2 = PythonMajorVersion(2)
    >>> my_python_version = PythonVersion('2.7.1')
    >>> assert(my_python_version.major_version == python2)

    """

    SEGMENT_DEFINITIONS = (SegmentDefinition(name='major', ), )

    @property
    def major_version(self):
        """Return a new `PythonMajorVersion` with the object's values.

        This is mainly useful in subclasses.

        """
        return PythonMajorVersion(self[MAJOR])
예제 #11
0
class XorgVersion(Version):

    SEGMENT_DEFINITIONS = (
        SegmentDefinition(
            name='major',
        ),
        SegmentDefinition(
            name='minor',
            default=0,
        ),
        SegmentDefinition(
            name='patch',
            default=0,
        ),
        SegmentDefinition(
            name='snapshot',
            optional=True,
            default=0,
        ),
    )

    def validate(self):
        """Override for version scheme validations."""
        if self.is_pre_full_release:
            if self.is_release:
                raise ValueError(
                    "Pre-full-release versions (patch = {}) must have a "
                    "snapshot > 0."
                    .format(PRE_FULL_RELEASE))
        elif self.is_development:
            raise ValueError(
                "Development versions (0 < snapshot < {}) are only valid for "
                "development branches (patch = {})."
                .format(BRANCH_START_SNAPSHOT, PRE_FULL_RELEASE))

    @property
    def is_release(self):
        """Whether the version identifies a release."""
        return (self[SNAPSHOT] or 0) == 0

    @property
    def is_full_release(self):
        """Whether the version identifies a full release."""
        return self.is_release and self[PATCH] == 0

    @property
    def is_pre_full_release(self):
        """Whether the version is between feature freeze and a full release."""
        return self[PATCH] == PRE_FULL_RELEASE

    @property
    def is_bugfix_release(self):
        """Whether the version identifies a bug-fix release."""
        return self.is_release and not self.is_full_release

    @property
    def is_development(self):
        """Whether the version is a non-release prior to feature freeze."""
        return 0 < self[SNAPSHOT] < BRANCH_START_SNAPSHOT

    @property
    def is_branch_start(self):
        """Whether the version is the start of a release branch."""
        return self[SNAPSHOT] == BRANCH_START_SNAPSHOT

    @property
    def is_release_candidate(self):
        """Whether the version identifies a release candidate."""
        return self[SNAPSHOT] > BRANCH_START_SNAPSHOT

    @property
    def release_candidate(self):
        """The release candidate number if it is a release candidate."""
        return ((self[SNAPSHOT] - BRANCH_START_SNAPSHOT)
                if self.is_release_candidate else None)

    @property
    def stable_branch_suffix(self):
        """The suffix of the stable branch name if not in development."""
        if self.is_development:
            return
        major, minor = self[MAJOR], self[MINOR]
        if self.is_pre_full_release:
            if minor == PRE_FULL_RELEASE:
                minor = 0
                major += 1
            else:
                minor += 1
        return '-{}.{}-branch'.format(major, minor)
예제 #12
0
 def test_render_muliple_fields(self):
     sd = SegmentDefinition(fields=(SegmentField(name='a'),
                                    SegmentField(name='b')))
     self.assertEqual('138', sd.render((13, 8)))
예제 #13
0
 def test_init_fields_noniterable(self):
     self.assertEqual(SegmentDefinition(),
                      SegmentDefinition(fields=SegmentField()))
예제 #14
0
 class VersionNamedConflict(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(name='render'),
                            SegmentDefinition(name='second'),
                            SegmentDefinition(name='replace'))
예제 #15
0
 def test_validate_value_missing(self):
     sd = SegmentDefinition()
     self.assertRaises(ValueError, sd.validate_value, None)
예제 #16
0
 def test_ne_name(self):
     self.assertNotEqual(SegmentDefinition(name='different1'),
                         SegmentDefinition(name='different2'))
예제 #17
0
 def test_validate_value(self):
     sd = SegmentDefinition(fields=(SegmentField(name='a'),
                                    SegmentField(name='b')))
     self.assertEqual((1, 2), sd.validate_value((1, 2)))
     self.assertEqual((4, 3), sd.validate_value([4, 3]))
예제 #18
0
 class Version1(Version):
     SEGMENT_DEFINITIONS = (
         SegmentDefinition(),
         SegmentDefinition(separator_re_pattern='[.,-]'),
     )
예제 #19
0
 def test_eq_name(self):
     self.assertEqual(SegmentDefinition(name='same'),
                      SegmentDefinition(name='same'))
예제 #20
0
 class Version1(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(default=1), )
예제 #21
0
 def test_init_segment_name_duplicate(self):
     self.assertRaises(
         ValueError, type, 'VersionBad', (Version, ),
         dict(SEGMENT_DEFINITIONS=(SegmentDefinition(name='oops'),
                                   SegmentDefinition(name='unique'),
                                   SegmentDefinition(name='oops'))))
예제 #22
0
 def test_init_definitions_all_optional(self):
     self.assertRaises(
         ValueError, type, 'Version1', (Version, ),
         dict(SEGMENT_DEFINITIONS=(
             SegmentDefinition(optional=True, default=0),
             SegmentDefinition(optional=True, default=0))))
예제 #23
0
 def test_render(self):
     sd = SegmentDefinition()
     self.assertEqual('5', sd.render(5))
예제 #24
0
 class VersionNamed(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(name='first'),
                            SegmentDefinition(name='second'),
                            SegmentDefinition(name='third'))
예제 #25
0
 class VersionNamedWithDefault(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(name='first'),
                            SegmentDefinition(name='second', default=6),
                            SegmentDefinition(name='third'))
예제 #26
0
 def test_eq_default(self):
     self.assertEqual(SegmentDefinition(), SegmentDefinition())
예제 #27
0
 class VersionString(Version):
     SEGMENT_DEFINITIONS = (SegmentDefinition(fields=SegmentField(
         type=str, re_pattern='[0-9]+(?:[.][0-9]+)*')), )