test_nbcourse.py 1.6 KB
Newer Older
Matthieu Boileau's avatar
Matthieu Boileau committed
1
2
3
from nbcourse.initialize import initialize
from nbcourse.nbcourse import NbCourse, MyDoitMain, ClassTaskLoader
from nbcourse.utils import get_functions
4
from nbcourse import get_help_epilog
Matthieu Boileau's avatar
Matthieu Boileau committed
5
6
7
8
9
import pytest
from pathlib import Path
import os
from distutils.dir_util import copy_tree

Matthieu Boileau's avatar
Matthieu Boileau committed
10

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

Matthieu Boileau's avatar
pep8    
Matthieu Boileau committed
14

15
16
17
18
19
def test_get_help_epilog():
    """Test get_help_epilog function for CLI"""
    get_help_epilog()


Matthieu Boileau's avatar
Matthieu Boileau committed
20
21
22
23
24
25
26
@pytest.fixture
def create_project(tmpdir):
    """Create a sample nbcourse project"""
    p = tmpdir.mkdir("test_project")
    os.chdir(p)
    initialize()

Matthieu Boileau's avatar
Matthieu Boileau committed
27
    # Create a link to sample notebooks
Matthieu Boileau's avatar
Matthieu Boileau committed
28
    nb = Path('sample')
Matthieu Boileau's avatar
Matthieu Boileau committed
29
    nb.symlink_to(TESTS_PATH / 'sample', target_is_directory=True)
Matthieu Boileau's avatar
Matthieu Boileau committed
30

Matthieu Boileau's avatar
Matthieu Boileau committed
31
32
33
34
    # Create a link to sample yaml file
    yaml_file = Path('nbcourse.yml')
    yaml_file.unlink()
    yaml_file.symlink_to(TESTS_PATH / 'sample' / 'nbcourse.yml')
Matthieu Boileau's avatar
Matthieu Boileau committed
35
36
37
38
39
40
41
42
43
44


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
45
    course = NbCourse(MINI_CONF)
Matthieu Boileau's avatar
Matthieu Boileau committed
46
    assert course.build(["-n 4", task]) == 0
Matthieu Boileau's avatar
Matthieu Boileau committed
47
48
49


def test_nbcourse(create_project):
Matthieu Boileau's avatar
Matthieu Boileau committed
50
    """Test sample with nbcourse.yml sample file"""
Matthieu Boileau's avatar
Matthieu Boileau committed
51
52
    NbCourse(Path('nbcourse.yml'))

Matthieu Boileau's avatar
Matthieu Boileau committed
53

Matthieu Boileau's avatar
Matthieu Boileau committed
54
def test_nbcourse_build(create_project):
Matthieu Boileau's avatar
Matthieu Boileau committed
55
    """Test sample build with nbcourse.yml sample file"""
Matthieu Boileau's avatar
Matthieu Boileau committed
56
57
    course = NbCourse(Path('nbcourse.yml'))
    course.conf['book']
Matthieu Boileau's avatar
Matthieu Boileau committed
58
    assert course.build(["-n 4"]) == 0