Skip to content

Commit

Permalink
Merge pull request #105 from melexis/support_lxml_installation
Browse files Browse the repository at this point in the history
Support lxml
  • Loading branch information
Letme authored Jan 8, 2021
2 parents b0c1e76 + 5059f04 commit 1e997eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ jobs:
- python: '3.8'
env:
- TOXENV=py38,codecov
- python: '3.8'
env:
- TOXENV=lxml_support
# Stage COVERITY
- stage: coverity
python: '3.6'
Expand Down
15 changes: 9 additions & 6 deletions src/mlx/junit_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import sys
import xml.etree.ElementTree as ET
try:
from lxml import etree
except ImportError:
from xml.etree import ElementTree as etree

from junitparser import Error, Failure, JUnitXml

Expand All @@ -20,7 +23,7 @@ def check(self, content):
'''
try:
is_valid_suite_name = False
root_input = ET.fromstring(content.encode('utf-8'))
root_input = etree.fromstring(content.encode('utf-8'))
testsuites_root = self.prepare_tree(root_input)
suites = JUnitXml.fromelem(testsuites_root)
for suite in suites:
Expand All @@ -37,22 +40,22 @@ def check(self, content):
if not is_valid_suite_name and hasattr(self, 'check_suite_name') and self.check_suite_name:
print('ERROR: No suite with name {!r} found. Returning error code -1.'.format(self.name))
sys.exit(-1)
except ET.ParseError as err:
except etree.ParseError as err:
print(err)

@staticmethod
def prepare_tree(root_input):
''' Prepares the tree element by adding a testsuites element as root when missing (to please JUnitXml)
Args:
root_input (lxml.etree._Element): Top-level XML element from input file
root_input (lxml.etree._Element/xml.etree.ElementTree.Element): Top-level XML element from input file
Returns:
lxml.etree._Element: Top-level XML element with testsuites tag
lxml.etree._Element/xml.etree.ElementTree.Element: Top-level XML element with testsuites tag
'''
if root_input.tag == 'testsuites':
testsuites_root = root_input
else:
testsuites_root = ET.Element("testsuites")
testsuites_root = etree.Element("testsuites")
testsuites_root.append(root_input)
return testsuites_root
12 changes: 9 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ basepython =
py37: {env:TOXPYTHON:python3.7}
py38: {env:TOXPYTHON:python3.8}
{py36,docs,spell}: {env:TOXPYTHON:python3.6}
{bootstrap,clean,check,report,coveralls,codecov}: python3
{lxml_support,bootstrap,clean,check,report,coveralls,codecov}: python3
setenv =
PYTHONPATH={toxinidir}/tests
PYTHONUNBUFFERED=yes
passenv =
*
usedevelop = false
deps =
pytest
pytest-travis-fold
pytest-cov
setuptools_scm
coverage
commands =
{posargs:py.test --cov=mlx --cov-report=term-missing -vv tests/}
pytest --cov=mlx --cov-report=term-missing -vv tests/
mlx-warnings -h
mlx-warnings --version
python -c 'import mlx.warnings;print(mlx.warnings.__version__)'
Expand All @@ -36,6 +35,13 @@ commands =
python -m mlx.warnings -j --maxwarnings 3 --minwarnings 3 "tests/test_in/junit*.xml" #emulate for windows (no shell expansion)
python -m mlx.warnings -j --command --maxwarnings 2 --minwarnings 2 cat tests/test_in/junit_double_fail.xml

[testenv:lxml_support]
deps =
pytest
lxml
commands =
pytest -vv tests/

[testenv:bootstrap]
deps =
jinja2
Expand Down

0 comments on commit 1e997eb

Please sign in to comment.