Ejemplo n.º 1
0
    def test_repr(self):
        _properties = OrderedDict((("a", 1), ))
        extra_properties = OrderedDict((("b", 2), ))
        _named_children = (("c", 3), )
        extra_named_children = (("d", 4), )

        class TestObject(pystiche.ComplexObject):
            def _properties(self):
                return _properties

            def extra_properties(self):
                return extra_properties

            def _named_children(self):
                return iter(_named_children)

            def extra_named_children(self):
                return iter(extra_named_children)

        test_object = TestObject()
        properties = OrderedDict([
            property for property in itertools.chain(_properties.items(),
                                                     extra_properties.items())
        ])
        named_children = tuple(
            itertools.chain(_named_children, extra_named_children))

        actual = repr(test_object)
        desired = build_complex_obj_repr(name="TestObject",
                                         properties=properties,
                                         named_children=named_children)
        assert actual == desired
Ejemplo n.º 2
0
    def _build_repr(
        self,
        name: Optional[str] = None,
        properties: Optional[Dict[str, str]] = None,
        named_children: Optional[Sequence[Tuple[str, Any]]] = None,
    ) -> str:
        if name is None:
            name = self.__class__.__name__

        if properties is None:
            properties = self.properties()

        if named_children is None:
            named_children = tuple(self.named_children())

        return build_complex_obj_repr(
            name,
            properties=properties,
            named_children=named_children,
            num_indent=self._STR_INDENT,
        )