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

13 statements  

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

1# ===================================================== 

2# Imports 

3# ===================================================== 

4from typing import Annotated 

5 

6from pydantic import Field, field_validator, HttpUrl 

7 

8from mt_metadata.common import Citation as CommonCitation 

9from mt_metadata.transfer_functions.io.emtfxml.metadata import helpers 

10from mt_metadata.utils.validators import validate_doi 

11 

12 

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

14class Citation(CommonCitation): 

15 survey_d_o_i: Annotated[ 

16 HttpUrl | str | None, 

17 Field( 

18 default=None, 

19 description="doi number of the survey", 

20 alias=None, 

21 json_schema_extra={ 

22 "units": None, 

23 "required": False, 

24 "examples": ["###/###"], 

25 }, 

26 ), 

27 ] 

28 

29 @field_validator("survey_d_o_i", mode="before") 

30 @classmethod 

31 def validate_survey_d_o_i( 

32 cls, 

33 value: HttpUrl | str | None, 

34 ) -> HttpUrl | None: 

35 """ 

36 Validate the survey DOI. 

37 

38 Parameters 

39 ---------- 

40 value : str | None 

41 The DOI value to validate. 

42 info : ValidationInfo 

43 Additional validation information. 

44 

45 Returns 

46 ------- 

47 str | None 

48 The validated DOI or None if not provided. 

49 """ 

50 return validate_doi(value) 

51 

52 def to_xml(self, string=False, required=True): 

53 """ 

54 

55 :param string: DESCRIPTION, defaults to False 

56 :type string: TYPE, optional 

57 :param required: DESCRIPTION, defaults to True 

58 :type required: TYPE, optional 

59 :return: DESCRIPTION 

60 :rtype: TYPE 

61 

62 """ 

63 

64 return helpers.to_xml( 

65 self, 

66 string=string, 

67 required=required, 

68 order=[ 

69 "title", 

70 "authors", 

71 "year", 

72 "survey_d_o_i", 

73 ], 

74 )