Skip to content
Snippets Groups Projects
Commit 54ae1c6a authored by tuhe's avatar tuhe
Browse files

changes

parent d6b0e78c
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,6 @@ from unitgrade.evaluate import evaluate_report_student ...@@ -3,8 +3,6 @@ from unitgrade.evaluate import evaluate_report_student
from cs102.homework1 import add, reverse_list from cs102.homework1 import add, reverse_list
from unitgrade import UTestCase, cache #!s from unitgrade import UTestCase, cache #!s
class Week1(UTestCase): class Week1(UTestCase):
@classmethod @classmethod
def setUpClass(cls) -> None: def setUpClass(cls) -> None:
...@@ -14,61 +12,58 @@ class Week1(UTestCase): ...@@ -14,61 +12,58 @@ class Week1(UTestCase):
self.assertEqualC(add(2,2)) self.assertEqualC(add(2,2))
self.assertEqualC(add(-100, 5)) self.assertEqualC(add(-100, 5))
# def test_reverse(self): def test_reverse(self):
# self.assertEqualC(reverse_list([1, 2, 3])) #!s self.assertEqualC(reverse_list([1, 2, 3])) #!s
#
# def test_output_capture(self): def test_output_capture(self):
# with self.capture() as out: with self.capture() as out:
# print("hello world 42") # Genereate some output (i.e. in a homework script) 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.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. 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 class Question2(UTestCase): #!s=c
# """ The same problem as before with nicer titles """ @cache
# def test_add(self): def my_reversal(self, ls):
# """ Test the addition method add(a,b) """ # The '@cache' decorator ensures the function is not run on the *students* computer
# self.assertEqualC(add(2,2)) # Instead the code is run on the teachers computer and the result is passed on with the
# print("output generated by test") # other pre-computed results -- i.e. this function will run regardless of how the student happens to have
# self.assertEqualC(add(-100, 5)) # implemented reverse_list.
# # self.assertEqual(2,3, msg="This test automatically fails.") return reverse_list(ls)
#
# 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
# 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 import cs102
class Report2(Report): class Report2(Report):
title = "CS 102 Report 2" title = "CS 102 Report 2"
questions = [(Week1, 10), questions = [(Week1, 10),
# (Week1Titles, 6) (Week1Titles, 6)
] ]
pack_imports = [cs102] pack_imports = [cs102]
......
...@@ -17,10 +17,4 @@ class Report1(Report): ...@@ -17,10 +17,4 @@ class Report1(Report):
pack_imports = [cs101] # Include all .py files in this folder pack_imports = [cs101] # Include all .py files in this folder
if __name__ == "__main__": if __name__ == "__main__":
# from HtmlTestRunner import HTMLTestRunner evaluate_report_student(Report1()) #!s=all
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
...@@ -9,5 +9,3 @@ s = " 1 / 4 * 1 / 2" ...@@ -9,5 +9,3 @@ s = " 1 / 4 * 1 / 2"
print("Result of", s, "is", from_string(s)) print("Result of", s, "is", from_string(s))
s = "5 / 2 div 10 / 3" s = "5 / 2 div 10 / 3"
print("Result of", s, "is", from_string(s)) print("Result of", s, "is", from_string(s))
pass
#!i
...@@ -23,6 +23,7 @@ src/unitgrade_private/hidden_create_files.py ...@@ -23,6 +23,7 @@ src/unitgrade_private/hidden_create_files.py
src/unitgrade_private/hidden_gather_upload.py src/unitgrade_private/hidden_gather_upload.py
src/unitgrade_private/run.py src/unitgrade_private/run.py
src/unitgrade_private/token_loader.py src/unitgrade_private/token_loader.py
src/unitgrade_private/utils.py
src/unitgrade_private/version.py src/unitgrade_private/version.py
src/unitgrade_private/autolab/__init__.py src/unitgrade_private/autolab/__init__.py
src/unitgrade_private/autolab/autolab.py src/unitgrade_private/autolab/autolab.py
......
...@@ -24,12 +24,17 @@ def exit_after(s): ...@@ -24,12 +24,17 @@ def exit_after(s):
''' '''
def outer(fn): def outer(fn):
def inner(*args, **kwargs): def inner(*args, **kwargs):
result = 0
try:
timer = threading.Timer(s, quit_function, args=[fn.__name__]) timer = threading.Timer(s, quit_function, args=[fn.__name__])
timer.start() timer.start()
try: try:
result = fn(*args, **kwargs) result = fn(*args, **kwargs)
finally: finally:
timer.cancel() 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 result
return inner return inner
return outer return outer
......
__version__ = "0.1.60" __version__ = "0.1.62"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment