def test_version_binding(self): """Test the Rex binding of the Version class.""" v = VersionBinding(Version("1.2.3alpha")) self.assertEqual(v.major, 1) self.assertEqual(v.minor, 2) self.assertEqual(v.patch, "3alpha") self.assertEqual(len(v), 3) self.assertEqual(v[1], 2) self.assertEqual(v[:2], (1, 2)) self.assertEqual(str(v), "1.2.3alpha") self.assertEqual(v[5], None) self.assertEqual(v.as_tuple(), (1, 2, "3alpha"))
def __init__(self, package_name, version_range=None, paths=None, verbose=False): """Create a PackageHelp object. Args: package_name (str): Package to search. version_range (`VersionRange`): Versions to search. """ self.package = None self._verbose = verbose self._sections = [] # find latest package with a help entry package = None it = iter_packages(package_name, range_=version_range) packages = sorted(it, key=lambda x: x.version, reverse=True) for package_ in packages: if self._verbose: print("searching for help in %s..." % package_.uri) if package_.help: package = package_ break if package: help_ = package.help if isinstance(help_, six.string_types): sections = [["Help", help_]] elif isinstance(help_, list): sections = help_ if self._verbose: print("found %d help entries in %s." % (len(sections), package.uri)) # create string formatter for help entries if package.num_variants == 0: base = package.base root = base else: variant = package.get_variant(0) base = variant.base root = variant.root formatter = scoped_formatter( base=base, root=root, config=config, version=VersionBinding(package.version), system=system) # format sections for section in sections: uri = section[1] uri = convert_old_command_expansions(uri) uri = uri.replace("$BROWSER", "").strip() uri = formatter.format(uri) section[1] = uri self.package = package self._sections = sections