Skip to content

Commit

Permalink
Check if solution requires assignment download
Browse files Browse the repository at this point in the history
  • Loading branch information
ykazakov committed Oct 25, 2024
1 parent ac05c5b commit 88cbf7f
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 22 deletions.
8 changes: 6 additions & 2 deletions ngshare_exchange/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,10 @@ def format_outbound_assignment(self, info):

def format_solution(self, info):
msg = "{course_id} {assignment_id}".format(**info)
if os.path.exists(os.path.join(info['assignment_id'], 'solution')):
if info['status'] == "fetched_solution":
msg += " (already downloaded)"
elif info['status'] == "fetch_assignment":
msg += " (download assignment!)"
return msg

def copy_files(self):
Expand Down Expand Up @@ -394,8 +396,10 @@ def parse_assignments(self):
if os.path.exists(solution_dir):
info['status'] = 'fetched_solution'
info['path'] = os.path.abspath(solution_dir)
else:
elif os.path.exists(assignment_dir):
info['status'] = 'released_solution'
else:
info['status'] = 'fetch_assignment'
elif os.path.exists(assignment_dir):
info['status'] = 'fetched'
info['path'] = os.path.abspath(assignment_dir)
Expand Down
126 changes: 106 additions & 20 deletions ngshare_exchange/tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def test_list_solution_2x1_course1(self):
{
"course_id": self.course_id,
"assignment_id": self.assignment_id,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
},
],
Expand All @@ -684,7 +684,7 @@ def test_list_solution_2x1_course1(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -703,7 +703,7 @@ def test_list_solution_2x1_course2(self):
{
"course_id": self.course_id2,
"assignment_id": self.assignment_id,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
},
],
Expand All @@ -714,7 +714,7 @@ def test_list_solution_2x1_course2(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -733,7 +733,7 @@ def test_list_solution_2x1(self):
{
"course_id": course_id,
"assignment_id": self.assignment_id,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
}
for course_id in (self.course_id, self.course_id2)
Expand All @@ -745,8 +745,8 @@ def test_list_solution_2x1(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {}
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -770,7 +770,7 @@ def test_list_solution_2x2_assignment1(self):
{
"course_id": course_id,
"assignment_id": self.assignment_id,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
}
for course_id in (self.course_id, self.course_id2)
Expand All @@ -782,8 +782,8 @@ def test_list_solution_2x2_assignment1(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {}
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -807,7 +807,7 @@ def test_list_solution_2x2_assignment2(self):
{
"course_id": course_id,
"assignment_id": self.assignment_id2,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
}
for course_id in (self.course_id, self.course_id2)
Expand All @@ -819,8 +819,8 @@ def test_list_solution_2x2_assignment2(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {}
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -843,7 +843,7 @@ def test_list_solution_2x2(self):
{
"course_id": course_id,
"assignment_id": assignment_id,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
}
for course_id in (self.course_id, self.course_id2)
Expand All @@ -856,10 +856,10 @@ def test_list_solution_2x2(self):
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {}
[INFO] {} {}
[INFO] {} {}
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand All @@ -875,7 +875,93 @@ def test_list_solution_2x2(self):
)
)

def test_list_solution_fetched_assignment_1(self):
self.num_assignments = 2
self._fetch(self.course_dir)
self.num_solutions = 2
self.list.solution = True
data = self.list.start()
solution_path = self.course_dir / self.assignment_id / "solution"
notebook_solution_path = solution_path / (self.notebook_id + '.ipynb')
self.assertEqual(
data,
[
{
"course_id": self.course_id,
"assignment_id": self.assignment_id,
"status": "released_solution",
"notebooks": [{"notebook_id": self.notebook_id}],
},
{
"course_id": self.course_id,
"assignment_id": self.assignment_id2,
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
},
],
)
output = self._read_log()
assert (
output
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
.format(
self.course_id,
self.assignment_id,
self.course_id,
self.assignment_id2,
)
)

def test_list_solution_fetched_assignment_2(self):
self.num_assignments = 2
self._fetch(self.course_dir)
self._fetch(self.course_dir, assignment_id=self.assignment_id2)
self.num_solutions = 2
self.list.solution = True
data = self.list.start()
solution_path = self.course_dir / self.assignment_id / "solution"
notebook_solution_path = solution_path / (self.notebook_id + '.ipynb')
self.assertEqual(
data,
[
{
"course_id": self.course_id,
"assignment_id": assignment_id,
"status": "released_solution",
"notebooks": [{"notebook_id": self.notebook_id}],
}
for assignment_id in (self.assignment_id, self.assignment_id2)
],
)
output = self._read_log()
assert (
output
== dedent(
"""
[INFO] Released solutions:
[INFO] {} {}
[INFO] {} {}
"""
)
.lstrip()
.format(
self.course_id,
self.assignment_id,
self.course_id,
self.assignment_id2,
)
)

def test_list_fetched_solution(self):
self.num_assignments = 2
self._fetch(self.course_dir)
self.num_solutions = 2
self._fetch_solution(self.course_dir)
self.list.solution = True
Expand All @@ -900,7 +986,7 @@ def test_list_fetched_solution(self):
{
"course_id": self.course_id,
"assignment_id": self.assignment_id2,
"status": "released_solution",
"status": "fetch_assignment",
"notebooks": [{"notebook_id": self.notebook_id}],
},
],
Expand All @@ -912,7 +998,7 @@ def test_list_fetched_solution(self):
"""
[INFO] Released solutions:
[INFO] {} {} (already downloaded)
[INFO] {} {}
[INFO] {} {} (download assignment!)
"""
)
.lstrip()
Expand Down

0 comments on commit 88cbf7f

Please sign in to comment.