11import os
2+ import pytest
23import shutil
34import tempfile
45
56from notebooker .utils .filesystem import mkdir_p
7+ from notebooker .utils .templates import _valid_dirname
68from 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+
927def 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