Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ transfer_functions \ io \ emtfxml \ metadata \ field_notes.py: 100%

27 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-10 00:11 -0800

1# -*- coding: utf-8 -*- 

2""" 

3Created on Thu Mar 9 12:25:44 2023 

4 

5@author: jpeacock 

6""" 

7from xml.etree import ElementTree as et 

8 

9from loguru import logger 

10 

11# ============================================================================= 

12# Imports 

13# ============================================================================= 

14from mt_metadata.base import MetadataBase 

15 

16from . import Run 

17 

18 

19# ============================================================================= 

20class FieldNotes(MetadataBase): 

21 _run_list: list[Run] = [] 

22 

23 def __str__(self): 

24 lines = [] 

25 for r in self._run_list: 

26 lines.append(r.__str__()) 

27 return "\n".join(lines) 

28 

29 def __repr__(self): 

30 return self.__str__() 

31 

32 def read_dict(self, input_dict): 

33 self._run_list = [] 

34 try: 

35 if not isinstance(input_dict["field_notes"], list): 

36 run_list = [input_dict["field_notes"]] 

37 else: 

38 run_list = input_dict["field_notes"] 

39 

40 for run in run_list: 

41 r = Run() 

42 r.read_dict(run) 

43 

44 self._run_list.append(r) 

45 except KeyError: 

46 logger.warning("Did not find any field notes in xml") 

47 

48 def to_xml( 

49 self, string: bool = False, required: bool = True 

50 ) -> list[str | et.Element]: 

51 """ 

52 Convert the FieldNotes instance to XML format. 

53 

54 Parameters 

55 ---------- 

56 string : bool, optional 

57 If True, return XML as a string, by default False 

58 required : bool, optional 

59 If True, include all required fields, by default True 

60 

61 Returns 

62 ------- 

63 list[str | et.Element] 

64 The XML representation of the FieldNotes instance 

65 """ 

66 

67 return [r.to_xml(string=string, required=required) for r in self._run_list]