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

Updates for presentation

parent d1e994c8
No related branches found
No related tags found
No related merge requests found
wandb_version: 1
_wandb:
desc: null
value:
cli_version: 0.13.3
is_jupyter_run: false
is_kaggle_kernel: false
python_version: 3.10.6
start_time: 1666115618.482377
t:
1:
- 55
3:
- 14
- 23
4: 3.10.6
5: 0.13.3
8:
- 5
...@@ -178,7 +178,8 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa ...@@ -178,7 +178,8 @@ def evaluate_report(report, question=None, qitem=None, passall=False, verbose=Fa
else: else:
raise Exception("Status not known.") raise Exception("Status not known.")
nice_title = s.title # s can be an '_ErrorHolder' object, which has no title.
nice_title = s.title if hasattr(s, 'title') else 's has no title; unitgrade/evaluate.py line 181'
detail = {**detail, **msg, 'nice_title': nice_title} #['message'] = msg detail = {**detail, **msg, 'nice_title': nice_title} #['message'] = msg
details[key] = detail details[key] = detail
......
...@@ -294,9 +294,30 @@ def get_hints(ss): ...@@ -294,9 +294,30 @@ def get_hints(ss):
except Exception as e: except Exception as e:
print("bad hints", ss, e) print("bad hints", ss, e)
from threading import Thread
class WandUpload(Thread):
# - What do you want to know? What might be of help?
# - What errors occur
# - How many times each test is run, and how many times it fails
# - What kind of errors occur in the tests
# - timestamps
# For each test, track the number of runs and the different errors
# For each test, track which errors many have in common.
def run(self):
pass
pass
class UTestCase(unittest.TestCase): class UTestCase(unittest.TestCase):
# a = 234 # a = 234
api = "053eccb9234af62a683b5733d8c00138ed601a43" # secret key
# How should it work?
# Sync errors online.
_outcome = None # A dictionary which stores the user-computed outcomes of all the tests. This differs from the cache. _outcome = None # A dictionary which stores the user-computed outcomes of all the tests. This differs from the cache.
_cache = None # Read-only cache. Ensures method always produce same result. _cache = None # Read-only cache. Ensures method always produce same result.
_cache2 = None # User-written cache. _cache2 = None # User-written cache.
...@@ -333,19 +354,16 @@ class UTestCase(unittest.TestCase): ...@@ -333,19 +354,16 @@ class UTestCase(unittest.TestCase):
from unitgrade.artifacts import StdCapturing from unitgrade.artifacts import StdCapturing
from unitgrade.utils import DKPupDB from unitgrade.utils import DKPupDB
db = DKPupDB(self._artifact_file()) db = DKPupDB(self._artifact_file(), register_ephemeral=True)
db.set("state", "running") db.set("state", "running")
db.set('run_id', np.random.randint(1000*1000)) db.set('run_id', np.random.randint(1000*1000))
db.set('coverage_files_changed', None) db.set('coverage_files_changed', None)
_stdout = sys.stdout _stdout = sys.stdout
_stderr = sys.stderr _stderr = sys.stderr
std_capture = StdCapturing(stdout=sys.stdout, stderr=sys.stderr, db=db, mute=False) std_capture = StdCapturing(stdout=sys.stdout, stderr=sys.stderr, db=db, mute=False)
# stderr_capture = StdCapturing(sys.stderr, db=db)
# std_err_capture = StdCapturing(sys.stderr, "stderr", db=db)
state_ = None state_ = None
try: try:
# Run this unittest and record all of the output. # Run this unittest and record all of the output.
...@@ -354,9 +372,20 @@ class UTestCase(unittest.TestCase): ...@@ -354,9 +372,20 @@ class UTestCase(unittest.TestCase):
sys.stderr = std_capture.dummy_stderr sys.stderr = std_capture.dummy_stderr
sys.stdout = std_capture.dummy_stdout sys.stdout = std_capture.dummy_stdout
result_ = TestCase.run(self, result) # db.get('stdout')
# db.get('stderr')
# db.get("history")
result_ = TestCase.run(self, result)
from werkzeug.debug.tbtools import DebugTraceback, _process_traceback from werkzeug.debug.tbtools import DebugTraceback, _process_traceback
# What could be nice to upload?
# When the files are edited?
# When tests are run?
# how to register it? (report, question, user...)
#
# print(result_._excinfo[0]) # print(result_._excinfo[0])
actual_errors = [] actual_errors = []
for test, err in self._error_fed_during_run: for test, err in self._error_fed_during_run:
...@@ -364,17 +393,16 @@ class UTestCase(unittest.TestCase): ...@@ -364,17 +393,16 @@ class UTestCase(unittest.TestCase):
continue continue
else: else:
import traceback import traceback
# traceback.print_tb(err[2])
actual_errors.append(err) actual_errors.append(err)
if len(actual_errors) > 0: if len(actual_errors) > 0:
ex, exi, tb = actual_errors[0] ex, exi, tb = actual_errors[0]
exi.__traceback__ = tb exi.__traceback__ = tb
dbt = DebugTraceback(exi) dbt = DebugTraceback(exi)
sys.stderr.write(dbt.render_traceback_text()) sys.stderr.write(dbt.render_traceback_text())
html = dbt.render_traceback_html(include_title="hello world") html = dbt.render_traceback_html(include_title="hello world")
db.set('wz_stacktrace', html) db.set('wz_stacktrace', html)
# db.set('state', 'fail')
state_ = "fail" state_ = "fail"
else: else:
state_ = "pass" state_ = "pass"
...@@ -400,11 +428,12 @@ class UTestCase(unittest.TestCase): ...@@ -400,11 +428,12 @@ class UTestCase(unittest.TestCase):
self.cov.start() self.cov.start()
self.setUp() self.setUp()
def _callTearDown(self): def _callTearDown(self):
self.tearDown() self.tearDown()
# print("Teardown.") # print("TEaring down.")
if self._with_coverage: if self._with_coverage:
# print("with cov") # print("TEaring down with coverage")
from pathlib import Path from pathlib import Path
from snipper import snipper_main from snipper import snipper_main
try: try:
...@@ -415,17 +444,16 @@ class UTestCase(unittest.TestCase): ...@@ -415,17 +444,16 @@ class UTestCase(unittest.TestCase):
data = self.cov.get_data() data = self.cov.get_data()
base, _, _ = self._report._import_base_relative() base, _, _ = self._report._import_base_relative()
for file in data.measured_files(): for file in data.measured_files():
print(file)
file = os.path.normpath(file) file = os.path.normpath(file)
root = Path(base) root = Path(base)
child = Path(file) child = Path(file)
if root in child.parents: if root in child.parents:
# print("Reading file", child)
with open(child, 'r') as f: with open(child, 'r') as f:
s = f.read() s = f.read()
lines = s.splitlines() lines = s.splitlines()
garb = 'GARBAGE' garb = 'GARBAGE'
lines2 = snipper_main.censor_code(lines, keep=True) lines2 = snipper_main.censor_code(lines, keep=True)
# print("\n".join(lines2))
if len(lines) != len(lines2): if len(lines) != len(lines2):
for k in range(len(lines)): for k in range(len(lines)):
print(k, ">", lines[k], "::::::::", lines2[k]) print(k, ">", lines[k], "::::::::", lines2[k])
...@@ -436,9 +464,11 @@ class UTestCase(unittest.TestCase): ...@@ -436,9 +464,11 @@ class UTestCase(unittest.TestCase):
assert len(lines) == len(lines2) assert len(lines) == len(lines2)
for ll in data.contexts_by_lineno(file): for ll in data.contexts_by_lineno(file):
l = ll-1 l = ll-1
print(l, lines2[l])
if l < len(lines2) and lines2[l].strip() == garb: if l < len(lines2) and lines2[l].strip() == garb:
# print("Got a hit at l", l) print("Got one.")
rel = os.path.relpath(child, root) rel = os.path.relpath(child, root)
cc = self._covcache cc = self._covcache
j = 0 j = 0
...@@ -452,7 +482,8 @@ class UTestCase(unittest.TestCase): ...@@ -452,7 +482,8 @@ class UTestCase(unittest.TestCase):
if rel not in cc: if rel not in cc:
cc[rel] = {} cc[rel] = {}
cc[rel][fun] = (l, "\n".join(comments)) cc[rel][fun] = (l, "\n".join(comments))
# print("found", rel, fun) print("found", rel, fun)
# print(file, ll)
self._cache_put((self.cache_id(), 'coverage'), self._covcache) self._cache_put((self.cache_id(), 'coverage'), self._covcache)
def shortDescriptionStandard(self): def shortDescriptionStandard(self):
...@@ -660,7 +691,7 @@ class UTestCase(unittest.TestCase): ...@@ -660,7 +691,7 @@ class UTestCase(unittest.TestCase):
return file return file
def _artifact_file(self): def _artifact_file(self):
""" File for the artifacts DB (thread safe). This file is optinal. Note that it is a pupdb database file. """ File for the artifacts DB (thread safe). This file is optinal.
Note the file is shared between all sub-questions. """ Note the file is shared between all sub-questions. """
return os.path.join(os.path.dirname(self.__class__._cache_file()), '-'.join(self.cache_id()) + ".json") return os.path.join(os.path.dirname(self.__class__._cache_file()), '-'.join(self.cache_id()) + ".json")
......
...@@ -305,13 +305,14 @@ def load_token(file_in): ...@@ -305,13 +305,14 @@ def load_token(file_in):
## Key/value store related. ## Key/value store related.
class DKPupDB: class DKPupDB:
""" This key/value store store artifacts (associated with a specific question) in a dictionary. """ """ This key/value store store artifacts (associated with a specific question) in a dictionary. """
def __init__(self, artifact_file, use_pupdb=False): def __init__(self, artifact_file, use_pupdb=False, register_ephemeral=False):
# Make a double-headed disk cache thingy. # Make a double-headed disk cache thingy.
self.dk = Cache(os.path.dirname(artifact_file)) # Start in this directory. self.dk = Cache(os.path.dirname(artifact_file)) # Start in this directory.
self.name_ = os.path.basename(artifact_file[:-5]) self.name_ = os.path.basename(artifact_file[:-5])
if self.name_ not in self.dk: if self.name_ not in self.dk:
self.dk[self.name_] = dict() self.dk[self.name_] = dict()
self.use_pupdb = use_pupdb self.use_pupdb = use_pupdb
self.register_ephemeral = register_ephemeral
if self.use_pupdb: if self.use_pupdb:
from pupdb.core import PupDB from pupdb.core import PupDB
self.db_ = PupDB(artifact_file) self.db_ = PupDB(artifact_file)
...@@ -323,6 +324,7 @@ class DKPupDB: ...@@ -323,6 +324,7 @@ class DKPupDB:
d = self.dk[self.name_] d = self.dk[self.name_]
d[key] = value d[key] = value
self.dk[self.name_] = d self.dk[self.name_] = d
self.dk.set(key=np.random.randint(0, high=1e8), value=(key,value), tag="ephemeral")
self.dk[self.name_ + "-updated"] = True self.dk[self.name_ + "-updated"] = True
def __getitem__(self, item): def __getitem__(self, item):
......
__version__ = "0.1.30.0" __version__ = "0.1.30.2"
\ No newline at end of file \ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment