Coverage for /home/ubuntu/hidebound/python/hidebound/core/specifications.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-05 23:50 +0000

1from typing import Any, Dict, List # noqa F401 

2 

3from schematics.types import IntType, ListType, StringType 

4 

5import hidebound.core.validators as vd 

6import hidebound.core.traits as tr 

7from hidebound.core.specification_base import SequenceSpecificationBase 

8# ------------------------------------------------------------------------------ 

9 

10 

11''' 

12The specifications module house all the specifications for all hidebound projects. 

13 

14All specifications used in production should be subclassed from the base classes 

15found in the specification_base module. All class attributes must have a 

16"get_[attribute]" function in the traits module and should have one or more 

17validators related to the value of that trait (especially if required). 

18''' 

19 

20 

21class Raw001(SequenceSpecificationBase): 

22 ''' 

23 Raw JPEG sequences with 1 or 3 channels. 

24 

25 Attributes: 

26 filename_fields (list[str]): project, specification, descriptor, 

27 version, frame, extension 

28 asset_name_fields (list[str]): project, specification, descriptor, 

29 version, 

30 height (int): Image height. Must be 1024. 

31 width (int): Image width. Must be 1024. 

32 extension (str): File extension. Must be "png". 

33 ''' 

34 asset_name_fields = ['project', 'specification', 'descriptor', 'version'] # type: List[str] 

35 filename_fields = [ 

36 'project', 'specification', 'descriptor', 'version', 'frame', 

37 'extension' 

38 ] # type: List[str] 

39 height = ListType(IntType(), required=True) # type: ListType 

40 width = ListType(IntType(), required=True) # type: ListType 

41 frame = ListType(IntType(), required=True, validators=[vd.is_frame]) # type: ListType 

42 channels = ListType( 

43 IntType(), required=True, validators=[lambda x: vd.is_in(x, [1, 3])] 

44 ) # type: ListType 

45 extension = ListType( 

46 StringType(), 

47 required=True, 

48 validators=[vd.is_extension, lambda x: vd.is_eq(x, 'jpg')] 

49 ) # type: ListType 

50 file_traits = dict( 

51 width=tr.get_image_width, 

52 height=tr.get_image_height, 

53 channels=tr.get_num_image_channels, 

54 ) # type: Dict[str, Any] 

55 

56 

57class Raw002(SequenceSpecificationBase): 

58 ''' 

59 Raw JPEG sequences with 1 or 3 channels and coordinates. 

60 

61 Attributes: 

62 filename_fields (list[str]): project, specification, descriptor, 

63 version, frame, extension 

64 asset_name_fields (list[str]): project, specification, descriptor, 

65 version, 

66 height (int): Image height. Must be 1024. 

67 width (int): Image width. Must be 1024. 

68 extension (str): File extension. Must be "png". 

69 ''' 

70 asset_name_fields = ['project', 'specification', 'descriptor', 'version'] # type: List[str] 

71 filename_fields = [ 

72 'project', 'specification', 'descriptor', 'version', 'coordinate', 

73 'frame', 'extension' 

74 ] # type: List[str] 

75 height = ListType(IntType(), required=True) # type: ListType 

76 width = ListType(IntType(), required=True) # type: ListType 

77 frame = ListType(IntType(), required=True, validators=[vd.is_frame]) # type: ListType 

78 coordinate = ListType( 

79 ListType(IntType(), validators=[vd.is_coordinate]), required=True, 

80 ) # type: ListType 

81 channels = ListType( 

82 IntType(), required=True, validators=[lambda x: vd.is_in(x, [1, 3])] 

83 ) # type: ListType 

84 extension = ListType( 

85 StringType(), 

86 required=True, 

87 validators=[vd.is_extension, lambda x: vd.is_eq(x, 'jpg')] 

88 ) # type: ListType 

89 file_traits = dict( 

90 width=tr.get_image_width, 

91 height=tr.get_image_height, 

92 channels=tr.get_num_image_channels, 

93 ) # type: Dict[str, Any] 

94 

95 

96SPECIFICATIONS = [ 

97 Raw001, 

98 Raw002, 

99] # type: List[type]