test_submit_examples.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test whether success submit examples DAG to PythonGatewayService."""
  18. import subprocess
  19. from pathlib import Path
  20. import pytest
  21. from tests.testing.constants import ignore_exec_examples
  22. from tests.testing.path import path_example
  23. @pytest.mark.parametrize(
  24. "example_path",
  25. [
  26. path
  27. for path in path_example.iterdir()
  28. if path.is_file() and path.stem not in ignore_exec_examples
  29. ],
  30. )
  31. def test_exec_white_list_example(example_path: Path):
  32. """Test execute examples and submit DAG to PythonGatewayService."""
  33. try:
  34. # Because our task decorator used module ``inspect`` to get the source, and it will
  35. # raise IOError when call it by built-in function ``exec``, so we change to ``subprocess.check_call``
  36. subprocess.check_call(["python", str(example_path)])
  37. except subprocess.CalledProcessError:
  38. raise RuntimeError("Run example %s failed.", example_path.stem)
  39. def test_exec_multiple_times():
  40. """Test whether process definition can be executed more than one times."""
  41. tutorial_path = path_example.joinpath("tutorial.py")
  42. time = 0
  43. while time < 3:
  44. try:
  45. subprocess.check_call(["python", str(tutorial_path)])
  46. except subprocess.CalledProcessError:
  47. raise RuntimeError("Run example %s failed.", tutorial_path.stem)
  48. time += 1