File tree Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Expand file tree Collapse file tree 2 files changed +17
-12
lines changed Original file line number Diff line number Diff line change @@ -316,24 +316,25 @@ def format_path(
316316 When escape=True, the non-passed elements of the path are regex-escaped, so the
317317 resulting string can be used as a pattern to match path components.
318318 """
319-
320319 kwargs = dict (
321320 nbgrader_step = nbgrader_step ,
322321 student_id = student_id ,
323322 assignment_id = assignment_id
324323 )
325-
326- if escape :
327- base = Path (re .escape (self .root ))
328- else :
329- base = Path (self .root )
330-
331- path = base / self .directory_structure .format (** kwargs )
332-
324+ base = Path (self .root )
325+ structure = Path (self .directory_structure .format (** kwargs ))
333326 if escape :
334- return path .anchor + re .escape (os .path .sep ).join (path .parts [1 :])
327+ if structure .is_absolute ():
328+ anchor = structure .anchor
329+ parts = list (structure .parts )
330+ else :
331+ anchor = base .anchor
332+ parts = [re .escape (part ) for part in base ._tail ] + list (structure .parts )
333+ return re .escape (anchor ) + re .escape (os .path .sep ).join (parts )
335334 else :
336- return str (path )
335+ if structure .is_absolute ():
336+ return str (structure )
337+ return str (base / structure )
337338
338339 def find_assignments (self ,
339340 nbgrader_step : str = "*" ,
Original file line number Diff line number Diff line change @@ -20,7 +20,11 @@ def test_coursedir_configurable(conf, course_dir):
2020 assert coursedir .root == course_dir
2121
2222
23- @pytest .mark .parametrize ("root" , [None , os .path .sep + "[special]~root" ])
23+ @pytest .mark .parametrize ("root" , [
24+ None , # Keep the course_dir fixture
25+ os .path .sep + "[special]~root" ,
26+ "C:\\ Users\\ Student" ,
27+ ])
2428def test_coursedir_format_path (conf , root ):
2529 if root is not None :
2630 conf .CourseDirectory .root = root
You can’t perform that action at this time.
0 commit comments