Coverage for phml\nodes\root.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-12-08 16:33 -0600

1from __future__ import annotations 

2 

3from typing import Optional 

4 

5from .parent import Parent 

6from .position import Position 

7 

8 

9class Root(Parent): 

10 """Root (Parent) represents a document. 

11 

12 Root can be used as the root of a tree, or as a value 

13 of the content field on a 'template' Element, never as a child. 

14 """ 

15 

16 def __init__( 

17 self, 

18 position: Optional[Position] = None, 

19 children: Optional[list] = None, 

20 ): 

21 super().__init__(position, children) 

22 self.parent = None 

23 

24 def __eq__(self, obj) -> bool: 

25 return bool( 

26 obj is not None 

27 and isinstance(obj, Root) 

28 and len(self.children) == len(obj.children) 

29 and all(child == obj_child for child, obj_child in zip(self.children, obj.children)) 

30 ) 

31 

32 def __repr__(self) -> str: 

33 return f"root [{len(self.children)}]"