Skip to content

Commit

Permalink
Fix grading protocol when run after analytics (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
knrafto authored Sep 2, 2016
1 parent b432856 commit 8f12f66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
25 changes: 6 additions & 19 deletions client/protocols/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,15 @@ def grade(questions, messages, env=None, verbose=True):
locked = 0

analytics = {}
# Check if analytics info is in messages.
if 'analytics' in messages:
started = messages['analytics']['started']
else:
started = None

# The environment in which to run the tests.
for test in questions:
# run test if the question is not detected, or question detected and started
if (started is None
or test.name not in started
or started[test.name]):

log.info('Running tests for {}'.format(test.name))
results = test.run(env)
passed += results['passed']
failed += results['failed']
locked += results['locked']
analytics[test.name] = results
else:
print('It looks like you haven\'t started {}. Skipping the tests.'.format(test.name))
print()
log.info('Running tests for {}'.format(test.name))
results = test.run(env)
passed += results['passed']
failed += results['failed']
locked += results['locked']
analytics[test.name] = results

if not verbose and (failed > 0 or locked > 0):
# Stop at the first failed test
Expand Down
11 changes: 3 additions & 8 deletions tests/protocols/grading_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def testOnInteract_withTests(self):
self.assignment.specified_tests = [test]
self.assertIsInstance(self.callRun(), dict)

def testRun_skipTestsWhenQuestionNotStarted(self):
def testRun_AfterAnalytics(self):
test1 = mock.Mock(spec=models.Test)
test1.run.return_value = {
'passed': 1,
Expand All @@ -58,17 +58,12 @@ def testRun_skipTestsWhenQuestionNotStarted(self):
self.assignment.specified_tests = [test1, test2]

messages = {
'analytics': {
'started': {
'test1': False,
'test2': True
}
}
'analytics': {}
}

self.proto.run(messages)

self.assertIn('grading', messages)
results = messages['grading']
self.assertNotIn('test1', results)
self.assertIn('test1', results)
self.assertIn('test2', results)

0 comments on commit 8f12f66

Please sign in to comment.