|
1 | 1 | # Copyright (c) Jupyter Development Team.
|
2 | 2 | # Distributed under the terms of the Modified BSD License.
|
3 | 3 |
|
| 4 | +import jupyter_core.paths |
4 | 5 | import nbformat
|
5 | 6 | import os
|
6 | 7 | import json
|
7 | 8 | import pytest
|
8 |
| - |
9 |
| -from binascii import hexlify |
10 |
| - |
11 |
| -import urllib.parse |
| 9 | +import shutil |
12 | 10 | import tornado
|
13 |
| -from tornado.escape import url_escape |
14 |
| - |
15 |
| -from traitlets.config import Config |
| 11 | +import urllib.parse |
16 | 12 |
|
| 13 | +from binascii import hexlify |
17 | 14 | from jupyter_server.extension import serverextension
|
18 | 15 | from jupyter_server.serverapp import ServerApp
|
19 | 16 | from jupyter_server.utils import url_path_join
|
20 | 17 | from jupyter_server.services.contents.filemanager import FileContentsManager
|
21 |
| - |
| 18 | +from tornado.escape import url_escape |
| 19 | +from traitlets.config import Config |
22 | 20 |
|
23 | 21 | from .utils import mkdir
|
24 | 22 |
|
@@ -78,8 +76,29 @@ def jp_http_port(http_server_port):
|
78 | 76 | return http_server_port[-1]
|
79 | 77 |
|
80 | 78 |
|
| 79 | +@pytest.fixture |
| 80 | +def jp_setup_templates(jp_data_dir): |
| 81 | + """Setups up a temporary directory consisting of the nbconvert templates.""" |
| 82 | + |
| 83 | + # Get path to nbconvert template directory *before* |
| 84 | + # monkeypatching the paths env variable via the jp_environ fixture. |
| 85 | + possible_paths = jupyter_core.paths.jupyter_path('nbconvert', 'templates') |
| 86 | + nbconvert_path = None |
| 87 | + for path in possible_paths: |
| 88 | + if os.path.exists(path): |
| 89 | + nbconvert_path = path |
| 90 | + break |
| 91 | + |
| 92 | + nbconvert_target = jp_data_dir / 'nbconvert' / 'templates' |
| 93 | + |
| 94 | + # copy nbconvert templates to new tmp data_dir. |
| 95 | + if nbconvert_path: |
| 96 | + shutil.copytree(nbconvert_path, str(nbconvert_target)) |
| 97 | + |
| 98 | + |
81 | 99 | @pytest.fixture(scope='function')
|
82 | 100 | def jp_configurable_serverapp(
|
| 101 | + jp_setup_templates, # this fixture must preceed jp_environ |
83 | 102 | jp_environ,
|
84 | 103 | jp_server_config,
|
85 | 104 | jp_argv,
|
|
0 commit comments