Coverage for skema/gromet/execution_engine/types/other.py: 93%

85 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-30 17:15 +0000

1from typing import Any 

2 

3from skema.gromet.execution_engine.types.defined_types import Field 

4 

5 

6class CASTGenericIter: 

7 source_language_name = {"CAST": "iter"} 

8 inputs = [Field("iterable_input", "Iterable")] 

9 outputs = [Field("iterator_output", "Iterator")] 

10 shorthand = "iter" 

11 documentation = "The cast currently uses generic primitive operators (_get, _set, iter, next) while the Gromet uses specific operators (IteratorMap_next). These primitive ops are a tempory fix for that mismatch" 

12 

13 

14class CASTGenericNext: 

15 source_language_name = {"CAST": "next"} 

16 inputs = [Field("iterator_input", "Iterator")] 

17 outputs = [ 

18 Field("element", "Any"), 

19 Field("iterator_output", "Iterator"), 

20 Field("stop_condition", "Boolean"), 

21 ] 

22 shorthand = "next" 

23 documentation = "The cast currently uses generic primitive operators (_get, _set, iter, next) while the Gromet uses specific operators (IteratorMap_next). These primitive ops are a tempory fix for that mismatch" 

24 

25 

26class Is(object): 

27 source_language_name = { 

28 "Python": "is", 

29 "CAST": "Is", 

30 } # TODO: Should Python/CAST be Is or is? 

31 inputs = [Field("operand1", "Any"), Field("operand2", "Any")] 

32 outputs = [Field("result", "Boolean")] 

33 shorthand = "is" 

34 documentation = "" 

35 

36 def exec(operand1: Any, operand2: Any) -> bool: 

37 return operand1 is operand2 

38 

39 

40class NotIs(object): 

41 source_language_name = { 

42 "Python": "is not", 

43 "CAST": "NotIs", 

44 } # TODO: What should Python name be here? 

45 inputs = [Field("operand1", "Any"), Field("operand2", "Any")] 

46 outputs = [Field("result", "Boolean")] 

47 shorthand = "not is" 

48 documentation = "" 

49 

50 def exec(operand1: Any, operand2: Any) -> bool: 

51 return operand1 is not operand2 

52 

53 

54class IsInstance(object): 

55 source_language_name = {"Python": "isinstance"} 

56 inputs = [ 

57 Field("operand", "Any"), 

58 Field("type_name", "String"), 

59 ] # TODO: Get confirmation on adding Type field 

60 outputs = [Field("result", "Boolean")] 

61 shorthand = "type" 

62 documentation = "" 

63 

64 def exec( 

65 operand: Any, type_name: str 

66 ) -> bool: # TODO: Fix name of right argument 

67 return isinstance(operand, type) 

68 

69 

70class Type(object): 

71 source_language_name = {"Python": "type"} 

72 inputs = [Field("operand", "Any")] 

73 outputs = [Field("result", "String")] 

74 shorthand = "type" 

75 documentation = "" 

76 

77 def exec(operand: Any) -> str: 

78 return str(type(operand)) 

79 

80 

81class Cast(object): 

82 source_language_name = {"CAST": "cast"} 

83 inputs = [Field("operand", "Any")] 

84 outputs = [Field("type_name", "String")] 

85 shorthand = "cast" 

86 documentation = "" 

87 

88 

89class Slice(object): 

90 source_language_name = {"CAST": "slice"} 

91 inputs = [ 

92 Field("lower", "Integer"), 

93 Field("upper", "Integer"), 

94 Field("step", "Integer"), 

95 ] 

96 outputs = [Field("output_slice", "Slice")] 

97 shorthand = "slice" 

98 documentation = "" 

99 

100 

101class ExtSlice(object): 

102 source_language_name = {"CAST": "ext_slice"} 

103 inputs = [Field("dims", "List")] 

104 outputs = [Field("output_slice", "ExtSlice")] 

105 shorthand = "ext_slice" 

106 

107 

108class Print: # TODO: How should print work? Will likely not be a CASTGeneric function 

109 source_language_name = {"CAST": "print"} 

110 inputs = [Field("input", "Any")] 

111 outputs = [] 

112 shorthand = "print" 

113 documentation = "The cast currently uses generic primitive operators (_get, _set, iter, next) while the Gromet uses specific operators (IteratorMap_next). These primitive ops are a tempory fix for that mismatch" 

114 

115 def exec(input: Any) -> None: 

116 print(input) 

117 

118 

119class Range: 

120 source_language_name = {"CAST": "range"} 

121 inputs = [ 

122 Field("stop", "integer"), 

123 Field("start", "integer", default_val=0), 

124 Field("step", "integer", default_val=1), 

125 ] # TODO: What is the input to range? 

126 outputs = [Field("range_output", "Range")] 

127 shorthand = "range" 

128 documentation = "" 

129 

130 def exec(input: int) -> range: 

131 return range(input) 

132 

133 

134class Call: 

135 source_language_name = {"CAST": "_call"} 

136 inputs = [ 

137 Field("func_name", "string"), 

138 Field("args","Any",variatic=True) 

139 ] 

140 outputs = [Field("call_output", "Any")] 

141 shorthand = "_call" 

142 documentation = "" 

143 

144 # TODO: exec