airflow_test_operator.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. """
  57. def __init__(
  58. self,
  59. str_no_default,
  60. bool_no_default,
  61. int_no_default,
  62. str_default="default",
  63. bool_default_true=True,
  64. bool_default_false=False,
  65. int_default_non_zero=2,
  66. int_default_zero=0,
  67. str_empty=None,
  68. list_default_is_none=None,
  69. dict_default_is_none=None,
  70. str_not_in_docstring="",
  71. bool_not_in_docstring=False,
  72. int_not_in_docstring=3,
  73. unusual_type_dict=None,
  74. unusual_type_list=None,
  75. fallback_type=None,
  76. long_description_property=None,
  77. *args,
  78. **kwargs,
  79. ):
  80. super().__init__(*args, **kwargs)
  81. def execute(self, context: Any):
  82. pass
  83. class DeriveFromTestOperator(TestOperator):
  84. """
  85. Operator derives indirectly from BaseOperator and mimics Airflow v2 Operator
  86. structure, including type hints given for all parameters
  87. :param str_no_default: a string parameter with no default given
  88. :type str_no_default: str
  89. :param bool_no_default: a boolean parameter with no default given
  90. :type bool_no_default: bool
  91. :param int_no_default: an integer parameter with no default given
  92. :type int_no_default: int
  93. :param str_default: a string parameter with a default value given
  94. :type str_default: str
  95. :param bool_default: a boolean parameter with a default value given
  96. :type bool_default: bool
  97. :param int_default: an integer parameter with a default value given
  98. :type int_default: int
  99. :param str_optional_default: an Optional string parameter with a default value given
  100. :type str_optional_default: Optional[str]
  101. :param list_optional_default: an Optional list parameter with a default of None
  102. :type list_optional_default: Optional[list]
  103. """
  104. def __init__(
  105. self,
  106. *,
  107. str_no_default: str,
  108. bool_no_default: bool,
  109. int_no_default: int,
  110. str_not_in_docstring: str,
  111. bool_not_in_docstring: bool,
  112. int_not_in_docstring: int,
  113. str_default: str = "default",
  114. bool_default: bool = True,
  115. int_default: int = 2,
  116. str_optional_default: Optional[str] = "optional default",
  117. list_optional_default: Optional[List] = None,
  118. **kwargs,
  119. ):
  120. super().__init__(**kwargs)
  121. def execute(self, context: Any):
  122. pass
  123. class DeriveFromImportedOperator(ImportedOperator):
  124. """
  125. Operator derives from an airflow package Operator (and therefore indirectly
  126. extends the BaseOperator) and whose parameters are list and dictionary types
  127. :param dict_no_default: a dictionary parameter with no default given
  128. :type dict_no_default: dict
  129. :param list_no_default: a list parameter with no default given
  130. :type list_no_default: list
  131. :param dict_optional_no_default: an optional dictionary parameter with no default given
  132. :type dict_optional_no_default: Optional[Dict[str, str]]
  133. :param list_optional_no_default: an optional list parameter with no default given
  134. :type list_optional_no_default: Optional[List[int]]
  135. :param nested_dict_default: a nested dictionary parameter with a default value
  136. :type nested_dict_default: Dict[str, Dict[str, str]]
  137. :param list_default: a list parameter with a default value
  138. :type list_default: List[str]
  139. :param list_optional_default: a list parameter with a default value of None
  140. :type list_optional_default: Optional[List[str]]
  141. """
  142. def __init__(
  143. self,
  144. *,
  145. dict_no_default: Dict,
  146. list_no_default: List,
  147. dict_optional_no_default: Optional[Dict[str, str]],
  148. list_optional_no_default: Optional[List[int]],
  149. nested_dict_default: Dict[str, Dict[str, str]] = None,
  150. list_default: List[str] = None,
  151. list_optional_default: Optional[List[str]] = None,
  152. list_not_in_docstring: List[str],
  153. dict_not_in_docstring: Dict[str, str],
  154. **kwargs,
  155. ):
  156. super().__init__(**kwargs)
  157. def execute(self, context: Any):
  158. pass
  159. class HelperClass1:
  160. """
  161. A class that should not be picked up by the parser as it does not
  162. derive from an Operator class
  163. """
  164. def __init__(self, myvar1, *args, **kwargs):
  165. super().__init__(*args, **kwargs)
  166. class HelperClass2(object):
  167. """
  168. Another class that should not be picked up by the parser as it does not
  169. derive from an Operator class
  170. """
  171. def __init__(self, myvar2, *args, **kwargs):
  172. super().__init__(*args, **kwargs)