diff options
author | raylu <raylu@cmu.edu> | 2011-05-13 18:14:58 -0400 |
---|---|---|
committer | raylu <raylu@cmu.edu> | 2011-05-13 18:14:58 -0400 |
commit | f564a4616beead043e1568f22f5ef908af601afb (patch) | |
tree | 4d55d27f0c3d022b04a00551af5f7c4bf3178fda /graders | |
parent | d31422d4908dcb0d63b372ce9c10e371a0b4113c (diff) | |
download | pyc-f564a4616beead043e1568f22f5ef908af601afb.tar.xz |
Lab 2!
Diffstat (limited to 'graders')
-rwxr-xr-x | graders/lab2.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/graders/lab2.py b/graders/lab2.py new file mode 100755 index 0000000..fa4c056 --- /dev/null +++ b/graders/lab2.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import sys +sys.path.append('/home/dotcloud/env/lib/python2.6/site-packages') +from sandbox import Sandbox, SandboxConfig +from os import path + +importname = sys.argv[1] +if importname.endswith('.py'): + importname = importname[:len(importname)-3] +else: + print >> sys.stderr, 'Filename did not end with .py for some reason...' + sys.exit(2) + +sys.path.insert(0, path.expanduser('~/submissions')) +sys.dont_write_bytecode = True + +output = '' +def run(): + exec("import %s as submission" % importname) + global output + score = 0 + + list1 = [-9, 20, 501] + list2 = xrange(100) + if submission.total(list1) == sum(list1): + score += 1 + else: + output += "Tried total(%s) and got %s\n" % (list1, submission.total(list1)) + if submission.total(list2) == sum(list2): + score += 1 + else: + output += "Tried total(%s) and got %s\n" % (list2, submission.total(list2)) + + onestring1 = submission.onestring() + onestring2 = submission.onestring() + if onestring1 == 1: + score += 1 + else: + output += "First call to onestring() returned %s\n" % onestring1 + if onestring2 == 'ring': + score += 1 + else: + output += "Second call to onestring() returned %s\n" % onestring2 + return score + +config = SandboxConfig() +config.timeout = 5 +config.allowModule(importname, 'total', 'onestring') +sandbox = Sandbox(config) +score = sandbox.call(run) +print score +print >> sys.stderr, output |