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

Updates to readme.md

parent cf305b49
No related branches found
No related tags found
No related merge requests found
"""
git add . && git commit -m "Options" && git push && pip install git+ssh://git@gitlab.compute.dtu.dk/tuhe/unitgrade.git --upgrade
"""
import numpy as np
import sys
import re
......@@ -13,13 +10,13 @@ import io
from unittest.runner import _WritelnDecorator
from typing import Any
import inspect
import textwrap
import colorama
from colorama import Fore
from functools import _make_key, RLock
from collections import namedtuple
import unittest
import time
import textwrap
_CacheInfo = namedtuple("CacheInfo", ["hits", "misses", "maxsize", "currsize"])
......@@ -96,20 +93,6 @@ class Capturing2(Capturing):
self.numbers = numbers
# @classmethod
# class OrderedClassMembers(type):
# def __prepare__(self, name, bases):
# assert False
# return collections.OrderedDict()
#
# def __new__(self, name, bases, classdict):
# ks = list(classdict.keys())
# for b in bases:
# ks += b.__ordered__
# classdict['__ordered__'] = [key for key in ks if key not in ('__module__', '__qualname__')]
# return type.__new__(self, name, bases, classdict)
class Report:
title = "report title"
version = None
......@@ -269,17 +252,9 @@ class ActiveProgress():
def dprint(first, last, nL, extra = "", file=None, dotsym='.', color='white'):
if file == None:
file = sys.stdout
# ss = self.item_title_print
# state = "PASS" if success else "FAILED"
dot_parts = (dotsym * max(0, nL - len(last) - len(first)))
# if self.show_progress_bar or True:
print(first + dot_parts, end="", file=file)
# else:
# print(dot_parts, end="", file=self.cc.file)
last += extra
# if tsecs >= 0.5:
# state += " (" + str(tsecs) + " seconds)"
print(last, file=file)
......@@ -406,13 +381,12 @@ def get_hints(ss):
try:
ss = textwrap.dedent(ss)
ss = ss.replace('''"""''', "").strip()
hints = ["hints:", ]
hints = ["hints:", "hint:"]
j = np.argmax([ss.lower().find(h) for h in hints])
h = hints[j]
ss = ss[ss.find(h) + len(h) + 1:]
ss = ss[ss.lower().find(h) + len(h) + 1:]
ss = "\n".join([l for l in ss.split("\n") if not l.strip().startswith(":")])
ss = textwrap.dedent(ss)
ss = ss.strip()
ss = textwrap.dedent(ss).strip()
return ss
except Exception as e:
print("bad hints", ss, e)
......@@ -472,10 +446,8 @@ class UTestCase(unittest.TestCase):
s = f.read()
lines = s.splitlines()
garb = 'GARBAGE'
lines2 = snipper_main.censor_code(lines, keep=True)
assert len(lines) == len(lines2)
for l in data.contexts_by_lineno(file):
if lines2[l].strip() == garb:
if self.cache_id() not in self._report.covcache:
......@@ -635,7 +607,8 @@ class UTestCase(unittest.TestCase):
hint = get_hints(comments)
if hint != None:
hints.append(hint)
# hint = textwrap.dedent(hint)
hints.append((hint, file, l) )
gprint(f"> - {l}")
er = er[0]
......@@ -643,10 +616,16 @@ class UTestCase(unittest.TestCase):
if doc is not None:
hint = get_hints(er._testMethodDoc)
if hint is not None:
hints = [hint] + hints
hints = [(hint, None, self.cache_id()[1] )] + hints
if len(hints) > 0:
gprint("> Hints:")
gprint(textwrap.indent("\n".join(hints), "> "))
for hint, file, method in hints:
s = (f"'{method.strip()}'" if method is not None else "")
if method is not None and file is not None:
s += " in "
s += (file.strip() if file is not None else "")
gprint(">")
gprint("> Hints (from " + s + ")")
gprint(textwrap.indent(hint, "> "))
super()._feedErrorsToResult(result, errors)
......@@ -704,4 +683,4 @@ def methodsWithDecorator(cls, decorator):
if maybeDecorated.decorator == decorator:
print(maybeDecorated)
yield maybeDecorated
# 817
# 817, 705
\ No newline at end of file
......@@ -38,8 +38,11 @@ parser.add_argument('--unmute', action="store_true", help='Show result of prin
parser.add_argument('--passall', action="store_true", help='Automatically pass all tests. Useful when debugging.')
parser.add_argument('--noprogress', action="store_true", help='Disable progress bars.')
def evaluate_report_student(report, question=None, qitem=None, unmute=None, passall=None, ignore_missing_file=False, show_tol_err=False):
def evaluate_report_student(report, question=None, qitem=None, unmute=None, passall=None, ignore_missing_file=False, show_tol_err=False, show_privisional=True, noprogress=None):
args = parser.parse_args()
if noprogress is None:
noprogress = args.noprogress
if question is None and args.q is not None:
question = args.q
if "." in question:
......@@ -56,11 +59,12 @@ def evaluate_report_student(report, question=None, qitem=None, unmute=None, pass
passall = args.passall
results, table_data = evaluate_report(report, question=question, show_progress_bar=not unmute and not args.noprogress, qitem=qitem, verbose=False, passall=passall, show_expected=args.showexpected, show_computed=args.showcomputed,unmute=unmute,
results, table_data = evaluate_report(report, question=question, show_progress_bar=not unmute and not noprogress, qitem=qitem,
verbose=False, passall=passall, show_expected=args.showexpected, show_computed=args.showcomputed,unmute=unmute,
show_tol_err=show_tol_err)
if question is None:
if question is None and show_privisional:
print("Provisional evaluation")
tabulate(table_data)
table = table_data
......@@ -84,9 +88,9 @@ def upack(q):
h = np.asarray(h)
return h[:,0], h[:,1], h[:,2],
class UnitgradeTextRunner(unittest.TextTestRunner):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# class UnitgradeTextRunner(unittest.TextTestRunner):
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
class SequentialTestLoader(unittest.TestLoader):
def getTestCaseNames(self, testCaseClass):
......@@ -105,7 +109,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
show_tol_err=False,
big_header=True):
from src.unitgrade2.version import __version__
from unitgrade2.version import __version__
now = datetime.now()
if big_header:
ascii_banner = pyfiglet.figlet_format("UnitGrade", font="doom")
......@@ -135,7 +139,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
q.possible = 0
q.obtained = 0
q_ = {} # Gather score in this class.
from src.unitgrade2.unitgrade2 import UTextTestRunner
from unitgrade2.unitgrade2 import UTextTestRunner
UTextResult.q_title_print = q_title_print # Hacky
UTextResult.show_progress_bar = show_progress_bar # Hacky.
UTextResult.number = n
......@@ -143,13 +147,21 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
res = UTextTestRunner(verbosity=2, resultclass=UTextResult).run(suite)
for s in res.successes:
q_[s._testMethodName] = ("pass",None)
for (s,msg) in res.failures:
q_[s._testMethodName] = ("fail", msg)
for (s,msg) in res.errors:
q_[s._testMethodName] = ("error", msg)
possible = res.testsRun
obtained = len(res.successes)
assert len(res.successes) + len(res.errors) + len(res.failures) == res.testsRun
obtained = int(w * obtained * 1.0 / possible ) if possible > 0 else 0
score[n] = {'w': w, 'possible': w, 'obtained': obtained, 'items': q_, 'title': qtitle}
score[n] = {'w': w, 'possible': w, 'obtained': obtained, 'items': q_, 'title': qtitle, 'name': q.__name__}
q.obtained = obtained
q.possible = possible
......@@ -172,7 +184,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
seconds = dt - minutes*60
plrl = lambda i, s: str(i) + " " + s + ("s" if i != 1 else "")
from src.unitgrade2.unitgrade2 import dprint
from unitgrade2.unitgrade2 import dprint
dprint(first = "Total points at "+ dt_string + " (" + plrl(minutes, "minute") + ", "+ plrl(seconds, "second") +")",
last=""+str(report.obtained)+"/"+str(report.possible), nL = report.nL)
......
__version__ = "0.0.3"
\ No newline at end of file
__version__ = "0.1.1"
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment