Пример #1
0
def test_pep440_compat():
    """Make sure we can generate appropriate pep440 range specifiers."""

    assert SemanticVersion.FromString(
        '1.2.3').pep440_compatibility_specifier() == '>= 1.2.3, == 1.*'
    assert SemanticVersion.FromString(
        '1.2.3-alpha4').pep440_compatibility_specifier(
        ) == '>= 1.2.3a4, == 1.*'

    req_rel = pkg_resources.Requirement.parse(
        'abc ' +
        SemanticVersion.FromString('1.2.3').pep440_compatibility_specifier())
    req_pre = pkg_resources.Requirement.parse(
        'abc ' + SemanticVersion.FromString(
            '1.2.3-alpha4').pep440_compatibility_specifier())

    print(str(req_rel))
    print(str(req_pre))

    assert not '1.2.2' in req_rel
    assert '1.2.3' in req_rel
    assert '1.3.0' in req_rel
    assert not '2.0.0' in req_rel

    assert '1.2.3' in req_pre
    assert '1.3.0' in req_pre
    assert '1.2.3b1' in req_pre
    assert not '2.0.0' in req_pre
Пример #2
0
def test_ordering_prereleases():
    build = SemanticVersion.FromString('0.1.2-build10')
    alpha = SemanticVersion.FromString('0.1.2-alpha9')
    beta = SemanticVersion.FromString('0.1.2-beta8')
    rc = SemanticVersion.FromString('0.1.2-rc7')
    bump = SemanticVersion.FromString('0.1.3-build1')

    assert build < alpha < beta < rc < bump
Пример #3
0
def test_star():
    """Make sure wildcard matching works."""

    ver_range = SemanticVersionRange.FromString('*')

    ver = SemanticVersion.FromString('1.0.0')
    ver2 = SemanticVersion.FromString('0.0.1-alpha1')

    assert ver_range.check(ver)
    assert ver_range.check(ver2)
Пример #4
0
def test_pep440():
    """Make sure we can generate pep440 compliant strings."""

    assert SemanticVersion.FromString(
        '1.2.3-alpha4').pep440_string() == '1.2.3a4'
    assert SemanticVersion.FromString(
        '1.2.3-beta4').pep440_string() == '1.2.3b4'
    assert SemanticVersion.FromString(
        '1.2.3-rc4').pep440_string() == '1.2.3rc4'
    assert SemanticVersion.FromString(
        '1.2.3-build4').pep440_string() == '1.2.3.dev4'
Пример #5
0
def test_inc_patch():
    ver = SemanticVersion.FromString('0.0.1')
    assert str(ver.inc_release()) == '0.0.2'

    ver = SemanticVersion.FromString('0.0.1-rc2')
    assert str(ver.inc_release()) == '0.0.2'

    ver = SemanticVersion.FromString('0.1.2')
    assert str(ver.inc_release()) == '0.1.3'

    ver = SemanticVersion.FromString('1.2.3')
    assert str(ver.inc_release()) == '1.2.4'
Пример #6
0
def test_inc_nonzero():
    """Make sure incrementing the first nonzero release component works
    """

    ver = SemanticVersion.FromString('0.0.1')
    assert str(ver.inc_first_nonzero()) == '0.0.2'

    ver = SemanticVersion.FromString('0.0.1-rc2')
    assert str(ver.inc_first_nonzero()) == '0.0.2'

    ver = SemanticVersion.FromString('0.1.2')
    assert str(ver.inc_first_nonzero()) == '0.2.0'

    ver = SemanticVersion.FromString('1.2.3')
    assert str(ver.inc_first_nonzero()) == '2.0.0'
Пример #7
0
def test_hash():
    """Make sure hashing SemanticVersions works
    """

    ver = SemanticVersion.FromString('0.1.2-alpha2')
    ver2 = SemanticVersion.FromString('0.1.2-alpha2')
    ver3 = SemanticVersion.FromString('0.2.2')

    assert hash(ver) == hash(ver2)
    assert hash(ver3) != hash(ver)
    assert ver == ver2
    assert ver != ver3

    version_set = set([ver, ver2, ver3])
    assert len(version_set) == 2
Пример #8
0
def test_basic_parsing():
    ver1 = SemanticVersion.FromString('1.2.3')

    assert ver1.major == 1 and ver1.minor == 2 and ver1.patch == 3
    assert ver1.release_type == 'release'
    assert ver1.is_release is True
    assert ver1.is_prerelease is False
Пример #9
0
def test_advanced_parsing():
    ver = SemanticVersion.FromString('0.1.2-alpha2')
    assert ver.major == 0
    assert ver.minor == 1
    assert ver.patch == 2
    assert ver.is_prerelease is True
    assert ver.release_type == 'alpha'
    assert ver.prerelease_number == 2
Пример #10
0
    def _check_criteria(self, criterion):

        for criteria in criterion:
            text, opr, value = criteria.split(":")
            if text == 'os_tag':
                if self.os_info[0] != int(value):
                    iprint("os_tag doesn't match: " + str(self.os_info[0]) +
                           " != " + value)
                    return False

            elif text == 'app_tag':
                if self.app_info[0] != int(value):
                    iprint("app_tag doesn't match: " + str(self.app_info[0]) +
                           " != " + value)
                    return False

            elif text == 'os_version':
                ver = SemanticVersion.FromString(value)
                if op_map[opr](self.os_info[1], ver):
                    iprint("os_version not compatible: " +
                           str(self.os_info[1]) + "not" + opr + value)
                    return False

            elif text == 'app_version':
                ver = SemanticVersion.FromString(value)
                if op_map[opr](self.app_info[1], ver):
                    iprint("app_version not compatible: " +
                           str(self.app_info[1]) + "not" + opr + value)
                    return False

            elif text == 'controller_hw_tag':
                # TODO : figure out what the check here should be
                if opr not in ('eq', '=='):
                    iprint("op needed: eq, op seen: " + opr)
                    return False
                if self._con.hardware_version() != value:
                    return False
            else:
                iprint("Unrecognized selection criteria tag : " + text)
                return None

        return True
Пример #11
0
def test_filtering_keys():
    """Make sure we can filter using a key."""

    ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')

    in1 = (SemanticVersion.FromString('2.0.0'), 'a')
    in2 = (SemanticVersion.FromString('2.1.1'), 'b')

    out1 = (SemanticVersion.FromString('2.0.0-alpha1'), 'c')

    inlist = [in1, in2, out1]

    outlist = ver_range.filter(inlist, key=lambda x: x[0])
    outset = set(outlist)

    assert len(outset) == 2

    assert in1 in outset
    assert in2 in outset
    assert out1 not in outset
Пример #12
0
def test_filtering():
    """Make sure we can filter a range of versions against a spec."""

    ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')

    in1 = SemanticVersion.FromString('2.0.0')
    in2 = SemanticVersion.FromString('2.1.1')

    out1 = SemanticVersion.FromString('2.0.0-alpha1')

    inlist = [in1, in2, out1]

    outlist = ver_range.filter(inlist)
    outset = set(outlist)

    assert len(outset) == 2

    assert in1 in outset
    assert in2 in outset
    assert out1 not in outset
Пример #13
0
def test_equals():
    """Make sure =X.Y.Z version ranges work."""

    ver_range = SemanticVersionRange.FromString('=0.0.1')
    assert ver_range.check(SemanticVersion.FromString('0.0.1'))
    assert not ver_range.check(SemanticVersion.FromString('0.0.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('0.0.2'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.1'))

    ver_range = SemanticVersionRange.FromString('=0.1.1')
    assert ver_range.check(SemanticVersion.FromString('0.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('0.2.1'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.0'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.1'))

    ver_range = SemanticVersionRange.FromString('=1.1.1')
    assert ver_range.check(SemanticVersion.FromString('1.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('0.0.2'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('1.2.1'))

    ver_range = SemanticVersionRange.FromString('=1.1.1-alpha2')
    assert ver_range.check(SemanticVersion.FromString('1.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.1-alpha3'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.1'))
Пример #14
0
def test_ordering_releases():
    major = SemanticVersion.FromString('1.0.0')
    minor = SemanticVersion.FromString('0.9.0')
    patch = SemanticVersion.FromString('0.8.9')

    assert patch < minor < major
Пример #15
0
def test_carrot():
    """Make sure semantic version operator works ^X.Y.Z."""

    ver_range = SemanticVersionRange.FromString('^0.0.1')

    print("Lower: %s" % ver_range._disjuncts[0][0][0])
    print("Upper: %s" % ver_range._disjuncts[0][0][1])

    assert ver_range.check(SemanticVersion.FromString('0.0.1'))
    assert not ver_range.check(SemanticVersion.FromString('0.0.2'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.0'))
    assert not ver_range.check(SemanticVersion.FromString('0.0.2-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.0'))

    ver_range = SemanticVersionRange.FromString('^0.1.0')

    print("Lower: %s" % ver_range._disjuncts[0][0][0])
    print("Upper: %s" % ver_range._disjuncts[0][0][1])

    assert ver_range.check(SemanticVersion.FromString('0.1.0'))
    assert ver_range.check(SemanticVersion.FromString('0.1.1'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.0'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.0'))

    ver_range = SemanticVersionRange.FromString('^2.0.0')

    print("Lower: %s" % ver_range._disjuncts[0][0][0])
    print("Upper: %s" % ver_range._disjuncts[0][0][1])

    assert ver_range.check(SemanticVersion.FromString('2.0.0'))
    assert ver_range.check(SemanticVersion.FromString('2.1.1'))
    assert ver_range.check(SemanticVersion.FromString('2.0.1'))
    assert not ver_range.check(SemanticVersion.FromString('2.0.1-alpha1'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.0'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.0'))

    #Make sure prerelease checking works in lower bound
    ver_range = SemanticVersionRange.FromString('^2.0.0-alpha2')

    print("Lower: %s" % ver_range._disjuncts[0][0][0])
    print("Upper: %s" % ver_range._disjuncts[0][0][1])

    assert ver_range.check(SemanticVersion.FromString('2.0.0'))
    assert ver_range.check(SemanticVersion.FromString('2.1.1'))
    assert ver_range.check(SemanticVersion.FromString('2.0.1'))
    assert ver_range.check(SemanticVersion.FromString('2.0.0-alpha2'))
    assert ver_range.check(SemanticVersion.FromString('2.0.0-beta1'))
    assert not ver_range.check(SemanticVersion.FromString('2.0.0-alpha1'))
    assert not ver_range.check(SemanticVersion.FromString('2.0.1-alpha1'))
    assert not ver_range.check(SemanticVersion.FromString('1.1.0'))
    assert not ver_range.check(SemanticVersion.FromString('0.1.1-alpha2'))
    assert not ver_range.check(SemanticVersion.FromString('1.0.0'))
Пример #16
0
def test_ordering_release_over_pre():
    ver1 = SemanticVersion.FromString('0.1.2')
    ver2 = SemanticVersion.FromString('0.1.2-rc1')

    assert ver2 < ver1
    assert ver1 > ver2
Пример #17
0
def test_equality():
    ver1 = SemanticVersion.FromString('0.1.2-alpha2')
    ver2 = SemanticVersion.FromString('0.1.2-alpha2')

    assert ver1 == ver2
    assert not ver1 < ver2
Пример #18
0
    def app(self, name=None, path=None, uuid=None):
        """Find the best IOTileApp for the device we are connected to.

        Apps are matched by looking at the app tag and version information
        specified by the connected device.  If no installed app matches, an
        exception will be thrown.  You can also force the matching of a
        specific app by using the name parameter.

        Args:
            name (str): Optional name of the app that you wish to load.
            path (str): Optional path to a python file containing the
                app that you wish to load.
            uuid (int): Optional uuid of device to directly connect to.
                Passing this parameter is equivalent to calling ``connect``
                before calling this method

        Returns:
            IOTileApp show-as context: The IOTileApp class that was loaded
                for this device.
        """

        if name is not None and path is not None:
            raise ArgumentError(
                "You cannot specify both an app name and an app path",
                name=name,
                path=path)

        if uuid is not None:
            self.connect(uuid)

        # We perform all app matching by asking the device's controller for its app and os info
        tile = self._create_proxy('TileBusProxyObject', 8)
        device_id, os_info, app_info = tile.rpc(0x10,
                                                0x08,
                                                result_format="L8xLL")

        os_tag = os_info & ((1 << 20) - 1)
        os_version_str = '%d.%d.%d' % ((os_info >> 26) & ((1 << 6) - 1),
                                       (os_info >> 20) & ((1 << 6) - 1), 0)

        app_tag = app_info & ((1 << 20) - 1)
        app_version_str = '%d.%d.%d' % ((app_info >> 26) & ((1 << 6) - 1),
                                        (app_info >> 20) & ((1 << 6) - 1), 0)

        os_version = SemanticVersion.FromString(os_version_str)
        app_version = SemanticVersion.FromString(app_version_str)

        app_class = None

        # If name includes a .py, assume that it points to python file and try to load that.
        if name is None and path is not None:
            _name, app_class = ComponentRegistry().load_extension(
                path, class_filter=IOTileApp, unique=True)
        elif name is not None:
            app_class = self._named_apps.get(name)
        else:
            best_match = None
            matching_tags = self._known_apps.get(app_tag, [])

            for (ver_range, quality, app) in matching_tags:
                if ver_range.check(app_version):
                    if best_match is None:
                        best_match = (quality, app)
                    elif quality > best_match[0]:
                        best_match = (quality, app)

            if best_match is not None:
                app_class = best_match[1]

        if app_class is None:
            raise HardwareError(
                "Could not find matching application for device",
                app_tag=app_tag,
                explicit_app=name,
                installed_apps=[x for x in self._named_apps])

        app = app_class(self, (app_tag, app_version), (os_tag, os_version),
                        device_id)
        return app
Пример #19
0
def test_formatting():
    ver = SemanticVersion.FromString('0.1.2-alpha2')
    assert str(ver) == '0.1.2-alpha2'

    ver = SemanticVersion.FromString('1.142.2123')
    assert str(ver) == '1.142.2123'
Пример #20
0
    def app(self, name=None, path=None):
        """Find the best IOTileApp for the device we are connected to.

        Apps are matched by looking at the app tag and version information
        specified by the connected device.  If no installed app matches, an
        exception will be thrown.  You can also force the matching of a
        specific app by using the name parameter.

        Args:
            name (str): Optional name of the app that you wish to load.
            path (str): Optional path to a python file containing the
                app that you wish to load.

        Returns:
            IOTileApp show-as context: The IOTileApp class that was loaded
                for this device.
        """

        if name is not None and path is not None:
            raise ArgumentError(
                "You cannot specify both an app name and an app path",
                name=name,
                path=path)

        # We perform all app matching by asking the device's controller for its app and os info
        tile = self._create_proxy('TileBusProxyObject', 8)
        device_id, os_info, app_info = tile.rpc(0x10,
                                                0x08,
                                                result_format="L8xLL")

        os_tag = os_info & ((1 << 20) - 1)
        os_version_str = '%d.%d.%d' % ((os_info >> 26) & ((1 << 6) - 1),
                                       (os_info >> 20) & ((1 << 6) - 1), 0)

        app_tag = app_info & ((1 << 20) - 1)
        app_version_str = '%d.%d.%d' % ((app_info >> 26) & ((1 << 6) - 1),
                                        (app_info >> 20) & ((1 << 6) - 1), 0)

        os_version = SemanticVersion.FromString(os_version_str)
        app_version = SemanticVersion.FromString(app_version_str)

        app_class = None

        # If name includes a .py, assume that it points to python file and try to load that.
        if name is None and path is not None:
            loaded_classes = self._load_module_classes(path, IOTileApp)
            if len(loaded_classes) > 1:
                raise ArgumentError(
                    "app called with a python file that contained more than one IOTileApp class",
                    classes=loaded_classes)
            elif len(loaded_classes) == 0:
                raise ArgumentError(
                    "app called with a python file that did not contain any IOTileApp subclasses"
                )

            app_class = loaded_classes[0]
        elif name is not None:
            if name in self.DevelopmentAppNames:
                app_class = self.DevelopmentAppNames[name]
            else:
                app_class = self._named_apps.get(name)
        else:
            best_match = None
            matching_tags = self._known_apps.get(app_tag, [])
            dev_tags = self.DevelopmentApps.get(app_tag, [])

            for (ver_range, quality, app) in matching_tags + dev_tags:
                if ver_range.check(app_version):
                    if best_match is None:
                        best_match = (quality, app)
                    elif quality > best_match[0]:
                        best_match = (quality, app)

            if best_match is not None:
                app_class = best_match[1]

        if app_class is None:
            raise HardwareError(
                "Could not find matching application for device",
                app_tag=app_tag,
                explicit_app=name,
                installed_apps=[x for x in self._named_apps])

        app = app_class(self, (app_tag, app_version), (os_tag, os_version),
                        device_id)
        return app
Пример #21
0
def test_coexistence():
    """Test to make sure that version coexistence determination works
    """
    ver = SemanticVersion.FromString('1.1.1')
    ver2 = SemanticVersion.FromString('1.2.3')
    ver3 = SemanticVersion.FromString('2.0.0')
    assert ver.coexistence_class == ver2.coexistence_class
    assert not ver3.coexistence_class == ver2.coexistence_class

    ver = SemanticVersion.FromString('0.1.1')
    ver2 = SemanticVersion.FromString('0.1.2')
    ver3 = SemanticVersion.FromString('0.2.0')
    ver4 = SemanticVersion.FromString('1.1.0')
    assert ver.coexistence_class == ver2.coexistence_class
    assert not ver3.coexistence_class == ver2.coexistence_class
    assert not ver4.coexistence_class == ver2.coexistence_class

    ver = SemanticVersion.FromString('0.0.1')
    ver2 = SemanticVersion.FromString('0.0.1')
    ver3 = SemanticVersion.FromString('0.1.0')
    ver4 = SemanticVersion.FromString('1.1.0')
    assert ver.coexistence_class == ver2.coexistence_class
    assert not ver3.coexistence_class == ver2.coexistence_class
    assert not ver4.coexistence_class == ver2.coexistence_class

    #Make sure prereleases are compat as well
    ver = SemanticVersion.FromString('0.1.0')
    ver2 = SemanticVersion.FromString('0.1.1-alpha2')

    assert ver.coexistence_class == ver2.coexistence_class