77
88from nbgrader .coursedir import CourseDirectory
99
10+ def pluck (key , collection ):
11+ return sorted ([x [key ] for x in collection ], key = lambda x : x )
12+
13+ def touch (path ):
14+ path .parent .mkdir (parents = True , exist_ok = True )
15+ path .touch ()
16+
1017@pytest .mark .parametrize ("root" , [
1118 None , # Keep the course_dir fixture
1219 os .path .sep + "[special]~root" ,
1320 "C:\\ Users\\ Student" ,
1421])
1522def test_coursedir_format_path (course_dir , root ):
16- conf = Config ()
23+ config = Config ()
1724 if root is None :
1825 root = course_dir
19- conf .CourseDirectory .root = root
20- coursedir = CourseDirectory (config = conf )
26+ config .CourseDirectory .root = root
27+ coursedir = CourseDirectory (config = config )
2128
2229 # The default includes the un-escaped root
2330 path = os .path .join (coursedir .root , "step" , "student_id" , "assignment1" )
@@ -37,3 +44,76 @@ def test_coursedir_format_path(course_dir, root):
3744 match = re .match (actual , path )
3845 assert match is not None
3946 assert match .group ("assignment_id" ) == "assignment1"
47+
48+ def test_find_assignments (course_dir ):
49+ config = Config ({"CourseDirectory" : {"root" : course_dir }})
50+ coursedir = CourseDirectory (config = config )
51+
52+ root = Path (coursedir .root )
53+
54+ root .joinpath ("source" , "." , "assn" ).mkdir (parents = True )
55+ root .joinpath ("release" , "." , "assn" ).mkdir (parents = True )
56+ root .joinpath ("submitted" , "student1" , "assn" ).mkdir (parents = True )
57+ root .joinpath ("submitted" , "student2" , "assn" ).mkdir (parents = True )
58+ root .joinpath ("autograded" , "student1" , "assn" ).mkdir (parents = True )
59+ root .joinpath ("autograded" , "student2" , "assn" ).mkdir (parents = True )
60+ root .joinpath ("feedback" , "student1" , "assn" ).mkdir (parents = True )
61+ root .joinpath ("feedback" , "student2" , "assn" ).mkdir (parents = True )
62+
63+
64+ assert pluck ("assignment_id" , coursedir .find_assignments ("source" , "." )) == [
65+ "assn" ,
66+ ]
67+
68+ assert pluck ("student_id" , coursedir .find_assignments ("submitted" )) == [
69+ "student1" , "student2" ,
70+ ]
71+
72+ assert pluck ("nbgrader_step" , coursedir .find_assignments (student_id = "student1" )) == [
73+ "autograded" , "feedback" , "submitted" ,
74+ ]
75+
76+ # Finding by assignment has the shortcoming of not being able to find across
77+ # student_id="." and student_id="*" at the same time.
78+ assn = coursedir .find_assignments (assignment_id = "assn" , student_id = "." )
79+ assert pluck ("nbgrader_step" , assn ) == ["release" , "source" ]
80+
81+ assn = coursedir .find_assignments (assignment_id = "assn" )
82+ assert pluck ("nbgrader_step" , assn ) == [
83+ "autograded" , "autograded" , "feedback" , "feedback" , "submitted" , "submitted" ,
84+ ]
85+
86+ def test_find_notebooks (course_dir ):
87+ config = Config ({"CourseDirectory" : {"root" : course_dir }})
88+ coursedir = CourseDirectory (config = config )
89+
90+ root = Path (coursedir .root )
91+
92+ touch (root .joinpath ("source" , "." , "assn" , "assn.ipynb" ))
93+ touch (root .joinpath ("release" , "." , "assn" , "assn.ipynb" ))
94+ touch (root .joinpath ("submitted" , "student1" , "assn" , "assn.ipynb" ))
95+ touch (root .joinpath ("submitted" , "student2" , "assn" , "assn.ipynb" ))
96+ touch (root .joinpath ("autograded" , "student1" , "assn" , "assn.ipynb" ))
97+ touch (root .joinpath ("autograded" , "student2" , "assn" , "assn.ipynb" ))
98+ touch (root .joinpath ("feedback" , "student1" , "assn" , "assn.html" ))
99+ touch (root .joinpath ("feedback" , "student2" , "assn" , "assn.html" ))
100+
101+ assert pluck ("ext" , coursedir .find_notebooks (assignment_id = "assn" , ext = "*" )) == [
102+ "html" ,
103+ "html" ,
104+ "ipynb" ,
105+ "ipynb" ,
106+ "ipynb" ,
107+ "ipynb" ,
108+ ]
109+
110+
111+ # By default, we only look for .ipynb files
112+ assert pluck ("nbgrader_step" , coursedir .find_notebooks (student_id = "student1" )) == [
113+ "autograded" , "submitted" ,
114+ ]
115+
116+ assert pluck ("nbgrader_step" , coursedir .find_notebooks (student_id = "student1" , ext = "*" )) == [
117+ "autograded" , "feedback" , "submitted" ,
118+ ]
119+
0 commit comments