Skip to content

Commit

Permalink
CI: redirect stdout and silence logging during testing tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
schlegelp committed Sep 5, 2024
1 parent 89c66ed commit d5a5343
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions tests/test_tutorials.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,44 @@
"""

import os
import subprocess
import sys
import navis

from pathlib import Path
from contextlib import contextmanager

SKIP = ["zzz_no_plot_01_nblast_flycircuit.py", "zzz_no_plot_02_nblast_hemibrain.py"]


@contextmanager
def suppress_stdout():
with open(os.devnull, "w") as devnull:
old_stdout = sys.stdout
sys.stdout = devnull
try:
yield
finally:
sys.stdout = old_stdout

# Silence logging
navis.config.logger.setLevel("ERROR")
navis.set_pbars(hide=True)

SKIP = [
"zzz_no_plot_01_nblast_flycircuit.py",
"zzz_no_plot_02_nblast_hemibrain.py"
]

if __name__ == "__main__":
# Recursively search for notebooks
path = Path(__file__).parent.parent / "docs/examples"

files = list(path.rglob("*.py"))
for i, file in enumerate(files):

if not file.is_file():
continue
if file.name in SKIP:
continue

print(f"Executing {file.name} [{i+1}/{len(files)}]... ", end="", flush=True)
os.chdir(file.parent)
exec(open(file.name).read())
with suppress_stdout():
exec(open(file).read())
print("Done.", flush=True)

# print(f"Executing {file.name} [{i+1}/{len(files)}]... ", end="", flush=True)
# try:
# # Set `capture_output=True` to see e.g. error messages.
# p = subprocess.run(["python", str(file)], check=True, capture_output=True, timeout=600, cwd=file.parent)
# except subprocess.CalledProcessError as e:
# print("Failed!")
# print(e.stdout.decode())
# print(e.stderr.decode())
# raise
# print("Done.", flush=True)

print("All done.")

0 comments on commit d5a5343

Please sign in to comment.