From 79543d3f4864ad3cbff98c2600033c49158d79ac Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Wed, 4 Jan 2017 17:54:15 -0800 Subject: [PATCH] Tests: handle change in an error message in lxml 3.7 --- pcs/lib/commands/test/test_resource_agent.py | 4 ++-- pcs/lib/commands/test/test_stonith_agent.py | 4 ++-- pcs/lib/test/test_resource_agent.py | 5 +++-- pcs/test/tools/assertions.py | 11 +++++++++++ pcs/test/test_lib_cib_tools.py | 4 ++-- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pcs/lib/commands/test/test_resource_agent.py b/pcs/lib/commands/test/test_resource_agent.py index 9652591..ed86d00 100644 --- a/pcs/lib/commands/test/test_resource_agent.py +++ b/pcs/lib/commands/test/test_resource_agent.py @@ -8,7 +8,7 @@ from __future__ import ( import logging from lxml import etree -from pcs.test.tools.assertions import assert_raise_library_error +from pcs.test.tools.assertions import assert_raise_library_error, start_tag_error_text from pcs.test.tools.custom_mock import MockLibraryReportProcessor from pcs.test.tools.pcs_unittest import mock, TestCase @@ -353,7 +353,7 @@ class TestDescribeAgent(TestCase): report_codes.UNABLE_TO_GET_AGENT_METADATA, { "agent": "ocf:test:Dummy", - "reason": "Start tag expected, '<' not found, line 1, column 1", + "reason": start_tag_error_text(), } ) ) diff --git a/pcs/lib/commands/test/test_stonith_agent.py b/pcs/lib/commands/test/test_stonith_agent.py index eaf5f93..d1e3ed0 100644 --- a/pcs/lib/commands/test/test_stonith_agent.py +++ b/pcs/lib/commands/test/test_stonith_agent.py @@ -8,7 +8,7 @@ from __future__ import ( import logging from lxml import etree -from pcs.test.tools.assertions import assert_raise_library_error +from pcs.test.tools.assertions import assert_raise_library_error, start_tag_error_text from pcs.test.tools.custom_mock import MockLibraryReportProcessor from pcs.test.tools.pcs_unittest import mock, TestCase @@ -204,7 +204,7 @@ class TestDescribeAgent(TestCase): report_codes.UNABLE_TO_GET_AGENT_METADATA, { "agent": "fence_dummy", - "reason": "Start tag expected, '<' not found, line 1, column 1", + "reason": start_tag_error_text(), } ) ) diff --git a/pcs/lib/test/test_resource_agent.py b/pcs/lib/test/test_resource_agent.py index 5298415..e45b359 100644 --- a/pcs/lib/test/test_resource_agent.py +++ b/pcs/lib/test/test_resource_agent.py @@ -12,6 +12,7 @@ from pcs.test.tools.assertions import ( ExtendedAssertionsMixin, assert_raise_library_error, assert_xml_equal, + start_tag_error_text, ) from pcs.test.tools.misc import create_patcher from pcs.test.tools.pcs_unittest import TestCase, mock @@ -1069,7 +1070,7 @@ class StonithdMetadataGetMetadataTest(TestCase, ExtendedAssertionsMixin): self.agent._get_metadata, { "agent": "stonithd", - "message": "Start tag expected, '<' not found, line 1, column 1", + "message": start_tag_error_text(), } ) @@ -1196,7 +1197,7 @@ class CrmAgentMetadataGetMetadataTest(TestCase, ExtendedAssertionsMixin): self.agent._get_metadata, { "agent": self.agent_name, - "message": "Start tag expected, '<' not found, line 1, column 1", + "message": start_tag_error_text(), } ) diff --git a/pcs/test/tools/assertions.py b/pcs/test/tools/assertions.py index 4c8f8df..16e2571 100644 --- a/pcs/test/tools/assertions.py +++ b/pcs/test/tools/assertions.py @@ -7,10 +7,21 @@ from __future__ import ( import doctest from lxml.doctestcompare import LXMLOutputChecker +from lxml.etree import LXML_VERSION from pcs.lib.errors import LibraryError from pcs.test.tools.misc import prepare_diff +def start_tag_error_text(): + """lxml 3.7+ gives a longer 'start tag expected' error message, + handle it here so multiple tests can just get the appropriate + string from this function. + """ + msg = "Start tag expected, '<' not found, line 1, column 1" + if LXML_VERSION >= (3, 7, 0, 0): + msg += " (, line 1)" + return msg + def console_report(*lines): #after lines append last new line return "\n".join(lines + ("",)) --- a/pcs/test/test_lib_cib_tools.py +++ b/pcs/test/test_lib_cib_tools.py @@ -13,6 +13,7 @@ from pcs.test.tools.assertions import ( assert_raise_library_error, assert_xml_equal, + start_tag_error_text, ) from pcs.test.tools.misc import get_test_resource as rc from pcs.test.tools.pcs_unittest import mock @@ -488,7 +489,7 @@ report_codes.CIB_UPGRADE_FAILED, { "reason": - "Start tag expected, '<' not found, line 1, column 1", + start_tag_error_text(), } ) ) -- 2.11.0