Commit f504dc18 authored by Matthieu Boileau's avatar Matthieu Boileau

Add get_functions()

parent d291875e
import shutil
from pathlib import Path
from zipfile import ZipFile
import inspect
import re
IGNORED = '__pycache__'
......@@ -58,3 +60,17 @@ def zip_files(zip_file_name: Path, paths_to_zip: list,
arcpath = arcdir / path.relative_to(refpath) \
if ref_to_arc else None
zf.write(path, arcname=arcpath)
def get_functions(namespace, pattern: str) -> list:
Return the list of functions in namespace that match the regex pattern
all_functions = inspect.getmembers(namespace, inspect.isfunction)
p = re.compile(pattern)
functions = []
for function, dummy in all_functions:
m = p.match(function)
if m:
return functions
from nbcourse.initialize import initialize
from nbcourse.nbcourse import NbCourse, MyDoitMain, ClassTaskLoader
from nbcourse.utils import get_functions
import pytest
from pathlib import Path
import os
......@@ -33,13 +34,9 @@ def test_minimal_nbcourse_build_pages(create_project):["build_pages"])
TASKS = 'output_dir', 'copy_material', 'copy_reveal', 'zip_chapters', \
'build_pages', 'execute_notebooks', 'convert_to_html', \
'convert_to_slides', 'build_book', 'zip_archive'
@pytest.mark.parametrize('task', TASKS)
@pytest.mark.parametrize('task', get_functions(NbCourse, 'task_(.*)'))
def test_minimal_nbcourse_build(create_project, task):
"""test nbcourse on list of doit tasks returned by get_functions"""
course = NbCourse()
with pytest.raises(SystemExit):["-n 4", task])
from nbcourse.utils import update_dict
from nbcourse.utils import update_dict, get_functions
from nbcourse.nbcourse import NbCourse
import os
from pprint import pprint
import pytest
......@@ -29,3 +30,10 @@ def test_update_dict():
'1-d': {'2-d': 0}}
assert cur == ref
def test_utils():
tasks = {'output_dir', 'copy_material', 'copy_reveal', 'zip_chapters',
'build_pages', 'execute_notebooks', 'convert_to_html',
'convert_to_slides', 'build_book', 'zip_archive'}
assert tasks.issubset(set(get_functions(NbCourse, 'task_(.*)')))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment