Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ common \ software.py: 100%

15 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 

6import numpy as np 

7import pandas as pd 

8from pydantic import Field, field_validator 

9 

10from mt_metadata.base import MetadataBase 

11from mt_metadata.common.mttime import MTime 

12 

13 

14# ===================================================== 

15class Software(MetadataBase): 

16 author: Annotated[ 

17 str | None, 

18 Field( 

19 default="", 

20 description="Author of the software", 

21 alias=None, 

22 json_schema_extra={ 

23 "units": None, 

24 "required": True, 

25 "examples": ["Neo"], 

26 }, 

27 ), 

28 ] 

29 

30 version: Annotated[ 

31 str, 

32 Field( 

33 default="", 

34 description="Software version", 

35 alias=None, 

36 json_schema_extra={ 

37 "units": None, 

38 "required": True, 

39 "examples": ["12.01a"], 

40 }, 

41 ), 

42 ] 

43 

44 last_updated: Annotated[ 

45 MTime | str | float | int | np.datetime64 | pd.Timestamp | None, 

46 Field( 

47 default_factory=lambda: MTime(time_stamp=None), 

48 description="Most recent date the software was updated. Prefer to use version, but this works for non-versioned software.", 

49 alias=None, 

50 json_schema_extra={ 

51 "units": None, 

52 "required": False, 

53 "examples": ["2020-01-01"], 

54 }, 

55 ), 

56 ] 

57 

58 name: Annotated[ 

59 str, 

60 Field( 

61 default="", 

62 description="Software name", 

63 alias=None, 

64 json_schema_extra={ 

65 "units": None, 

66 "required": True, 

67 "examples": ["mtrules"], 

68 }, 

69 ), 

70 ] 

71 

72 @field_validator("last_updated", mode="before") 

73 @classmethod 

74 def validate_last_updated( 

75 cls, field_value: MTime | float | int | np.datetime64 | pd.Timestamp | str 

76 ): 

77 return MTime(time_stamp=field_value)