コード例 #1
0
    def test_xml_to_tupletree_sax(self, encoding, desc, xml_string,
                                  exp_tupletree, exp_exc_type,
                                  exp_exc_msg_pattern, condition):
        # pylint: disable=no-self-use
        """
        Test xml_to_tupletree_sax() against expected results and against
        DOM parser results.
        """

        if not condition:
            pytest.skip("Condition for test case not met")

        assert isinstance(xml_string, six.text_type)
        if encoding == 'bytes':
            xml_string = xml_string.encode("utf-8")
        else:
            assert encoding == 'unicode'

        if exp_exc_type is None:

            act_tupletree = tupletree.xml_to_tupletree_sax(
                xml_string, 'Test XML')

            # Compare against expected result
            assert act_tupletree == exp_tupletree

            if encoding == 'bytes':
                # Compare against result from previously used DOM parser
                dom_tupletree = xml_to_tupletree(xml_string)
                assert act_tupletree == dom_tupletree

        else:
            with pytest.raises(exp_exc_type) as exec_info:

                tupletree.xml_to_tupletree_sax(xml_string, 'Test XML')

            if exp_exc_msg_pattern:
                exc = exec_info.value
                exc_msg = str(exc)
                one_line_exc_msg = exc_msg.replace('\n', '\\n')
                assert re.search(exp_exc_msg_pattern, one_line_exc_msg), \
                    "Unexpected exception message:\n" + exc_msg
コード例 #2
0
    def _run_single(self, xml, obj):
        """
        Parse the xml parameter to an object and compare it with the obj
        parameter
        """
        # Parse raw XML to an object

        result = tupleparse.parse_any(tupletree.xml_to_tupletree_sax(xml))

        # Assert XML parses to particular Python object

        self.assertEqual(obj, result, 'parsed XML: %s' % result)
コード例 #3
0
ファイル: test_tupleparse.py プロジェクト: pywbem/pywbem
    def _run_single(self, xml, obj):
        """
        Parse the xml parameter to an object and compare it with the obj
        parameter
        """
        # Parse raw XML to an object

        result = tupleparse.parse_any(tupletree.xml_to_tupletree_sax(xml))

        # Assert XML parses to particular Python object

        self.assertEqual(obj, result,
                         'parsed XML: %s' % result)
コード例 #4
0
    def test_xml_to_tupletree_sax(self):
        """
        XML to tupletree with SAX is accurate.

        This test compares data to the test_tuple variable in this file.
        """
        data_dir = resource_filename(__name__, 'tupletree_ok')
        path = os.path.join(data_dir, 'Associators_StorageVolume_small.xml')
        with open(path, 'rb') as fh:
            xml_str = fh.read()
        tree_sax = tupletree.xml_to_tupletree_sax(xml_str, 'Test XML')
        self.assertEqual(test_tuple, tree_sax,
                         'Test tuple and SAX not equal for %s:\n%s,\n%s'
                         % (path, pp.pformat(tree_sax), pp.pformat(tree_sax)))
コード例 #5
0
    def test_to_tupletree(self):
        """
        SAX parsing replicates DOM parsing to the tupletree.

        This test compares the input xml compiled with the dom and sax.

        """
        for fn in self.filenames:
            with open(fn, 'rb') as fh:
                xml_str = fh.read()
            tree_dom = xml_to_tupletree(xml_str)
            tree_sax = tupletree.xml_to_tupletree_sax(xml_str, 'Test XML')
            self.assertEqual(tree_dom, tree_sax,
                             'SAX and DOM not equal for %s:\n%s,\n%s'
                             % (fn, pp.pformat(tree_sax), pp.pformat(tree_dom)))
コード例 #6
0
ファイル: test_tupletree.py プロジェクト: pywbem/pywbem
    def test_xml_to_tupletree_sax(self):
        """
        XML to tupletree with SAX is accurate.

        This test compares data to the test_tuple variable in this file.
        """
        data_dir = resource_filename(__name__, "tupletree_ok")
        path = os.path.join(data_dir, "Associators_StorageVolume_small.xml")
        with open(path, "rb") as fh:
            xml_str = fh.read()
        tree_sax = tupletree.xml_to_tupletree_sax(xml_str)
        self.assertEqual(
            test_tuple,
            tree_sax,
            "Test tuple and SAX not equal for %s:\n%s,\n%s" % (path, pp.pformat(tree_sax), pp.pformat(tree_sax)),
        )
コード例 #7
0
ファイル: test_tupletree.py プロジェクト: pywbem/pywbem
    def test_to_tupletree(self):
        """
        SAX parsing replicates DOM parsing to the tupletree.

        This test compares the input xml compiled with the dom and sax.

        """
        for fn in self.filenames:
            with open(fn, "rb") as fh:
                xml_str = fh.read()
            tree_dom = xml_to_tupletree(xml_str)
            tree_sax = tupletree.xml_to_tupletree_sax(xml_str)
            self.assertEqual(
                tree_dom,
                tree_sax,
                "SAX and DOM not equal for %s:\n%s,\n%s" % (fn, pp.pformat(tree_sax), pp.pformat(tree_dom)),
            )
コード例 #8
0
ファイル: test_tupleparse.py プロジェクト: saminigod/pywbem
    def _run_single(self, obj):
        """
        Execute the test on a single object.  This test converts the object to
        xml and then parses it.  The result must be the same as the original
        object.
        """
        # Convert object to xml

        xml = obj.tocimxml().toxml()

        # Parse back to an object

        result = tupleparse.parse_any(tupletree.xml_to_tupletree_sax(xml))

        # Assert that the before and after objects should be equal

        self.assertEqual(obj, result,
                         '\nbefore: %s\nafter:  %s' %
                         (xml, result.tocimxml().toxml()))
コード例 #9
0
def execute_test_code(xml_string, profiler):
    """
    The test code to be executed. If a profiler is defined it is enabled
    just before the test code is executed and disabled just after the
    code is executed.
    """
    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.enable()
        elif isinstance(profiler, Profiler):
            profiler.start()

    # The code to be tested
    tt_ = tupletree.xml_to_tupletree_sax(xml_string, "TestData")
    # call method dependent on pywbem version
    test_tuple_parse(tt_)

    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.disable()
        elif isinstance(profiler, Profiler):
            profiler.stop()
コード例 #10
0
def execute_test_code(xml_string, profiler):
    """
    The test code to be executed. If a profiler is defined it is enabled
    just before the test code is executed and disabled just after the
    code is executed.
    """
    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.enable()
        elif isinstance(profiler, Profiler):
            profiler.start()

    # The code to be tested
    tt = tupletree.xml_to_tupletree_sax(xml_string, "TestData")

    parse_cim(tt)

    if profiler:
        if isinstance(profiler, cProfile.Profile):
            profiler.disable()
        elif isinstance(profiler, Profiler):
            profiler.stop()