Skip to content

Commit

Permalink
Merge pull request #12 from ryan-rs/bug/ASC-412/fix_strict_regex_matc…
Browse files Browse the repository at this point in the history
…h_on_classname

ASC-412 Fix Broken Regex Matcher
  • Loading branch information
zreichert authored Apr 20, 2018
2 parents d87c3d5 + 51552e1 commit 52362f0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.0
current_version = 0.7.1
commit = false
tag = false

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name='rpc-zigzag',
version='0.7.0',
version='0.7.1',
author="rcbops",
author_email='[email protected]',
maintainer='rcbops',
Expand Down
23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,26 @@ def missing_build_url_xml(tmpdir_factory):
f.write(junit_xml)

return filename


@pytest.fixture(scope='session')
def invalid_classname_xml(tmpdir_factory):
"""JUnitXML sample representing a testcase that has an invalid 'classname' attribute which is used to build the
results hierarchy in the '_generate_module_hierarchy' function."""

filename = tmpdir_factory.mktemp('data').join('invalid_classname.xml').strpath
junit_xml = \
"""<?xml version="1.0" encoding="utf-8"?>
<testsuite errors="0" failures="0" name="pytest" skips="0" tests="5" time="1.664">
{global_properties}
<testcase classname="this is not a valid classname" file="tests/test_default.py" line="8"
name="test_pass[ansible://localhost]" time="0.00372695922852">
{testcase_properties}
</testcase>
</testsuite>
""".format(global_properties=DEFAULT_GLOBAL_PROPERTIES, testcase_properties=DEFAULT_TESTCASE_PROPERTIES)

with open(filename, 'w') as f:
f.write(junit_xml)

return filename
10 changes: 10 additions & 0 deletions tests/test_zigzag.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ def test_junit_xml_attachment(self, single_passing_xml):
assert attachment_exp_content_type == test_log_dict['attachments'][0]['content_type']
assert attachment_exp_data_md5 == md5(test_log_dict['attachments'][0]['data'].encode('UTF-8')).hexdigest()

def test_invalid_classname(self, invalid_classname_xml):
"""Verify that JUnitXML that has an invalid 'classname' attribute for a testcase raises a RuntimeError."""

# Setup
junit_xml = zigzag._load_input_file(invalid_classname_xml)

# Test
with pytest.raises(RuntimeError):
zigzag._generate_test_logs(junit_xml)


# noinspection PyUnresolvedReferences
class TestGenerateAutoRequest(object):
Expand Down
2 changes: 1 addition & 1 deletion zigzag/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = """rcbops"""
__email__ = '[email protected]'
__version__ = '0.7.0'
__version__ = '0.7.1'
7 changes: 5 additions & 2 deletions zigzag/zigzag.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ def _generate_module_hierarchy(testcase_xml, testsuite_props):
list(str): An ordered list of strings to use for the qTest results hierarchy.
Raises:
KeyError: missing property.
KeyError: missing test suite property.
AttributeError: the testcase 'classname' attribute is invalid
"""

module_hierarchy = [testsuite_props['RPC_RELEASE'], # RPC Release Version (e.g. 16.0.0)
testsuite_props['JOB_NAME'], # CI Job name (e.g. PM_rpc-openstack-pike-xenial_mnaio_no_artifacts-swift-system) # noqa
testsuite_props['MOLECULE_TEST_REPO'], # (e.g. molecule-validate-neutron-deploy)
testsuite_props['MOLECULE_SCENARIO_NAME']] # (e.g. "default")

testcase_groups = TESTCASE_GROUP_RGX.match(testcase_xml.attrib['classname']).groups()
testcase_groups = TESTCASE_GROUP_RGX.search(testcase_xml.attrib['classname']).groups()

module_hierarchy.append(testcase_groups[0]) # Always append at least the filename of the test grouping.
if testcase_groups[1]:
Expand Down Expand Up @@ -123,6 +124,8 @@ def _generate_test_logs(junit_xml):
test_log.module_names = _generate_module_hierarchy(testcase_xml, testsuite_props)
except KeyError as e:
raise RuntimeError("Test suite is missing the required property!\n\n{}".format(str(e)))
except AttributeError:
raise RuntimeError("Test case '{}' has an invalid 'classname' attribute!".format(test_log.name))

try:
test_log.name = TESTCASE_NAME_RGX.match(testcase_xml.attrib['name']).group(1)
Expand Down

0 comments on commit 52362f0

Please sign in to comment.