Example #1
0
    def version(self, value):
        if isinstance(value, Version):
            version = value.dup()

        elif isinstance(value, basestring):
            try:
                version = Version.load_from_string(value)

            except Exception:
                raise ValueError("Invalid version string %r" % value)

        else:
            raise ValueError("Version can only be a string or another Version object")

        self._version = version
Example #2
0
    def parse_config_xml(self, xml_root):
        # Update the XML tree if needed (this needs pre-verifying the version)
        if 'version' not in xml_root.attrib:
            raise ParseError("Configuration version cannot be determined", 1)

        try:
            version = Version.load_from_string(xml_root.attrib['version'])

        except ValueError:
            raise ParseError("Invalid version format %s" % xml_root.attrib['version'], 1)

        xml_root = UpdateVisitor().visit(version, xml_root)

        # Validate the XML root with the config.xsd. The config.xsd file always
        # refers to the current version (see UpdateVisitor.version_current)
        try:
            validate_xml(xml_root, resource='config.xsd', resource_locator=ModuleLocator(__import__(__name__)))

        except etree.DocumentInvalid, e:
            raise ParseError('Configuration is invalid', e.error_log.last_error.line)
Example #3
0
 def test_initialize(self):
     self.assertEqual(Version('1', '0')._components, [1, 0])
     self.assertEqual(Version.load_from_string('1')._components, [1])
     self.assertEqual(Version.load_from_string('1.')._components, [1, 0])
     self.assertEqual(Version.load_from_string('1.0')._components, [1, 0])
     self.assertEqual(Version.load_from_string('1..0')._components, [1, 0, 0])
Example #4
0
 def test_compare(self):
     self.assertTrue(Version.load_from_string('1.0') == Version.load_from_string('1'))
     self.assertTrue(Version.load_from_string('1.0') < Version.load_from_string('1.1'))
     self.assertTrue(Version.load_from_string('1.0') <= Version.load_from_string('1.1'))
     self.assertTrue(Version.load_from_string('1.1.2') > Version.load_from_string('1.1'))