Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log the actual exception that caused a ParseError, reduce code duplic…
…ation parsing XMl files
- Loading branch information
Showing
23 changed files
with
108 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
import os | ||
import pathlib | ||
from typing import Iterable, Callable | ||
|
||
from lxml import etree | ||
|
||
from publish.junit import JUnitTreeOrException, ParsedJUnitFile | ||
from publish.junit import JUnitTree, ParsedJUnitFile, progress_safe_parse_xml_file | ||
|
||
with (pathlib.Path(__file__).parent / 'xslt' / 'nunit3-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
with (pathlib.Path(__file__).resolve().parent / 'xslt' / 'nunit3-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
transform_nunit_to_junit = etree.XSLT(etree.parse(r)) | ||
|
||
|
||
def parse_nunit_files(files: Iterable[str], | ||
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]: | ||
"""Parses nunit files.""" | ||
def parse(path: str) -> JUnitTreeOrException: | ||
"""Parses an nunit file and returns either a JUnitTree or an Exception.""" | ||
if not os.path.exists(path): | ||
return FileNotFoundError(f'File does not exist.') | ||
if os.stat(path).st_size == 0: | ||
return Exception(f'File is empty.') | ||
def parse(path: str) -> JUnitTree: | ||
nunit = etree.parse(path) | ||
return transform_nunit_to_junit(nunit) | ||
|
||
try: | ||
nunit = etree.parse(path) | ||
return transform_nunit_to_junit(nunit) | ||
except BaseException as e: | ||
return e | ||
|
||
return [progress((result_file, parse(result_file))) for result_file in files] | ||
return progress_safe_parse_xml_file(files, parse, progress) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
import os | ||
import pathlib | ||
from typing import Iterable, Callable | ||
|
||
from lxml import etree | ||
|
||
from publish.junit import JUnitTreeOrException, ParsedJUnitFile | ||
from publish.junit import JUnitTree, ParsedJUnitFile, progress_safe_parse_xml_file | ||
|
||
with (pathlib.Path(__file__).parent / 'xslt' / 'trx-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
with (pathlib.Path(__file__).resolve().parent / 'xslt' / 'trx-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
transform_trx_to_junit = etree.XSLT(etree.parse(r)) | ||
|
||
|
||
def parse_trx_files(files: Iterable[str], | ||
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]: | ||
"""Parses trx files.""" | ||
def parse(path: str) -> JUnitTreeOrException: | ||
"""Parses a trx file and returns either a JUnitTree or an Exception.""" | ||
if not os.path.exists(path): | ||
return FileNotFoundError(f'File does not exist.') | ||
if os.stat(path).st_size == 0: | ||
return Exception(f'File is empty.') | ||
def parse(path: str) -> JUnitTree: | ||
trx = etree.parse(path) | ||
return transform_trx_to_junit(trx) | ||
|
||
try: | ||
trx = etree.parse(path) | ||
return transform_trx_to_junit(trx) | ||
except BaseException as e: | ||
return e | ||
|
||
return [progress((result_file, parse(result_file))) for result_file in files] | ||
return progress_safe_parse_xml_file(files, parse, progress) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
import os | ||
import pathlib | ||
from typing import Iterable, Callable | ||
|
||
from lxml import etree | ||
|
||
from publish.junit import JUnitTreeOrException, ParsedJUnitFile | ||
from publish.junit import JUnitTree, ParsedJUnitFile, progress_safe_parse_xml_file | ||
|
||
with (pathlib.Path(__file__).parent / 'xslt' / 'xunit-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
with (pathlib.Path(__file__).resolve().parent / 'xslt' / 'xunit-to-junit.xslt').open('r', encoding='utf-8') as r: | ||
transform_xunit_to_junit = etree.XSLT(etree.parse(r)) | ||
|
||
|
||
def parse_xunit_files(files: Iterable[str], | ||
progress: Callable[[ParsedJUnitFile], ParsedJUnitFile] = lambda x: x) -> Iterable[ParsedJUnitFile]: | ||
"""Parses xunit files.""" | ||
def parse(path: str) -> JUnitTreeOrException: | ||
"""Parses an xunit file and returns either a JUnitTree or an Exception.""" | ||
if not os.path.exists(path): | ||
return FileNotFoundError(f'File does not exist.') | ||
if os.stat(path).st_size == 0: | ||
return Exception(f'File is empty.') | ||
def parse(path: str) -> JUnitTree: | ||
xunit = etree.parse(path) | ||
return transform_xunit_to_junit(xunit) | ||
|
||
try: | ||
xunit = etree.parse(path) | ||
return transform_xunit_to_junit(xunit) | ||
except BaseException as e: | ||
return e | ||
|
||
return [progress((result_file, parse(result_file))) for result_file in files] | ||
return progress_safe_parse_xml_file(files, parse, progress) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Exception: 'File is empty.' | ||
ParseError: file='files/junit-xml/empty.xml', message='File is empty.', line=None, column=None, exception=Exception('File is empty.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
XMLSyntaxError: "Start tag expected, '<' not found, line 1, column 1" | ||
ParseError: file='files/junit-xml/non-xml.xml', message="Start tag expected, '<' not found, line 1, column 1 (non-xml.xml, line 1)", line=None, column=None, exception=XMLSyntaxError("Start tag expected, '<' not found, line 1, column 1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
XMLSyntaxError: 'Premature end of data in tag skipped line 9, line 11, column 22' | ||
ParseError: file='files/junit-xml/pytest/corrupt-xml.xml', message='Premature end of data in tag skipped line 9, line 11, column 22 (corrupt-xml.xml, line 11)', line=None, column=None, exception=XMLSyntaxError('Premature end of data in tag skipped line 9, line 11, column 22') |
2 changes: 1 addition & 1 deletion
2
python/test/files/nunit/nunit3/jenkins/NUnit-issue17521.exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
XMLSyntaxError: 'Char 0x0 out of allowed range, line 33, column 16' | ||
ParseError: file='files/nunit/nunit3/jenkins/NUnit-issue17521.xml', message='Char 0x0 out of allowed range, line 33, column 16 (NUnit-issue17521.xml, line 33)', line=None, column=None, exception=XMLSyntaxError('Char 0x0 out of allowed range, line 33, column 16') |
2 changes: 1 addition & 1 deletion
2
python/test/files/nunit/nunit3/jenkins/NUnit-issue47367.exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
XMLSyntaxError: 'attributes construct error, line 5, column 109' | ||
ParseError: file='files/nunit/nunit3/jenkins/NUnit-issue47367.xml', message='attributes construct error, line 5, column 109 (NUnit-issue47367.xml, line 5)', line=None, column=None, exception=XMLSyntaxError('attributes construct error, line 5, column 109') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.