test_airflow_operator.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. import pytest
  17. from elyra.airflow.operator import BootscriptBuilder
  18. def test_fail_without_cos_endpoint():
  19. with pytest.raises(TypeError):
  20. BootscriptBuilder(
  21. filename="test_notebook.ipynb",
  22. cos_bucket="test_bucket",
  23. cos_directory="test_directory",
  24. cos_dependencies_archive="test_archive.tgz",
  25. )
  26. def test_fail_without_cos_bucket():
  27. with pytest.raises(TypeError):
  28. BootscriptBuilder(
  29. filename="test_notebook.ipynb",
  30. cos_endpoint="http://testserver:32525",
  31. cos_directory="test_directory",
  32. cos_dependencies_archive="test_archive.tgz",
  33. )
  34. def test_fail_without_cos_directory():
  35. with pytest.raises(TypeError):
  36. BootscriptBuilder(
  37. filename="test_notebook.ipynb",
  38. cos_endpoint="http://testserver:32525",
  39. cos_bucket="test_bucket",
  40. cos_dependencies_archive="test_archive.tgz",
  41. )
  42. def test_fail_without_cos_dependencies_archive():
  43. with pytest.raises(TypeError):
  44. BootscriptBuilder(
  45. filename="test_notebook.ipynb",
  46. cos_endpoint="http://testserver:32525",
  47. cos_bucket="test_bucket",
  48. cos_directory="test_directory",
  49. )
  50. def test_fail_without_filename():
  51. with pytest.raises(TypeError):
  52. BootscriptBuilder(
  53. cos_endpoint="http://testserver:32525",
  54. cos_bucket="test_bucket",
  55. cos_directory="test_directory",
  56. cos_dependencies_archive="test_archive.tgz",
  57. )
  58. def test_fail_with_empty_string_as_filename():
  59. with pytest.raises(ValueError) as error_info:
  60. BootscriptBuilder(
  61. filename="",
  62. pipeline_name="test-pipeline",
  63. cos_endpoint="http://testserver:32525",
  64. cos_bucket="test_bucket",
  65. cos_directory="test_directory",
  66. cos_dependencies_archive="test_archive.tgz",
  67. )
  68. assert "You need to provide a filename for the operation." == str(error_info.value)
  69. def test_build_cmd_with_inputs_and_outputs():
  70. pipeline_inputs = ["test.txt", "test2.txt"]
  71. pipeline_outputs = ["test3.txt", "test4.txt"]
  72. boot_build = BootscriptBuilder(
  73. filename="test_notebook.ipynb",
  74. pipeline_name="test-pipeline",
  75. cos_endpoint="http://testserver:32525",
  76. cos_bucket="test_bucket",
  77. cos_directory="test_directory",
  78. cos_dependencies_archive="test_archive.tgz",
  79. inputs=pipeline_inputs,
  80. outputs=pipeline_outputs,
  81. )
  82. assert boot_build.inputs == pipeline_inputs
  83. assert boot_build.outputs == pipeline_outputs
  84. boot_arg_list = boot_build.container_cmd.split("--")
  85. for arg in boot_arg_list:
  86. arg_value = arg.split(" ")[1]
  87. if "outputs" in arg:
  88. assert arg_value == f"'{';'.join(pipeline_outputs)}'"
  89. if "inputs" in arg:
  90. assert arg_value == f"'{';'.join(pipeline_inputs)}'"