test_nbcourse.py 1.36 KB
Newer Older
Matthieu Boileau's avatar
Matthieu Boileau committed
1
2
3
4
5
6
7
8
9
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
from distutils.dir_util import copy_tree

TESTS_PATH = Path(__file__).parent.absolute()
Matthieu Boileau's avatar
Matthieu Boileau committed
10
MINI_CONF = {'nb': {'dir': 'sample'}}
Matthieu Boileau's avatar
Matthieu Boileau committed
11

Matthieu Boileau's avatar
pep8    
Matthieu Boileau committed
12

Matthieu Boileau's avatar
Matthieu Boileau committed
13
14
15
16
17
18
19
20
@pytest.fixture
def create_project(tmpdir):
    """Create a sample nbcourse project"""
    p = tmpdir.mkdir("test_project")
    os.chdir(p)
    initialize()

    # Create a link to notebooks sample
Matthieu Boileau's avatar
Matthieu Boileau committed
21
22
    nb = Path('sample')
    nb.symlink_to(TESTS_PATH / 'sample')
Matthieu Boileau's avatar
Matthieu Boileau committed
23
24
25
26
27
28
29
30
31
32
33
34

    return p


def test_minimal_nbcourse(create_project):
    """Only test nbcourse object instantiation"""
    NbCourse()


@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"""
Matthieu Boileau's avatar
Matthieu Boileau committed
35
    course = NbCourse(MINI_CONF)
Matthieu Boileau's avatar
Matthieu Boileau committed
36
    assert course.build(["-n 4", task]) == 0
Matthieu Boileau's avatar
Matthieu Boileau committed
37
38
39
40
41
42


def test_nbcourse(create_project):
    """Test sample with nbcourse.yml example file"""
    NbCourse(Path('nbcourse.yml'))

Matthieu Boileau's avatar
Matthieu Boileau committed
43
@pytest.mark.skip(reason="material directories not available yet")
Matthieu Boileau's avatar
Matthieu Boileau committed
44
45
46
47
def test_nbcourse_build(create_project):
    """Test sample build with nbcourse.yml example file"""
    course = NbCourse(Path('nbcourse.yml'))
    course.conf['book']
Matthieu Boileau's avatar
Matthieu Boileau committed
48
    assert course.build(["-n 4"]) == 0