forked from pre-commit/pre-commit-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
57 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import absolute_import | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
import argparse | ||
import io | ||
import sys | ||
import xml.sax | ||
|
||
|
||
def check_xml(argv=None): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('filenames', nargs='*', help='XML filenames to check.') | ||
args = parser.parse_args(argv) | ||
|
||
retval = 0 | ||
for filename in args.filenames: | ||
try: | ||
with io.open(filename, 'rb') as xml_file: | ||
xml.sax.parse(xml_file, xml.sax.ContentHandler()) | ||
except xml.sax.SAXException as exc: | ||
print('{0}: Failed to xml parse ({1})'.format(filename, exc)) | ||
retval = 1 | ||
return retval | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(check_xml()) |
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,5 +1,6 @@ | ||
-e . | ||
|
||
astroid<1.3.3 | ||
coverage | ||
flake8 | ||
mock | ||
|
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<im><not><terminated><lol> |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<document> | ||
<hello>Hi</hello> | ||
<world>Earth</world> | ||
</document> |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import pytest | ||
|
||
from pre_commit_hooks.check_xml import check_xml | ||
from testing.util import get_resource_path | ||
|
||
|
||
@pytest.mark.parametrize(('filename', 'expected_retval'), ( | ||
('bad_xml.notxml', 1), | ||
('ok_xml.xml', 0), | ||
)) | ||
def test_check_xml(filename, expected_retval): | ||
ret = check_xml([get_resource_path(filename)]) | ||
assert ret == expected_retval |
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