I’m a grader for a beginning programming class using Python. My python-fu is not so strong myself, but I would like to try to automate some of the grading.
Looking online, I like the PyUnit testing suite, though it probably is a bit overpowered for what I want.
My problem is that I’m not sure how to pass the test inputs I want to the student’s functions, since they are not using command line arguments or even multiple functions yet, but getting user input through the input() function.
A silly example:
#/usr/bin/python3.1
# A silly example python program
def main():
a = int(input("Enter an integer: "))
b = int(input("Enter another integer: "))
c = a+b
print("The sum is %d" % c)
if __name__ == '__main__'
main()
For my silly example, how would I write a unit test that could check the output for several different inputs? (ie, if I pass 2 and 3 to the input, the output string should be “The sum is 5”)
Edit: Only proposing this since the example isn’t unittest-able (and I’m assuming the beginner students will just be confused by the constraint)
If you are just concerned with the output matching what you are looking for, why not just use some “silly” bash? Something like:
If you are doing relatively trivial programs like this, then this should be a sufficient, or good enough, solution that requires little effort.