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
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
def test_no_deployments(ota_cloud, simple_hw): cloud, _proj_id, _server = ota_cloud hw = simple_hw hw.connect(3) ota_updater = OtaUpdater(hw, [123, SemanticVersion(0,0,1)], [234, SemanticVersion(0,0,1)], 3) actual_result = ota_updater.check_cloud_for_script() assert not actual_result
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)
def test_prerelease_parsing(): reltype, relnum = SemanticVersion.ParsePrerelease('alpha1') assert reltype == 'alpha' assert relnum == 1 reltype, relnum = SemanticVersion.ParsePrerelease('beta10') assert reltype == 'beta' assert relnum == 10 reltype, relnum = SemanticVersion.ParsePrerelease('rc20') assert reltype == 'rc' assert relnum == 20 reltype, relnum = SemanticVersion.ParsePrerelease('build30') assert reltype == 'build' assert relnum == 30 with pytest.raises(DataError): SemanticVersion.ParsePrerelease('30') with pytest.raises(DataError): SemanticVersion.ParsePrerelease('build') with pytest.raises(DataError): SemanticVersion.ParsePrerelease('unknown5') with pytest.raises(DataError): SemanticVersion.ParsePrerelease('unknown') with pytest.raises(DataError): SemanticVersion.ParsePrerelease('')
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'
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'
def find_correct_proxy_version(self, proxies, version): """Retrieves the ModuleVersion of each proxy and match it with the tile version something Args: proxies (list): A list of proxies of a specific short name version (obj): A tuple that specifies the tile's version """ proxy_details = {} tile_version = SemanticVersion(version[0], version[1], version[2]) min_version = SemanticVersion(0, 0, 0) best_proxy = None self.logger.debug( "Short name matched proxies found: {0}".format(proxies)) for proxy in proxies: proxy_details[proxy] = {} try: # If proxy has ModuleVersion(), get the SemanticVersionRange module_version = proxy.ModuleVersion() least_version = module_version._disjuncts[0][0][0] except AttributeError: # If proxy does not have ModuleVersion(), use None module_version = None least_version = SemanticVersion(0, 0, 0) if module_version is None: # Regardless if version is compatible, choose a best proxy for now if min_version == SemanticVersion(0, 0, 0): best_proxy = proxy self.logger.debug( "Found a proxy without ModuleVersion info: {0}".format( proxy)) elif module_version.check(tile_version): # Set best proxy since it matches SVR and update min_version to beat if least_version > min_version: min_version = least_version best_proxy = proxy self.logger.debug( "Found a compatible proxy: {0}".format(proxy)) else: self.logger.debug( "Passed compatible proxy: {0}".format(proxy)) self.logger.debug("Best proxy found: {0} with base version {1}".format( best_proxy, min_version)) # If we don't make it in either conditional, best_proxy will return None return best_proxy
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'
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
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
def test_ota_app_creation(ota_cloud, simple_hw): cloud, _proj_id, _server = ota_cloud hw = simple_hw app_tag = 123 app_version = SemanticVersion(0,0,1) os_tag = 234 os_version = SemanticVersion(0,0,1) app_info = [app_tag, app_version] os_info = [os_tag, os_version] device_id = 1 hw.connect(device_id) ota_updater = OtaUpdater(hw, app_info, os_info, device_id) assert ota_updater is not None
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
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
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
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
def test_inform_cloud(ota_cloud, simple_hw): cloud, _proj_id, _server = ota_cloud hw = simple_hw app_tag = 123 app_version = SemanticVersion(0,0,2) os_tag = 234 os_version = SemanticVersion(0,0,2) app_info = [app_tag, app_version] os_info = [os_tag, os_version] device_id = 1 hw.connect(device_id) ota_updater = OtaUpdater(hw, app_info, os_info, device_id) try: ota_updater._inform_cloud(device_id, 'd--0000-0000-0000-0001', True) except: pytest.fail("inform cloud test failed")
def test_apply_update(ota_cloud, simple_hw): cloud, _proj_id, _server = ota_cloud hw = simple_hw app_tag = 123 app_version = SemanticVersion(0,0,2) os_tag = 234 os_version = SemanticVersion(0,0,2) app_info = [app_tag, app_version] os_info = [os_tag, os_version] device_id = 1 hw.connect(device_id) ota_updater = OtaUpdater(hw, app_info, os_info, device_id) blob = b'\x8e\x9a\x1fG\x8e)\x92\xc1\xbaz\x9e\xd3\x9a@\x86\x10L=.\x1f\x1a\x05\x00\x00\x0e\x00\x00\x00\x04\x00\x00\x00\x05 \x08\x08\x00\x00\x0c\x00\x00\x00\x04\x00\x00\x00\x0c \x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\r \x08\x08 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00D\x028\xff\xff\x00\n\n\x01\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x01D\x038\xff\xff\x00\n\n\x01\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x01<\xff\xff\x00\n\n\x01\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x01\x14\x02<\xff\xff\x00\n\n\x01\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x00\x04\x14\x008\xff\xff\x00\n\n\x01\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x08\x00\x00\x00\x01$\x02$\x00\x14\x00\n\x08\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x08\x00\x00\x00\x01$\x03$\x01\x14\x00\n\x08\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x01\x00\x00\x00\x00\x00\x00\x00\x01P\x00D\x00$\x06\x05\n\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x01\x00\x00\x00\x00\x00\x00\x00\x03\x14\x00\x14\x05$\x05\t\n\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00h\x01\x00\x00\x00X\x04\x14\x00D\x00\n\x05\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x00\x00\x00\x00\x01\x00\x00\x00\x05D\x01D\x01$\x00\n\x08\x00\x00\x00 \x00\x00\x00\x04\x00\x00\x00\x03 \x08\x08\x01\x00\x00\x00\x00\x00\x00\x00\x0b\x10\x05D\x06$\x06\x05\n\x00\x00\x00\x1a\x00\x00\x00\x04\x00\x00\x00\x07 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x02\xff\xd7\x00\x01\x02\x00\x1a\x00\x00\x00\x04\x00\x00\x00\x07 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x02\xff_\x80\x01\x02\x00\x1a\x00\x00\x00\x04\x00\x00\x00\x07 \x08\x08\x00\x00\x00\x00\x00\x00\x00\x02\x0b\x10\x01\x00\x02\x00\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x082\x80\x0b\x00\x00$\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x08\x00\x00\x00\x00\x01$\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x08\x01\x00\x00\x00\x02$\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x08\x00\x00\x00\x00\x03$\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x08\x00\x00\x00\x00\x05$\x12\x00\x00\x00\x04\x00\x00\x00\x00 \x08\x082\x80\x0b\x00\x06$\x0c\x00\x00\x00\x04\x00\x00\x00\x0e \x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08\x00 \x00\x00\x00\x00\x00\x00\x00\x02\x10\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x01\x00\x00\x00\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x082\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\n\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08B\x80\x01\x00\x00\x00\x00\x00\x00\x01\x0e\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x90\x01\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08P\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x03\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08Q\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08R\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08S\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08T\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08U\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08V\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08W\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08X\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08Y\x80\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x08\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08\x16\x00\x00\x00\x04\x00\x00\x00\x07*\x08\x08\x01\x90\x01\x00\x00\x00\x00\x00\x00\x01\r\x00\x00\x00\x04\x00\x00\x00\x08*\x08\x08\x00\x0c\x00\x00\x00\x04\x00\x00\x00\t*\x08\x08' try: ota_updater._apply_ota_update(blob=blob) except: pytest.fail("Unexpected error")
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
def test_all_attributes(ota_cloud, simple_hw): cloud, _proj_id, _server = ota_cloud app_tags = [122, 123, 124] app_versions = [SemanticVersion(0, 0, 1), SemanticVersion(0, 0, 2), SemanticVersion(0, 0, 3)] os_tags = [233, 234, 235] os_versions = [SemanticVersion(0, 0, 1), SemanticVersion(0, 0, 2), SemanticVersion(0, 0, 3)] devices = [1, 4, 6] expected_results = [False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, (3, 'bar.com/zipzap'), False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, (3, 'bar.com/zipzap'), False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, (1, 'bar.com/zipzap'), False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, (5, 'bar.com/zipzap'), (7, 'bar.com/zipzap'), (9, 'bar.com/zipzap'), False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, (5, 'bar.com/zipzap'), (7, 'bar.com/zipzap'), (9, 'bar.com/zipzap'), False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False] stage = 0 for app_tag in app_tags: for app_version in app_versions: for os_tag in os_tags: for os_version in os_versions: for device_id in devices: app_info = [app_tag, app_version] os_info = [os_tag, os_version] hw = simple_hw try: hw.disconnect() except: pass hw.connect(device_id) ota_updater = OtaUpdater(hw, app_info, os_info, device_id) actual_result = ota_updater.check_cloud_for_script() if not actual_result: print("os_tag={2}, app_tag={0}, os_version={3}, app_version={1}".format(app_tag, app_version, os_tag, os_version)) if actual_result: print("---------") print("Match achieved for device ID ", device_id) print("os_tag={2}, app_tag={0}, os_version={3}, app_version={1}".format(app_tag, app_version, os_tag, os_version)) print("---------") assert expected_results[stage] == actual_result stage += 1
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'))
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'
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'))
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
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
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
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
def test_equality(): ver1 = SemanticVersion.FromString('0.1.2-alpha2') ver2 = SemanticVersion.FromString('0.1.2-alpha2') assert ver1 == ver2 assert not ver1 < ver2