Skip to content

Commit 2b6fc78

Browse files
authored
Merge pull request #151 from man-group/bugfix-template-local-dirs
Fix minor bug in template directory argument
2 parents 018e535 + 325de22 commit 2b6fc78

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.5.2 (2023-??)
22
------------------
33
* Feature: Allow configuring error email addresses via UI.
4+
* Bugfix: . and .. should now be allowed to be used when specifying the templates directory.
45

56

67

notebooker/utils/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def _valid_dirname(d):
17-
hidden_dirs = [dir for dir in d.split("/") if dir.startswith(".") and (dir != "." or dir != "..")]
17+
hidden_dirs = [dir for dir in d.split("/") if dir.startswith(".") and dir not in {".", ".."}]
1818
return "__init__" not in d and "__pycache__" not in d and not hidden_dirs
1919

2020

tests/unit/utils/test_templates.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
import os
2+
import pytest
23
import shutil
34
import tempfile
45

56
from notebooker.utils.filesystem import mkdir_p
7+
from notebooker.utils.templates import _valid_dirname
68
from notebooker.web.utils import get_directory_structure
79

810

11+
@pytest.mark.parametrize(
12+
"input_dirname, expected_result",
13+
[
14+
("./my_directory", True),
15+
("../hello_world/a/b/c/", True),
16+
(".git/blah", False),
17+
("../.git/hello/world", False),
18+
("normal/path/to/something", True),
19+
("/absolute/path/.git", False),
20+
("/absolute/path/git", True),
21+
],
22+
)
23+
def test_valid_dirnames(input_dirname, expected_result):
24+
assert _valid_dirname(input_dirname) is expected_result
25+
26+
927
def test_get_directory_structure():
1028
temp_dir = tempfile.mkdtemp()
1129
try:
@@ -23,7 +41,7 @@ def test_get_directory_structure():
2341
".hidden/visible/5.ipynb",
2442
".hidden/.more-hidden/6.ipynb",
2543
"./visible/7.ipynb",
26-
"this/is/../is/8.ipynb"
44+
"this/is/../is/8.ipynb",
2745
]
2846
for path in paths:
2947
abspath = os.path.join(temp_dir, path)
@@ -35,7 +53,10 @@ def test_get_directory_structure():
3553
"hello": None,
3654
"goodbye": None,
3755
"depth": {"depth/1": None, "depth/2": None, "depth/3": None},
38-
"this": {"this/report": None, "is": {"this/is/8": None, "this/is/deep": None, "very": {"this/is/very/deep": None}}},
56+
"this": {
57+
"this/report": None,
58+
"is": {"this/is/8": None, "this/is/deep": None, "very": {"this/is/very/deep": None}},
59+
},
3960
"hello_again": None,
4061
"visible": {"visible/7": None},
4162
}

0 commit comments

Comments
 (0)