Пример #1
0
    def test3serialize_object(self):
        """This test case checks if all child objects are serialized correctly."""
        a3 = MatchElement('a3', b'a3', b'a3', [])
        a2 = MatchElement('a2', b'a2', b'a2', [a3])
        a1 = MatchElement('a1', b'a1', b'a1', [a2])
        b3 = MatchElement('b3', b'b3', b'b3', [])
        b2 = MatchElement('b2', b'b2', b'b2', [b3])
        b1 = MatchElement('b1', b'b1', b'b1', [b2])

        root_element = MatchElement('root', b'root', b'root', [a1, b1])

        self.assertEqual(root_element.serialize_object(), {'path': 'root', 'matchobject': b'root', 'matchString': b'root', 'children': [
            {'path': 'a1', 'matchobject': b'a1', 'matchString': b'a1', 'children': [
                {'path': 'a2', 'matchobject': b'a2', 'matchString': b'a2',
                    'children': [{'path': 'a3', 'matchobject': b'a3', 'matchString': b'a3', 'children': []}]}]},
            {'path': 'b1', 'matchobject': b'b1', 'matchString': b'b1', 'children': [
                {'path': 'b2', 'matchobject': b'b2', 'matchString': b'b2',
                    'children': [{'path': 'b3', 'matchobject': b'b3', 'matchString': b'b3', 'children': []}]}]}]})
Пример #2
0
    def test6serialize_object(self):
        """This test case checks if all child objects are serialized correctly."""
        a3 = MatchElement("a3", b"a3", b"a3", None)
        a2 = MatchElement("a2", b"a2", b"a2", [a3])
        a1 = MatchElement("a1", b"a1", b"a1", [a2])
        b3 = MatchElement("b3", b"b3", b"b3", None)
        b2 = MatchElement("b2", b"b2", b"b2", [b3])
        b1 = MatchElement("b1", b"b1", b"b1", [b2])
        root_element = MatchElement("root", b"root", b"root", [a1, b1])

        self.assertEqual(
            root_element.serialize_object(), {
                "path":
                "root",
                "match_object":
                b"root",
                "match_string":
                b"root",
                "children": [{
                    "path":
                    "a1",
                    "match_object":
                    b"a1",
                    "match_string":
                    b"a1",
                    "children": [{
                        "path":
                        "a2",
                        "match_object":
                        b"a2",
                        "match_string":
                        b"a2",
                        "children": [{
                            "path": "a3",
                            "match_object": b"a3",
                            "match_string": b"a3",
                            "children": []
                        }]
                    }]
                }, {
                    "path":
                    "b1",
                    "match_object":
                    b"b1",
                    "match_string":
                    b"b1",
                    "children": [{
                        "path":
                        "b2",
                        "match_object":
                        b"b2",
                        "match_string":
                        b"b2",
                        "children": [{
                            "path": "b3",
                            "match_object": b"b3",
                            "match_string": b"b3",
                            "children": []
                        }]
                    }]
                }]
            })