Coverage for src/wiktextract/extractor/pt/etymology.py: 78%

29 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2024-12-27 08:07 +0000

1from wikitextprocessor.parser import ( 

2 LEVEL_KIND_FLAGS, 

3 LevelNode, 

4 NodeKind, 

5 WikiNode, 

6) 

7 

8from ...page import clean_node 

9from ...wxr_context import WiktextractContext 

10from .models import WordEntry 

11 

12 

13def extract_etymology_section( 

14 wxr: WiktextractContext, 

15 page_data: list[WordEntry], 

16 level_node: LevelNode, 

17) -> None: 

18 cats = {} 

19 e_nodes = [] 

20 e_texts = [] 

21 for node in level_node.children: 

22 if isinstance(node, WikiNode) and node.kind in LEVEL_KIND_FLAGS: 22 ↛ 23line 22 didn't jump to line 23 because the condition on line 22 was never true

23 break 

24 elif isinstance(node, WikiNode) and node.kind == NodeKind.LIST: 

25 e_text = clean_node(wxr, cats, e_nodes).lstrip(": ") 

26 if e_text != "": 26 ↛ 28line 26 didn't jump to line 28 because the condition on line 26 was always true

27 e_texts.append(e_text) 

28 e_nodes.clear() 

29 for list_item in node.find_child(NodeKind.LIST_ITEM): 

30 e_text = clean_node(wxr, cats, list_item.children) 

31 if e_text != "": 31 ↛ 29line 31 didn't jump to line 29 because the condition on line 31 was always true

32 e_texts.append(e_text) 

33 else: 

34 e_nodes.append(node) 

35 

36 if len(e_nodes) > 0: 36 ↛ 37line 36 didn't jump to line 37 because the condition on line 36 was never true

37 e_text = clean_node(wxr, cats, e_nodes).lstrip(": ") 

38 if e_text != "": 

39 e_texts.append(e_text) 

40 for data in page_data: 

41 if data.lang_code == page_data[-1].lang_code: 41 ↛ 40line 41 didn't jump to line 40 because the condition on line 41 was always true

42 data.etymology_texts.extend(e_texts) 

43 data.categories.extend(cats.get("categories", []))