def test_parse_vowarning(): config = {'verify': 'exception', 'filename': 'foo.xml'} pos = (42, 64) with catch_warnings(exceptions.W47) as w: field = tree.Field(None, name='c', datatype='char', config=config, pos=pos) c = converters.get_converter(field, config=config, pos=pos) parts = exceptions.parse_vowarning(str(w[0].message)) match = { 'number': 47, 'is_exception': False, 'nchar': 64, 'warning': 'W47', 'is_something': True, 'message': 'Missing arraysize indicates length 1', 'doc_url': 'io/votable/api_exceptions.html#w47', 'nline': 42, 'is_warning': True } assert parts == match
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
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
def write_warning(w, line, xml_lines): warning = exceptions.parse_vowarning(line) if not warning['is_something']: w.data(line) else: w.write(f"Line {warning['nline']:d}: ") if warning['warning']: w.write('<a href="{}/{}">{}</a>: '.format( online_docs_root, warning['doc_url'], warning['warning'])) msg = warning['message'] if not isinstance(warning['message'], str): msg = msg.decode('utf-8') w.write(xml_escape(msg)) w.write('\n') if 1 <= warning['nline'] < len(xml_lines): write_source_line(w, xml_lines[warning['nline'] - 1], warning['nchar'])
def write_warning(w, line, xml_lines): warning = exceptions.parse_vowarning(line) if not warning['is_something']: w.data(line) else: w.write('Line {:d}: '.format(warning['nline'])) if warning['warning']: w.write('<a href="{}/{}">{}</a>: '.format( online_docs_root, warning['doc_url'], warning['warning'])) msg = warning['message'] if not isinstance(warning['message'], str): msg = msg.decode('utf-8') w.write(xml_escape(msg)) w.write('\n') if 1 <= warning['nline'] < len(xml_lines): write_source_line(w, xml_lines[warning['nline'] - 1], warning['nchar'])
def test_parse_vowarning(): config = {'pedantic': True, 'filename': 'foo.xml'} pos = (42, 64) with catch_warnings(exceptions.W47) as w: field = tree.Field( None, name='c', datatype='char', config=config, pos=pos) c = converters.get_converter(field, config=config, pos=pos) parts = exceptions.parse_vowarning(str(w[0].message)) match = { 'number': 47, 'is_exception': False, 'nchar': 64, 'warning': 'W47', 'is_something': True, 'message': 'Missing arraysize indicates length 1', 'doc_url': 'io/votable/api_exceptions.html#w47', 'nline': 42, 'is_warning': True } assert parts == match