Skip to content

Commit

Permalink
XMLBear: Support for style specifications
Browse files Browse the repository at this point in the history
A format can be specified in the arguments or in the configuration.
The valid args are c14n, c14n11, exc-c14n and oldxml10.

Closes #1098
  • Loading branch information
namanyadav12 committed Dec 21, 2016
1 parent 47f61cc commit 9fe080e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
19 changes: 15 additions & 4 deletions bears/xml2/XMLBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,32 @@ class XMLBear:
_output_regex = re.compile(
r'.*:(?P<line>\d+):.*(?P<severity>error|warning)\s?: '
r'(?P<message>.*)\n.*\n.*')
_diff_severity = RESULT_SEVERITY.INFO

@staticmethod
def create_arguments(filename, file, config_file,
def create_arguments(self, filename, file, config_file,
xml_schema: path='',
xml_dtd: path_or_url=''):
xml_dtd: path_or_url='',
xml_style: str=''):
"""
:param xml_schema: ``W3C XML Schema`` file used for validation.
:param xml_dtd: ``Document type Definition (DTD)`` file or
url used for validation.
:param xml_style: ``XML Style Specification`` Relevant args are
c14n, c14n11, exc-c14n and oldxml10.
"""
args = (filename,)
if xml_schema:
args += ('-schema', xml_schema)
if xml_dtd:
args += ('-dtdvalid', xml_dtd)
styles = ('c14n', 'c14n11', 'exc-c14n', 'oldxml10')
if xml_style in styles:
args += ('--' + xml_style,)
self._diff_severity = RESULT_SEVERITY.MAJOR
elif xml_style != '':
self.warn('Invalid xml_style argument ' + xml_style +
'. Valid arguments are c14n, c1411,'
' exc-c14n and oldxml10.')

return args

Expand All @@ -68,7 +79,7 @@ def process_output(self, output, filename, file):
output_regex=self._output_regex),
self.process_output_corrected(
stdout, filename, file,
diff_severity=RESULT_SEVERITY.INFO,
diff_severity=self._diff_severity,
result_message='XML can be formatted better.'))
else:
# Return issues from stderr if stdout is empty
Expand Down
14 changes: 14 additions & 0 deletions tests/xml2/XMLBearTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ def load_testdata(filename):
settings={'xml_dtd': dtd_url},
tempfile_kwargs={'suffix': '.xml'})

XMLBearStyleTest = verify_local_bear(
XMLBear,
valid_files=(valid_xml_file,),
invalid_files=(invalid_xml_chars,),
settings={'xml_style': 'oldxml10'},
tempfile_kwargs={'suffix': '.xml'})

XMLBearInvalidStyleTest = verify_local_bear(
XMLBear,
valid_files=(valid_xml_file,),
invalid_files=(invalid_xml_chars,),
settings={'xml_style': 'wrong args'},
tempfile_kwargs={'suffix': '.xml'})


@generate_skip_decorator(XMLBear)
class XMLBearSeverityTest(unittest.TestCase):
Expand Down

0 comments on commit 9fe080e

Please sign in to comment.