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

updates

parent af168e16
No related branches found
No related tags found
No related merge requests found
__version__ = "0.1.1" __version__ = "0.1.1"
import os import os
import compress_pickle # DONT't import stuff here since install script requires __version__
def cache_write(object, file_name, verbose=True): def cache_write(object, file_name, verbose=True):
import compress_pickle
dn = os.path.dirname(file_name) dn = os.path.dirname(file_name)
if not os.path.exists(dn): if not os.path.exists(dn):
os.mkdir(dn) os.mkdir(dn)
...@@ -19,6 +19,7 @@ def cache_exists(file_name): ...@@ -19,6 +19,7 @@ def cache_exists(file_name):
def cache_read(file_name): def cache_read(file_name):
import compress_pickle # Import here because if you import in top the __version__ tag will fail.
# file_name = cn_(file_name) if cache_prefix else file_name # file_name = cn_(file_name) if cache_prefix else file_name
if os.path.exists(file_name): if os.path.exists(file_name):
with open(file_name, 'rb') as f: with open(file_name, 'rb') as f:
......
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -114,7 +114,7 @@ class QItem(unittest.TestCase): ...@@ -114,7 +114,7 @@ class QItem(unittest.TestCase):
def test(self, computed, expected): def test(self, computed, expected):
self.testfun(computed, expected) self.testfun(computed, expected)
def get_points(self, verbose=False, show_expected=False, show_computed=False,unmute=False, passall=False, **kwargs): def get_points(self, verbose=False, show_expected=False, show_computed=False,unmute=False, passall=False, silent=False, **kwargs):
possible = 1 possible = 1
computed = None computed = None
def show_computed_(computed): def show_computed_(computed):
...@@ -132,6 +132,7 @@ class QItem(unittest.TestCase): ...@@ -132,6 +132,7 @@ class QItem(unittest.TestCase):
computed = self.compute_answer(unmute=unmute) computed = self.compute_answer(unmute=unmute)
except Exception as e: except Exception as e:
if not passall: if not passall:
if not silent:
print("\n=================================================================================") print("\n=================================================================================")
print(f"When trying to run test class '{self.name}' your code threw an error:", e) print(f"When trying to run test class '{self.name}' your code threw an error:", e)
show_expected_(correct) show_expected_(correct)
...@@ -153,6 +154,7 @@ class QItem(unittest.TestCase): ...@@ -153,6 +154,7 @@ class QItem(unittest.TestCase):
if not passall: if not passall:
self.test(computed=computed, expected=correct) self.test(computed=computed, expected=correct)
except Exception as e: except Exception as e:
if not silent:
print("\n=================================================================================") print("\n=================================================================================")
print(f"Test output from test class '{self.name}' does not match expected result. Test error:") print(f"Test output from test class '{self.name}' does not match expected result. Test error:")
print(e) print(e)
......
...@@ -87,7 +87,8 @@ def upack(q): ...@@ -87,7 +87,8 @@ def upack(q):
# ws, possible, obtained = (np.asarray(x).squeeze() for x in zip([(i['w'], i['possible'], i['obtained']) for i in q.values()])) # ws, possible, obtained = (np.asarray(x).squeeze() for x in zip([(i['w'], i['possible'], i['obtained']) for i in q.values()]))
# return ws, possible, obtained # return ws, possible, obtained
def evaluate_report(report, question=None, qitem=None, passall=False, verbose=False, show_expected=False, show_computed=False,unmute=False, show_help_flag=True): def evaluate_report(report, question=None, qitem=None, passall=False, verbose=False, show_expected=False, show_computed=False,unmute=False, show_help_flag=True,
silent=False):
now = datetime.now() now = datetime.now()
ascii_banner = pyfiglet.figlet_format("UnitGrade", font="doom") ascii_banner = pyfiglet.figlet_format("UnitGrade", font="doom")
b = "\n".join( [l for l in ascii_banner.splitlines() if len(l.strip()) > 0] ) b = "\n".join( [l for l in ascii_banner.splitlines() if len(l.strip()) > 0] )
...@@ -129,7 +130,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -129,7 +130,7 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
sys.stdout.flush() sys.stdout.flush()
import time import time
start = time.time() start = time.time()
(current, possible) = item.get_points(show_expected=show_expected, show_computed=show_computed,unmute=unmute, passall=passall) (current, possible) = item.get_points(show_expected=show_expected, show_computed=show_computed,unmute=unmute, passall=passall, silent=silent)
q_[j] = {'w': iw, 'possible': possible, 'obtained': current, 'hidden': hidden, 'computed': str(item._computed_answer), 'title': item.title} q_[j] = {'w': iw, 'possible': possible, 'obtained': current, 'hidden': hidden, 'computed': str(item._computed_answer), 'title': item.title}
tsecs = np.round(time.time()-start, 2) tsecs = np.round(time.time()-start, 2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment