Commit e9f401e2 authored by Matthieu Boileau's avatar Matthieu Boileau
Browse files

test update_material

parent 509ac265
Pipeline #6004 passed with stage
in 34 seconds
......@@ -211,7 +211,7 @@ class NbCourse:
src_files = [src_path / file for file in files]
dst_path = self.conf['output_path'] / Path(
dst_files = [dst_path / file for file in files]
else: # dealing with single file
else: # dealing with single file, preserve directory tree
src_files = [src_path]
dst_path = self.conf['output_path'] /
dst_files = [dst_path]
......@@ -13,7 +13,12 @@ def update_material(src: Path, dst: Path):
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(IGNORED))
except NotADirectoryError:
shutil.copy(src, dst)
shutil.copy(src, dst)
except FileNotFoundError:
Path(dst.parent).mkdir(parents=True, exist_ok=True)
shutil.copy(src, dst)
def get_file_list(path: Path, relative=True, ignore: list = None):
from nbcourse.utils import update_dict, get_functions
import filecmp
from nbcourse.utils import update_dict, get_functions, update_material
from nbcourse.nbcourse import NbCourse
import os
from pathlib import Path
from pprint import pprint
import pytest
TESTS_PATH = Path(__file__).parent.absolute()
def test_update_dict():
......@@ -38,3 +42,28 @@ def test_get_functions():
'build_pages', 'execute_notebooks', 'convert_to_html',
'convert_to_slides', 'build_book', 'zip_archive'}
assert tasks.issubset(set(get_functions(NbCourse, 'task_(.*)')))
def temporary_directory(tmpdir):
"""Create a sample nbcourse project"""
p = tmpdir.mkdir("test_utils")
def test_update_material(temporary_directory):
"""Check that a directory tree is updated"""
src = TESTS_PATH / Path("sample/fig")
dst = Path("build/fig")
update_material(src, dst)
cmp = filecmp.dircmp(src, dst)
assert not cmp.diff_files
def test_update_material_file(temporary_directory):
"""Check that a single file is updated"""
src = TESTS_PATH / Path("sample/exos/")
dst = Path("build/exos/")
update_material(src, dst)
assert filecmp.cmp(src, dst)
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