Skip to content
Snippets Groups Projects
Commit 0263c5d7 authored by tuhe's avatar tuhe
Browse files

Version jump with changes to token file structure

parent 837c1df0
Branches
No related tags found
No related merge requests found
Showing
with 88 additions and 64 deletions
......@@ -73,10 +73,11 @@ class Week1(unittest.TestCase):
self.assertEqual(reverse_list([1,2,3]), [3,2,1])
```
A number of tests can be collected into a `Report`, which will allow us to assign points to the tests and use the more advanced features of the framework later. A complete, minimal example:
```python
# example_simplest/instructor/cs101/report1.py
import unittest
from unitgrade2 import Report, evaluate_report_student
from unitgrade import Report, evaluate_report_student
import cs101
from cs101.homework1 import reverse_list, add
......@@ -100,10 +101,11 @@ if __name__ == "__main__":
### Deployment
The above is all you need if you simply want to use the framework as a self-check: Students can run the code and see how well they did.
In order to begin using the framework for evaluation we need to create a bit more structure. We do that by deploying the report class as follows:
```python
# example_simplest/instructor/cs101/deploy.py
from cs101.report1 import Report1
from unitgrade_private2.hidden_create_files import setup_grade_file_report
from unitgrade_private.hidden_create_files import setup_grade_file_report
from snipper import snip_dir
a = 34 #!i
......@@ -267,17 +269,18 @@ Finally, notice how one of the tests has a return value. This will be automatica
To use `unitgrade` as part of automatic grading, it is recommended you check the students output locally and use hidden tests. Fortunately, this is very easy.
Let's start with the hidden tests. As usual we write a complete report script (`report3_complete.py`), but this time we use the `@hide`-decorator to mark tests as hidden:
```python
# example_docker/instructor/cs103/report3_complete.py
from unitgrade2 import UTestCase, Report, hide
from unitgrade2 import evaluate_report_student
from unitgrade import UTestCase, Report, hide
from unitgrade import evaluate_report_student
import cs103
class AutomaticPass(UTestCase):
def test_automatic_pass(self):
self.assertEqual(2, 2) # For simplicity, this test will always pass
@hide # The @hide-decorator tells unitgrade to hide the test for students.
@hide # The @hide-decorator tells unitgrade_v1 to hide the test for students.
def test_hidden_fail(self):
self.assertEqual(2, 3) # For simplicity, this test will always fail.
......@@ -302,10 +305,11 @@ if __name__ == "__main__":
snip_dir("./", student_directory, exclude=['__pycache__', '*.token', 'deploy.py', 'report3_complete*.py', '.*'])
```
Just to check, let's have a quick look at the students report script `report3.py`:
```python
# example_docker/instructor/cs103/report3.py
from unitgrade2 import UTestCase, Report, hide
from unitgrade2 import evaluate_report_student
from unitgrade import UTestCase, Report, hide
from unitgrade import evaluate_report_student
import cs103
class AutomaticPass(UTestCase):
......@@ -331,8 +335,8 @@ To build the Docker image simply run:
```python
# example_docker/instructor/cs103/deploy.py
# Step 3: Compile the Docker image (obviously you should only do this once).
Dockerfile = os.path.dirname(__file__) + "/../../../../docker_images/unitgrade-docker/Dockerfile"
os.system(f"cd {os.path.dirname(Dockerfile)} && docker build --tag unitgrade-docker .")
Dockerfile = os.path.dirname(__file__) + "/../../../../docker_images/unitgrade_v1-docker/Dockerfile"
os.system(f"cd {os.path.dirname(Dockerfile)} && docker build --tag unitgrade_v1-docker .")
```
This takes about 3 minutes but only needs to be done once. If you are keeping track we have the following:
- A grade script with all tests, `report3_complete_grade.py`, which we build when the file was deployed
......
This is a secret string!
---------------------------------------------------------------------- ..ooO0Ooo.. ----------------------------------------------------------------------
6f774b1b490282254d8d4489a71f8e35a1bc0f9d110878a7d77afc1bb17566f03700db52c1f423c956f043b105b5563d63fed4bac21b27a3a71fd68c22796506 312
---------------------------------------------------------------------- ..ooO0Ooo.. ----------------------------------------------------------------------
./Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AD9AKVdAEABDn00k5WbOjrzTP2JdPDxjMFiaFt0mOyTdWdABrodOziNXUz3K0C9CUxHmo/LfzWwBEOzRYhaiNF/vwTFUTuakVPJWIUU2SgXrLAr4A5uErhe08wY2+Cdk7wK4jT+YZTEguA0NmK
WSAgf0hzUFOBhtI160f3LqDavoPRrGPjO8ZD6kiG1+TlemkMA3vHh/Ua0+7IpofmC3Q3SSHWJREqeKDhcsQAAAACL6sSmF6JWzwABwQH+AQAA3zv6Q7HEZ/sCAAAAAARZWg==.
\ No newline at end of file
import numpy as np
if __name__ == "__main__":
from unitgrade_private.hidden_gather_upload import save_token, load_token
token = "test.token"
s = "This is a secret string!"
d = {'Something': 'or another', 'k': np.ones((3,3))}
save_token(dictionary=d, plain_text=s, file_out=token)
d2, s2 = load_token(file_in=token)
from unitgrade2 import UTestCase, Report, hide
from unitgrade2 import evaluate_report_student
from unitgrade import UTestCase, Report, hide
from unitgrade import evaluate_report_student
import cs103
class AutomaticPass(UTestCase):
......
"""
Example student code. This file is automatically generated from the files in the instructor-directory
"""
from src.unitgrade2.unitgrade2 import UTestCase, Report
from src.unitgrade2 import evaluate_report_student
from src.unitgrade.unitgrade import UTestCase, Report
from src.unitgrade import evaluate_report_student
class Week1(UTestCase):
""" The first question for week 1. """
......@@ -24,6 +24,6 @@ class Report3(Report):
pack_imports = [cs103]
if __name__ == "__main__":
# from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
# from unitgrade_private.hidden_gather_upload import gather_upload_to_campusnet
# gather_upload_to_campusnet(Report3())
evaluate_report_student(Report3())
......@@ -17,7 +17,7 @@ Unitgrade is an automatic report and exam evaluation framework that enables inst
- CMU Autolab integration (Experimental)
# Using unitgrade
The examples can be found in the `/examples/` directory: https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/examples
The examples can be found in the `/examples` directory: https://gitlab.compute.dtu.dk/tuhe/unitgrade_private/-/tree/master/examples
## A simple example
Unitgrade makes the following assumptions:
......
from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
from unitgrade.unitgrade_helpers import evaluate_report_student
from unitgrade_v1.unitgrade import QuestionGroup, Report, QPrintItem
from unitgrade_v1.unitgrade_helpers import evaluate_report_student
from cs101courseware_example import homework1
class ListReversalQuestion(QuestionGroup):
......
This diff is collapsed.
from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem, Hidden
from unitgrade_v1.unitgrade import QuestionGroup, Report, QPrintItem, Hidden
class ListReversalQuestion(QuestionGroup):
title = "Reversal of list"
......@@ -37,8 +37,8 @@ class Report2(Report):
pack_imports = [] # Include this file in .token file
if __name__ == "__main__":
# from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade.unitgrade_helpers import evaluate_report_student
# from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade_v1.unitgrade_helpers import evaluate_report_student
# setup_grade_file_report(Report2, minify=True, bzip=True, obfuscate=True)
# evaluate_report_student(Report2())
evaluate_report_student(Report2())
......
import inspect, os
import shutil
import unitgrade as ug
import unitgrade_v1 as ug
from cs101courseware.cs101report1 import Report1
from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade.unitgrade_helpers import evaluate_report_student
from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade_v1.unitgrade_helpers import evaluate_report_student
if __name__ == "__main__":
setup_answers(Report1()) # hidden for students; re-computes the answers file.
......@@ -20,8 +20,8 @@ if __name__ == "__main__":
## Report 2
from cs101courseware.cs101report2 import Report2
# from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
# from unitgrade.unitgrade_helpers import evaluate_report_student
# from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
# from unitgrade_v1.unitgrade_helpers import evaluate_report_student
setup_grade_file_report(Report2, minify=True, bzip=True, obfuscate=True)
# evaluate_report_student(Report2())
......
import inspect, os
import shutil
import unitgrade as ug
import unitgrade_v1 as ug
from cs101courseware.cs101report1 import Report1
from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade.unitgrade_helpers import evaluate_report_student
from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade_v1.unitgrade_helpers import evaluate_report_student
if __name__ == "__main__":
# setup_answers(Report1()) # hidden for students; re-computes the answers file.
......@@ -20,8 +20,8 @@ if __name__ == "__main__":
## Report 2
from cs101courseware.cs101report2 import Report2
# from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
# from unitgrade.unitgrade_helpers import evaluate_report_student
# from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
# from unitgrade_v1.unitgrade_helpers import evaluate_report_student
setup_grade_file_report(Report2, minify=False, bzip=False, obfuscate=False)
# evaluate_report_student(Report2())
......
......@@ -3,9 +3,9 @@ from cs202courseware.ug2report1 import Report1
import pickle
import os
import glob
from unitgrade_private2.deployment import remove_hidden_methods
from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
from unitgrade_private2.hidden_create_files import setup_grade_file_report
from unitgrade_private.deployment import remove_hidden_methods
from unitgrade_private.hidden_gather_upload import gather_upload_to_campusnet
from unitgrade_private.hidden_create_files import setup_grade_file_report
import shutil
# def docker_run_token_file(Dockerfile_location, host_tmp_dir, student_token_file, ReportClass):
......@@ -104,7 +104,7 @@ if __name__ == '__main__':
# Dockerfile = os.path.dirname(__file__) + "/../"
Dockerfile = os.path.dirname(__file__) + "/../../2021/python-docker/Dockerfile"
from unitgrade_private2.docker_helpers import docker_run_token_file
from unitgrade_private.docker_helpers import docker_run_token_file
docker_run_token_file(Dockerfile_location=Dockerfile,
host_tmp_dir=os.path.dirname(Dockerfile)+"/tmp",
student_token_file=token_file,
......
# from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
# from unitgrade.unitgrade_helpers import evaluate_report_student
# from unitgrade_v1.unitgrade_v1 import QuestionGroup, Report, QPrintItem
# from unitgrade_v1.unitgrade_helpers import evaluate_report_student
from src.unitgrade2.unitgrade2 import UTestCase, cache
from src.unitgrade.unitgrade import UTestCase, cache
from unittest import TestCase
# from unitgrade2.unitgrade2 import cache
from src.unitgrade2.unitgrade2 import hide
# from unitgrade.unitgrade import cache
from src.unitgrade.unitgrade import hide
import random
from cs202courseware.homework1 import my_sum
......@@ -80,7 +80,7 @@ class ListQuestion(UTestCase):
""" ccc test_integers-short """
self.assertEqual(2,2)
from src.unitgrade2.unitgrade2 import Report
from src.unitgrade.unitgrade import Report
class Report1(Report):
title = "CS 202 Report 1"
......@@ -109,7 +109,7 @@ if __name__ == "__main__":
# print(inspect.getsourcelines(f) ) # How to get all hidden questions.
from src.unitgrade2 import evaluate_report_student
from src.unitgrade import evaluate_report_student
# cov = coverage.Coverage()
# cov.start()
......@@ -122,6 +122,6 @@ if __name__ == "__main__":
# cov.html_report()
z = 234
# deploy the report
# from unitgrade_private2.hidden_create_files import setup_grade_file_report
# from unitgrade_private.hidden_create_files import setup_grade_file_report
# setup_grade_file_report(Report1, minify=False, obfuscate=False, execute=False)
This diff is collapsed.
# from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
# from unitgrade.unitgrade_helpers import evaluate_report_student
# from unitgrade_v1.unitgrade_v1 import QuestionGroup, Report, QPrintItem
# from unitgrade_v1.unitgrade_helpers import evaluate_report_student
from src.unitgrade2.unitgrade2 import UTestCase, cache
# from unitgrade2.unitgrade2 import cache
from src.unitgrade2.unitgrade2 import methodsWithDecorator, hide
from src.unitgrade.unitgrade import UTestCase, cache
# from unitgrade.unitgrade import cache
from src.unitgrade.unitgrade import methodsWithDecorator, hide
......@@ -54,7 +54,7 @@ class ListQuestion(UTestCase):
""" ccc test_integers-short """
self.assertEqual(2,2)
from src.unitgrade2.unitgrade2 import Report
from src.unitgrade.unitgrade import Report
class Report1(Report):
title = "CS 202 Report 1"
......@@ -100,12 +100,12 @@ if __name__ == "__main__":
for f in ls:
print(inspect.getsourcelines(f) ) # How to get all hidden questions.
from src.unitgrade2 import evaluate_report_student
from src.unitgrade import evaluate_report_student
evaluate_report_student( Report1() )
# unittest.main(verbosity=2)
# deploy the report
from unitgrade_private2.hidden_create_files import setup_grade_file_report
from unitgrade_private.hidden_create_files import setup_grade_file_report
setup_grade_file_report(Report1, minify=False, obfuscate=False, execute=False)
from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem, Hidden
from unitgrade_v1.unitgrade import QuestionGroup, Report, QPrintItem, Hidden
from tutorial import shop
class AdditionQuestion(QuestionGroup):
......@@ -59,9 +59,9 @@ class FruitReport(Report):
pack_imports = [] # Include this file in .token file
if __name__ == "__main__":
# from unitgrade_private.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade.unitgrade_helpers import evaluate_report_student
from unitgrade_private.hidden_create_files import setup_grade_file_report
# from unitgrade_private_v1.hidden_create_files import setup_answers, setup_grade_file_report
from unitgrade_v1.unitgrade_helpers import evaluate_report_student
from unitgrade_private_v1.hidden_create_files import setup_grade_file_report
# setup_grade_file_report(FruitReport, minify=True, bzip=False, obfuscate=True)
# evaluate_report_student(Report2())
evaluate_report_student(FruitReport())
......
This diff is collapsed.
# example_simplest/instructor/cs101/deploy.py
from cs101.report1 import Report1
from unitgrade_private2.hidden_create_files import setup_grade_file_report
from unitgrade_private.hidden_create_files import setup_grade_file_report
from snipper import snip_dir
a = 34 #!i
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment