airflow_test_operator.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from typing import Any
  17. from typing import Dict
  18. from typing import List
  19. from typing import Optional
  20. from airflow.models import BaseOperator
  21. from airflow.operators.imported_operator import ImportedOperator # noqa TODO
  22. class TestOperator(BaseOperator):
  23. """
  24. Operator derives from BaseOperator and mimics Airflow v1 Operator structure.
  25. Note that some parameters have been intentionally omitted from the docstring
  26. in order to test that fallback types are assigned appropriately.
  27. :param str_no_default: a string parameter with no default given
  28. :type str_no_default: str
  29. :param bool_no_default: a boolean parameter with no default given
  30. :type bool_no_default: bool
  31. :param int_no_default: an integer parameter with no default given
  32. :type int_no_default: int
  33. :param str_default: a string parameter with a default value given
  34. :type str_default: str
  35. :param bool_default_true: a boolean parameter with a default value of True
  36. :type bool_default_true: bool
  37. :param bool_default_false: a boolean parameter with a default value of False
  38. :type bool_default_false: bool
  39. :param int_default_non_zero: an integer parameter with a non-zero default value
  40. :type int_default_non_zero: int
  41. :param int_default_zero: an integer parameter with a default value of 0
  42. :type int_default_zero: int
  43. :param str_empty: a string parameter with a default value of None
  44. :type str_empty: str
  45. :param list_default_is_none: an list parameter with a default of None
  46. :type list_default_is_none: list
  47. :param dict_default_is_none: a dictionary parameter with a default of None
  48. :type dict_default_is_none: dict
  49. :param unusual_type_dict: a dictionary parameter with the phrase 'list' in type description
  50. :type unusual_type_dict: a dictionary of arrays
  51. :param unusual_type_list: a list parameter with the phrase 'string' in type description
  52. :type unusual_type_list: a list of strings
  53. :param long_description_property: a string parameter with a very long description
  54. that wraps lines and also has an escaped underscore in it, as shown here: (\_) # noqa W605
  55. :type long_description_property: str
  56. :param: mounted_volumes: a property with the same name as an Elyra system property
  57. :type: str
  58. """
  59. def __init__(
  60. self,
  61. str_no_default,
  62. bool_no_default,
  63. int_no_default,
  64. str_default="default",
  65. bool_default_true=True,
  66. bool_default_false=False,
  67. int_default_non_zero=2,
  68. int_default_zero=0,
  69. str_empty=None,
  70. list_default_is_none=None,
  71. dict_default_is_none=None,
  72. str_not_in_docstring="",
  73. bool_not_in_docstring=False,
  74. int_not_in_docstring=3,
  75. unusual_type_dict=None,
  76. unusual_type_list=None,
  77. fallback_type=None,
  78. long_description_property=None,
  79. mounted_volumes=None,
  80. *args,
  81. **kwargs,
  82. ):
  83. super().__init__(*args, **kwargs)
  84. def execute(self, context: Any):
  85. pass
  86. class DeriveFromTestOperator(TestOperator):
  87. """
  88. Operator derives indirectly from BaseOperator and mimics Airflow v2 Operator
  89. structure, including type hints given for all parameters
  90. :param str_no_default: a string parameter with no default given
  91. :type str_no_default: str
  92. :param bool_no_default: a boolean parameter with no default given
  93. :type bool_no_default: bool
  94. :param int_no_default: an integer parameter with no default given
  95. :type int_no_default: int
  96. :param str_default: a string parameter with a default value given
  97. :type str_default: str
  98. :param bool_default: a boolean parameter with a default value given
  99. :type bool_default: bool
  100. :param int_default: an integer parameter with a default value given
  101. :type int_default: int
  102. :param str_optional_default: an Optional string parameter with a default value given
  103. :type str_optional_default: Optional[str]
  104. :param list_optional_default: an Optional list parameter with a default of None
  105. :type list_optional_default: Optional[list]
  106. """
  107. def __init__(
  108. self,
  109. *,
  110. str_no_default: str,
  111. bool_no_default: bool,
  112. int_no_default: int,
  113. str_not_in_docstring: str,
  114. bool_not_in_docstring: bool,
  115. int_not_in_docstring: int,
  116. str_default: str = "default",
  117. bool_default: bool = True,
  118. int_default: int = 2,
  119. str_optional_default: Optional[str] = "optional default",
  120. list_optional_default: Optional[List] = None,
  121. **kwargs,
  122. ):
  123. super().__init__(**kwargs)
  124. def execute(self, context: Any):
  125. pass
  126. class DeriveFromImportedOperator(ImportedOperator):
  127. """
  128. Operator derives from an airflow package Operator (and therefore indirectly
  129. extends the BaseOperator) and whose parameters are list and dictionary types
  130. :param dict_no_default: a dictionary parameter with no default given
  131. :type dict_no_default: dict
  132. :param list_no_default: a list parameter with no default given
  133. :type list_no_default: list
  134. :param dict_optional_no_default: an optional dictionary parameter with no default given
  135. :type dict_optional_no_default: Optional[Dict[str, str]]
  136. :param list_optional_no_default: an optional list parameter with no default given
  137. :type list_optional_no_default: Optional[List[int]]
  138. :param nested_dict_default: a nested dictionary parameter with a default value
  139. :type nested_dict_default: Dict[str, Dict[str, str]]
  140. :param list_default: a list parameter with a default value
  141. :type list_default: List[str]
  142. :param list_optional_default: a list parameter with a default value of None
  143. :type list_optional_default: Optional[List[str]]
  144. """
  145. def __init__(
  146. self,
  147. *,
  148. dict_no_default: Dict,
  149. list_no_default: List,
  150. dict_optional_no_default: Optional[Dict[str, str]],
  151. list_optional_no_default: Optional[List[int]],
  152. nested_dict_default: Dict[str, Dict[str, str]] = None,
  153. list_default: List[str] = None,
  154. list_optional_default: Optional[List[str]] = None,
  155. list_not_in_docstring: List[str],
  156. dict_not_in_docstring: Dict[str, str],
  157. **kwargs,
  158. ):
  159. super().__init__(**kwargs)
  160. def execute(self, context: Any):
  161. pass
  162. class HelperClass1:
  163. """
  164. A class that should not be picked up by the parser as it does not
  165. derive from an Operator class
  166. """
  167. def __init__(self, myvar1, *args, **kwargs):
  168. super().__init__(*args, **kwargs)
  169. class HelperClass2(object):
  170. """
  171. Another class that should not be picked up by the parser as it does not
  172. derive from an Operator class
  173. """
  174. def __init__(self, myvar2, *args, **kwargs):
  175. super().__init__(*args, **kwargs)