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

Updates

parent dadd26b9
No related branches found
No related tags found
No related merge requests found
Showing
with 802 additions and 34 deletions
LICENSE 0 → 100644
Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
\ No newline at end of file
......@@ -55,41 +55,48 @@ if __name__ == "__main__":
```
### The test:
The test consists of individual problems and a report-class. The tests themselves are just regular Unittest (we will see a slightly smarter idea in a moment). For instance:
```python
from homework1 import reverse_list, add
from looping import reverse_list, add
import unittest
class Week1(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2,2), 4)
self.assertEqual(add(2, 2), 4)
self.assertEqual(add(-100, 5), -95)
def test_reverse(self):
self.assertEqual(reverse_list([1,2,3]), [3,2,1])
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
from unitgrade2.unitgrade2 import Report
from unitgrade2.unitgrade_helpers2 import evaluate_report_student
from homework1 import reverse_list, add
from src.unitgrade2.unitgrade2 import Report
from src.unitgrade2 import evaluate_report_student
from looping import reverse_list, add
import unittest
class Week1(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2,2), 4)
self.assertEqual(add(2, 2), 4)
self.assertEqual(add(-100, 5), -95)
def test_reverse(self):
self.assertEqual(reverse_list([1,2,3]), [3,2,1])
self.assertEqual(reverse_list([1, 2, 3]), [3, 2, 1])
import cs101
class Report1(Report):
title = "CS 101 Report 1"
questions = [(Week1, 10)] # Include a single question for 10 credits.
pack_imports = [cs101]
if __name__ == "__main__":
# Uncomment to simply run everything as a unittest:
# unittest.main(verbosity=2)
......@@ -109,7 +116,7 @@ if __name__ == "__main__":
setup_grade_file_report(Report1, minify=False, obfuscate=False, execute=False)
# Deploy the files using snipper: https://gitlab.compute.dtu.dk/tuhe/snipper
snip_dir.snip_dir(source_dir="../cs101", dest_dir="../../students/cs101", clean_destination_dir=True, exclude=['__pycache__', '*.token', 'deploy.py'])
snip_dir.snip_dir(source_dir="../programs", dest_dir="../../students/programs", clean_destination_dir=True, exclude=['__pycache__', '*.token', 'deploy.py'])
```
- The first line creates the `report1_grade.py` script and any additional data files needed by the tests (none in this case)
......@@ -193,15 +200,18 @@ also that the students implementations didn't just detect what input was being u
return the correct answer. To do that you need hidden tests and external validation.
Our new testclass looks like this:
```python
from unitgrade2.unitgrade2 import UTestCase, Report, hide
from unitgrade2.unitgrade_helpers2 import evaluate_report_student
from src.unitgrade2.unitgrade2 import UTestCase, Report, hide
from src.unitgrade2 import evaluate_report_student
class Week1(UTestCase):
""" The first question for week 1. """
def test_add(self):
from cs103.homework1 import add
self.assertEqualC(add(2,2))
self.assertEqualC(add(2, 2))
self.assertEqualC(add(-100, 5))
@hide
......@@ -209,14 +219,18 @@ class Week1(UTestCase):
# This is a hidden test. The @hide-decorator will allow unitgrade to remove the test.
# See the output in the student directory for more information.
from cs103.homework1 import add
self.assertEqualC(add(2,2))
self.assertEqualC(add(2, 2))
import cs103
class Report3(Report):
title = "CS 101 Report 3"
questions = [(Week1, 20)] # Include a single question for 10 credits.
pack_imports = [cs103]
if __name__ == "__main__":
evaluate_report_student(Report3())
```
......
File deleted
build.md 0 → 100644
# Unitgrade build info
See https://packaging.python.org/tutorials/packaging-projects/
- Build the distribution package using:
```
py -m pip install --upgrade build && py -m build
```
- Upload to test repo
```
py -m pip install --upgrade twine && py -m twine upload --repository testpypi dist/*
```
### build and upload (to actual pypi; remember the .pypi token. you can find it in personal dtu repo)
```
rm -f dists/* && py -m build && twine upload dist/*
```
from prompt_toolkit.application import Application
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.bindings.focus import focus_next, focus_previous
from prompt_toolkit.layout import Dimension, HSplit, Layout, ScrollablePane
from prompt_toolkit.widgets import Frame, Label, TextArea
print("hello")
z = 234
def main():
# Create a big layout of many text areas, then wrap them in a `ScrollablePane`.
root_container = Frame(
ScrollablePane(
HSplit(
[
Frame(TextArea(text=f"label-{i}"), width=Dimension())
for i in range(20)
]
)
)
# ScrollablePane(HSplit([TextArea(text=f"label-{i}") for i in range(20)]))
)
layout = Layout(container=root_container)
# Key bindings.
kb = KeyBindings()
@kb.add("c-c")
def exit(event) -> None:
get_app().exit()
kb.add("down")(focus_next)
kb.add("up")(focus_previous)
# Create and run application.
application = Application(layout=layout, key_bindings=kb, full_screen=True)
application.run()
if __name__ == "__main__":
main()
\ No newline at end of file
# from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
# from unitgrade.unitgrade_helpers import evaluate_report_student
from cs202courseware import homework1
import unittest
from unitgrade2.unitgrade2 import wrapper, UTestCase, cache
from src.unitgrade2.unitgrade2 import UTestCase, cache
from unittest import TestCase
# from unitgrade2.unitgrade2 import cache
from unitgrade2.unitgrade2 import methodsWithDecorator, hide
from src.unitgrade2.unitgrade2 import hide
import random
from cs202courseware.homework1 import reverse_list, my_sum
from cs202courseware.homework1 import my_sum
class TestPartial(TestCase):
def test_a(self):
......@@ -83,7 +80,7 @@ class ListQuestion(UTestCase):
""" ccc test_integers-short """
self.assertEqual(2,2)
from unitgrade2.unitgrade2 import Report
from src.unitgrade2.unitgrade2 import Report
class Report1(Report):
title = "CS 202 Report 1"
......@@ -97,7 +94,6 @@ class Report1(Report):
pack_imports = [cs202courseware] # Include this file in .token file
a = 234
import coverage
if __name__ == "__main__":
"""
......@@ -113,7 +109,7 @@ if __name__ == "__main__":
# print(inspect.getsourcelines(f) ) # How to get all hidden questions.
from unitgrade2.unitgrade_helpers2 import evaluate_report_student
from src.unitgrade2 import evaluate_report_student
# cov = coverage.Coverage()
# cov.start()
......
# from unitgrade.unitgrade import QuestionGroup, Report, QPrintItem
# from unitgrade.unitgrade_helpers import evaluate_report_student
from cs202courseware import homework1
import unittest
from unitgrade2.unitgrade2 import wrapper, UTestCase, cache
from src.unitgrade2.unitgrade2 import UTestCase, cache
# from unitgrade2.unitgrade2 import cache
from unitgrade2.unitgrade2 import methodsWithDecorator, hide
from src.unitgrade2.unitgrade2 import methodsWithDecorator, hide
import random
from cs101courseware_example.homework1 import reverse_list, my_sum
from cs101courseware_example.homework1 import my_sum
class GeneratorQuestion(UTestCase):
def genTest(self, n):
......@@ -57,7 +54,7 @@ class ListQuestion(UTestCase):
""" ccc test_integers-short """
self.assertEqual(2,2)
from unitgrade2.unitgrade2 import Report
from src.unitgrade2.unitgrade2 import Report
class Report1(Report):
title = "CS 202 Report 1"
......@@ -103,7 +100,7 @@ if __name__ == "__main__":
for f in ls:
print(inspect.getsourcelines(f) ) # How to get all hidden questions.
from unitgrade2.unitgrade_helpers2 import evaluate_report_student
from src.unitgrade2 import evaluate_report_student
evaluate_report_student( Report1() )
......
File added
File added
......@@ -4,3 +4,4 @@ jinja2
tabulate
compress_pickle
pyfiglet
colorama
\ No newline at end of file
......@@ -5,7 +5,7 @@ FROM python:3.8-slim-buster
RUN apt-get -y update
RUN apt-get -y install git
WORKDIR /app
WORKDIR /home
# Remember to include requirements.
COPY requirements.txt requirements.txt
......@@ -16,6 +16,6 @@ RUN pip3 install -r requirements.txt
COPY . .
ADD . /app
ADD . /home
# CMD [ "python3", "app.py"]
File added
File added
"""
Example student code. This file is automatically generated from the files in the instructor-directory
"""
from unitgrade2.unitgrade2 import UTestCase, Report, hide
from unitgrade2.unitgrade_helpers2 import evaluate_report_student
from src.unitgrade2.unitgrade2 import UTestCase, Report
from src.unitgrade2 import evaluate_report_student
class Week1(UTestCase):
""" The first question for week 1. """
......@@ -24,4 +24,6 @@ class Report3(Report):
pack_imports = [cs103]
if __name__ == "__main__":
# from unitgrade_private2.hidden_gather_upload import gather_upload_to_campusnet
# gather_upload_to_campusnet(Report3())
evaluate_report_student(Report3())
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment