Commit c4a9089a authored by di68kap's avatar di68kap
Browse files

- neue prefx und postfix methoden

parent 1dde23fc
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -426,6 +426,22 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
            self._xml_attr = OrderedDict()
        return self._xml_attr

    def get_attr(self, attribute: str, default: str) -> str:
        """
        Returns the value of 'attribute' if attribute exists. If not, the
        default value is returned. This function has the same semantics
        as `node.attr.get(attribute, default)`, but with the advantage then
        other than `node.attr.get` it does not automatically create an
        attribute dictionary on (first) access.
        :param attribute: The attribute, the value of which shall be looked up
        :param default:   A default value that is returned, in case attribute
                          does not exist.
        :return: str
        """
        if self.has_attr():
            return self.attr.get(attribute, default)
        return default

    def compare_attr(self, other: 'Node') -> bool:
        """
        Returns True, if `self` and `other` have the same attributes with the
+3 −2
Original line number Diff line number Diff line
@@ -273,8 +273,8 @@ class TestRootNode:
            str(result)


class TestNodeFind():
    """Test the select_if-functions of class Node.
class TestNodeFind:
    """Test the item-access-functions of class Node.
    """

    def test_find(self):
@@ -297,6 +297,7 @@ class TestNodeFind():
        tree = parse_sxpr('(a (b X) (X (c d)) (e (X F)))')
        assert tree[0].equals(parse_sxpr('(b X)'))
        assert tree[2].equals(parse_sxpr('(e (X F))'))
        assert tree[-1].equals(parse_sxpr('(e (X F))'))
        try:
            node = tree[3]
            assert False, "IndexError expected!"