Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • tuhe/unitgrade_private
1 result
Show changes
from unitgrade.framework import Report
from unitgrade.evaluate import evaluate_report_student
from cs102.homework1 import add, reverse_list
from unitgrade import UTestCase, cache # !s
from unitgrade import UTestCase, cache #!s
class Week1(UTestCase):
@classmethod
......@@ -14,61 +12,58 @@ class Week1(UTestCase):
self.assertEqualC(add(2,2))
self.assertEqualC(add(-100, 5))
# def test_reverse(self):
# self.assertEqualC(reverse_list([1, 2, 3])) #!s
#
# def test_output_capture(self):
# with self.capture() as out:
# print("hello world 42") # Genereate some output (i.e. in a homework script)
# self.assertEqual(out.numbers[0], 42) # out.numbers is a list of all numbers generated
# self.assertEqual(out.output, "hello world 42") # you can also access the raw output.
def test_reverse(self):
self.assertEqualC(reverse_list([1, 2, 3])) #!s
def test_output_capture(self):
with self.capture() as out:
print("hello world 42") # Genereate some output (i.e. in a homework script)
self.assertEqual(out.numbers[0], 42) # out.numbers is a list of all numbers generated
self.assertEqual(out.output, "hello world 42") # you can also access the raw output.
class Week1Titles(UTestCase): #!s=b
""" The same problem as before with nicer titles """
def test_add(self):
""" Test the addition method add(a,b) """
self.assertEqualC(add(2,2))
print("output generated by test")
self.assertEqualC(add(-100, 5))
def test_reverse(self):
ls = [1, 2, 3]
reverse = reverse_list(ls)
self.assertEqualC(reverse)
# Although the title is set after the test potentially fails, it will *always* show correctly for the student.
self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title #!s=b
def ex_test_output_capture(self):
with self.capture() as out:
print("hello world 42") # Genereate some output (i.e. in a homework script)
self.assertEqual(out.numbers[0], 42) # out.numbers is a list of all numbers generated
self.assertEqual(out.output, "hello world 42") # you can also access the raw output.
# class Week1Titles(UTestCase): #!s=b
# """ The same problem as before with nicer titles """
# def test_add(self):
# """ Test the addition method add(a,b) """
# self.assertEqualC(add(2,2))
# print("output generated by test")
# self.assertEqualC(add(-100, 5))
# # self.assertEqual(2,3, msg="This test automatically fails.")
#
# def test_reverse(self):
# ls = [1, 2, 3]
# reverse = reverse_list(ls)
# self.assertEqualC(reverse)
# # Although the title is set after the test potentially fails, it will *always* show correctly for the student.
# self.title = f"Checking if reverse_list({ls}) = {reverse}" # Programmatically set the title #!s
#
# def ex_test_output_capture(self):
# with self.capture() as out:
# print("hello world 42") # Genereate some output (i.e. in a homework script)
# self.assertEqual(out.numbers[0], 42) # out.numbers is a list of all numbers generated
# self.assertEqual(out.output, "hello world 42") # you can also access the raw output.
#
#
# class Question2(UTestCase): #!s=c
# @cache
# def my_reversal(self, ls):
# # The '@cache' decorator ensures the function is not run on the *students* computer
# # Instead the code is run on the teachers computer and the result is passed on with the
# # other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# # implemented reverse_list.
# return reverse_list(ls)
#
# def test_reverse_tricky(self):
# ls = (2,4,8)
# ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
# print("The correct answer is supposed to be", ls2) # Show students the correct answer
# self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
# return "Buy world!" # This value will be stored in the .token file #!s=c
class Question2(UTestCase): #!s=c
@cache
def my_reversal(self, ls):
# The '@cache' decorator ensures the function is not run on the *students* computer
# Instead the code is run on the teachers computer and the result is passed on with the
# other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# implemented reverse_list.
return reverse_list(ls)
# w = Week1
def test_reverse_tricky(self):
ls = (2,4,8)
ls2 = self.my_reversal(tuple(ls)) # This will always produce the right result, [8, 4, 2]
print("The correct answer is supposed to be", ls2) # Show students the correct answer
self.assertEqualC(reverse_list(ls)) # This will actually test the students code.
return "Buy world!" # This value will be stored in the .token file #!s=c
import cs102
class Report2(Report):
title = "CS 102 Report 2"
questions = [(Week1, 10),
# (Week1Titles, 6)
(Week1Titles, 6)
]
pack_imports = [cs102]
......
......@@ -17,10 +17,4 @@ class Report1(Report):
pack_imports = [cs101] # Include all .py files in this folder
if __name__ == "__main__":
# from HtmlTestRunner import HTMLTestRunner
import HtmlTestRunner
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='example_dir'))
# evaluate_report_student(Report1()) #!s=all
# unittest.main(verbosity=2) # Uncomment to run everything as a regular unittest
evaluate_report_student(Report1()) #!s=all
......@@ -9,5 +9,3 @@ s = " 1 / 4 * 1 / 2"
print("Result of", s, "is", from_string(s))
s = "5 / 2 div 10 / 3"
print("Result of", s, "is", from_string(s))
pass
#!i
......@@ -24,12 +24,17 @@ def exit_after(s):
'''
def outer(fn):
def inner(*args, **kwargs):
timer = threading.Timer(s, quit_function, args=[fn.__name__])
timer.start()
result = 0
try:
result = fn(*args, **kwargs)
finally:
timer.cancel()
timer = threading.Timer(s, quit_function, args=[fn.__name__])
timer.start()
try:
result = fn(*args, **kwargs)
finally:
timer.cancel()
except KeyboardInterrupt as e:
print("The function took to long and is being killed.")
args[0].assertEqual(1,2, msg="Function took to long so I am killing it.")
return result
return inner
return outer
<<<<<<< HEAD
__version__ = "0.1.62"
=======
__version__ = "0.1.61"
>>>>>>> 05f66ebff680f2f18cf59f9adf46bc6c8ecea3c0