test_docs.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 pydolphinscheduler docs."""
  18. import re
  19. from tests.testing.constants import task_without_example
  20. from tests.testing.path import get_doc_tasks, get_tasks
  21. ignore_code_file = {"__init__.py"}
  22. ignore_doc_file = {"index.rst"}
  23. def test_without_missing_task_rst():
  24. """Test without missing any task document by compare filename.
  25. Avoiding add new type of tasks but without adding document about it.
  26. """
  27. code_files = {p.stem for p in get_tasks(ignore_name=ignore_code_file)}
  28. doc_files = {p.stem for p in get_doc_tasks(ignore_name=ignore_doc_file)}
  29. assert code_files == doc_files
  30. def test_task_without_example():
  31. """Test task document which without example.
  32. Avoiding add new type of tasks but without adding example content describe how to use it.
  33. """
  34. task_without_example_detected = set()
  35. pattern = re.compile("Example\n-------")
  36. for doc in get_doc_tasks(ignore_name=ignore_doc_file):
  37. search_result = pattern.search(doc.read_text())
  38. if not search_result:
  39. task_without_example_detected.add(doc.stem)
  40. assert task_without_example == task_without_example_detected
  41. def test_doc_automodule_directive_name():
  42. """Test task document with correct name in directive automodule."""
  43. pattern = re.compile(".. automodule:: (.*)")
  44. for doc in get_doc_tasks(ignore_name=ignore_doc_file):
  45. match_string = pattern.search(doc.read_text()).group(1)
  46. assert f"pydolphinscheduler.tasks.{doc.stem}" == match_string