Esempio n. 1
0
    def validate_vo(self):
        path = self.get_vo_xml_path()
        if not os.path.exists(path):
            self.download_xml_content()
        self['version'] = ''
        if 'network_error' in self and self['network_error'] is not None:
            self['nwarnings'] = 0
            self['nexceptions'] = 0
            self['warnings'] = []
            self['xmllint'] = None
            self['warning_types'] = set()
            return

        nexceptions = 0
        nwarnings = 0
        t = None
        lines = []
        with open(path, 'rb') as input:
            with warnings.catch_warnings(record=True) as warning_lines:
                try:
                    t = table.parse(input, verify='warn', filename=path)
                except (ValueError, TypeError, ExpatError) as e:
                    lines.append(str(e))
                    nexceptions += 1
        lines = [str(x.message) for x in warning_lines] + lines

        if t is not None:
            self['version'] = version = t.version
        else:
            self['version'] = version = "1.0"

        if 'xmllint' not in self:
            # Now check the VO schema based on the version in
            # the file.
            try:
                success, stdout, stderr = xmlutil.validate_schema(
                    path, version)
            # OSError is raised when XML file eats all memory and
            # system sends kill signal.
            except OSError as e:
                self['xmllint'] = None
                self['xmllint_content'] = str(e)
            else:
                self['xmllint'] = (success == 0)
                self['xmllint_content'] = stderr

        warning_types = set()
        for line in lines:
            w = exceptions.parse_vowarning(line)
            if w['is_warning']:
                nwarnings += 1
            if w['is_exception']:
                nexceptions += 1
            warning_types.add(w['warning'])

        self['nwarnings'] = nwarnings
        self['nexceptions'] = nexceptions
        self['warnings'] = lines
        self['warning_types'] = warning_types
Esempio n. 2
0
    def validate_vo(self):
        path = self.get_vo_xml_path()
        if not os.path.exists(path):
            self.download_xml_content()
        self['version'] = ''
        if 'network_error' in self and self['network_error'] is not None:
            self['nwarnings'] = 0
            self['nexceptions'] = 0
            self['warnings'] = []
            self['xmllint'] = None
            self['warning_types'] = set()
            return

        nexceptions = 0
        nwarnings = 0
        t = None
        lines = []
        with open(path, 'rb') as input:
            with warnings.catch_warnings(record=True) as warning_lines:
                try:
                    t = table.parse(input, pedantic=False, filename=path)
                except (ValueError, TypeError, ExpatError) as e:
                    lines.append(str(e))
                    nexceptions += 1
        lines = [str(x.message) for x in warning_lines] + lines

        if t is not None:
            self['version'] = version = t.version
        else:
            self['version'] = version = "1.0"

        if 'xmllint' not in self:
            # Now check the VO schema based on the version in
            # the file.
            try:
                success, stdout, stderr = xmlutil.validate_schema(path, version)
            # OSError is raised when XML file eats all memory and
            # system sends kill signal.
            except OSError as e:
                self['xmllint'] = None
                self['xmllint_content'] = str(e)
            else:
                self['xmllint'] = (success == 0)
                self['xmllint_content'] = stderr

        warning_types = set()
        for line in lines:
            w = exceptions.parse_vowarning(line)
            if w['is_warning']:
                nwarnings += 1
            if w['is_exception']:
                nexceptions += 1
            warning_types.add(w['warning'])

        self['nwarnings'] = nwarnings
        self['nexceptions'] = nexceptions
        self['warnings'] = lines
        self['warning_types'] = warning_types
Esempio n. 3
0
def assert_validate_schema(filename, version):
    if sys.platform.startswith('win'):
        return

    try:
        rc, stdout, stderr = validate_schema(filename, version)
    except OSError:
        # If xmllint is not installed, we want the test to pass anyway
        return
    assert rc == 0, 'File did not validate against VOTable schema'
Esempio n. 4
0
def assert_validate_schema(filename, version):
    if sys.platform.startswith('win'):
        return

    try:
        rc, stdout, stderr = validate_schema(filename, version)
    except OSError:
        # If xmllint is not installed, we want the test to pass anyway
        return
    assert rc == 0, 'File did not validate against VOTable schema'