Video editing with Python
add tests for doc examples
osaajani507d173e3d84
diff --git a/tests/conftest.py b/tests/conftest.pyindex a5062dc6..5a0b937f 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -16,6 +16,7 @@ import threadingimport numpy as npimport pytest+import pathlibfrom moviepy.video.io.VideoFileClip import VideoFileClip@@ -25,6 +26,9 @@ TMP_DIR = tempfile.gettempdir() # because tempfile.tempdir is sometimes None# Arbitrary font used in caption testing.FONT = "media/doc_medias/example.ttf"+# Dir for doc examples medias+DOC_EXAMPLES_MEDIAS_DIR = "media/doc_medias"+@functools.lru_cache(maxsize=None)def get_video(start_time=0, end_time=1):@@ -142,6 +146,7 @@ def util():class MoviepyTestUtils:FONT = FONTTMP_DIR = TMP_DIR+ DOC_EXAMPLES_MEDIAS_DIR = DOC_EXAMPLES_MEDIAS_DIRreturn MoviepyTestUtils@@ -173,4 +178,4 @@ def moviepy_modules():@pytest.fixturedef functions_with_decorator_defined():- return get_functions_with_decorator_defined+ return get_functions_with_decorator_defined\ No newline at end of filediff --git a/tests/test_doc_examples.py b/tests/test_doc_examples.pynew file mode 100644index 00000000..39b0d994--- /dev/null+++ b/tests/test_doc_examples.py@@ -0,0 +1,47 @@+"""Try to run all the documentation examples with runpy and check they dont raise exception"""++import os+import pytest+import shutil+import subprocess+import sys+import runpy+import pathlib+++from contextlib import contextmanager+import os++@contextmanager+def cwd(path):+ oldpwd = os.getcwd()+ os.chdir(path)+ try:+ yield+ finally:+ os.chdir(oldpwd)++# Dir for doc code examples to run+DOC_EXAMPLES_DIR = "docs/_static/code"++# List of examples script to ignore, mostly scripts that are too long+DOC_EXAMPLES_IGNORE = ['trailer.py']++scripts = pathlib.Path(DOC_EXAMPLES_DIR).resolve().rglob('*.py')+[email protected]('script', scripts)+def test_doc_examples(util, tmp_path, script):+ print('Try script: ', script)++ if os.path.basename(script) in DOC_EXAMPLES_IGNORE :+ return++ # Lets build a test dir with all medias needed to run our test in+ shutil.copytree(util.DOC_EXAMPLES_MEDIAS_DIR, os.path.join(tmp_path, "doc_tests"))+ test_dir = os.path.join(tmp_path, "doc_tests")++ with cwd(test_dir) :+ runpy.run_path(script)++if __name__ == "__main__":+ pytest.main()