From 23c5a6857d62a4f959c226b8f41b0f2a2684d793 Mon Sep 17 00:00:00 2001 From: Tue Herlau <tuhe@dtu.dk> Date: Mon, 13 Feb 2023 13:20:16 +0100 Subject: [PATCH] updates --- requirements.txt | 2 +- src/unitgrade.egg-info/PKG-INFO | 2 +- src/unitgrade.egg-info/SOURCES.txt | 8 +++++ src/unitgrade/dashboard/__init__.py | 1 + src/unitgrade/dashboard/static/unitgrade.js | 3 +- src/unitgrade/framework.py | 36 ++++++++++++++++----- src/unitgrade/utils.py | 8 +++-- src/unitgrade/version.py | 4 ++- 8 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 src/unitgrade/dashboard/__init__.py diff --git a/requirements.txt b/requirements.txt index 122324e..f7f816e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,4 +16,4 @@ diskcache # dashboard watchdog # dashboard flask_socketio # dashboard flask # dashboard -Werkzeug # dashboard +Werkzeug>=2.2.0 # dashboard diff --git a/src/unitgrade.egg-info/PKG-INFO b/src/unitgrade.egg-info/PKG-INFO index 6555d1d..601a473 100644 --- a/src/unitgrade.egg-info/PKG-INFO +++ b/src/unitgrade.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: unitgrade -Version: 0.1.30.1 +Version: 0.1.30.5 Summary: A student homework/exam evaluation framework build on pythons unittest framework. Home-page: https://lab.compute.dtu.dk/tuhe/unitgrade Author: Tue Herlau diff --git a/src/unitgrade.egg-info/SOURCES.txt b/src/unitgrade.egg-info/SOURCES.txt index 93c7366..3139727 100644 --- a/src/unitgrade.egg-info/SOURCES.txt +++ b/src/unitgrade.egg-info/SOURCES.txt @@ -16,6 +16,14 @@ src/unitgrade.egg-info/dependency_links.txt src/unitgrade.egg-info/entry_points.txt src/unitgrade.egg-info/requires.txt src/unitgrade.egg-info/top_level.txt +src/unitgrade/dashboard/__init__.py +src/unitgrade/dashboard/app.py +src/unitgrade/dashboard/app_helpers.py +src/unitgrade/dashboard/dashboard_cli.py +src/unitgrade/dashboard/dbwatcher.py +src/unitgrade/dashboard/ephermaltransfer.py +src/unitgrade/dashboard/file_change_handler.py +src/unitgrade/dashboard/watcher.py src/unitgrade/dashboard/static/favicon.ico src/unitgrade/dashboard/static/sidebars.css src/unitgrade/dashboard/static/sidebars.js diff --git a/src/unitgrade/dashboard/__init__.py b/src/unitgrade/dashboard/__init__.py new file mode 100644 index 0000000..e4af382 --- /dev/null +++ b/src/unitgrade/dashboard/__init__.py @@ -0,0 +1 @@ +# I think this is needed for setup.py \ No newline at end of file diff --git a/src/unitgrade/dashboard/static/unitgrade.js b/src/unitgrade/dashboard/static/unitgrade.js index 87c4496..90770b7 100644 --- a/src/unitgrade/dashboard/static/unitgrade.js +++ b/src/unitgrade/dashboard/static/unitgrade.js @@ -37,7 +37,8 @@ td_classes = {'fail': 'table-danger', 'pass': 'table-success', 'running': 'table-warning', } -$("#token-blurb").hide(); + + $("#token-blurb").hide(); socket.on("token_update", function(data){ console.log('> Updating token from remote...'); // console.log(data); diff --git a/src/unitgrade/framework.py b/src/unitgrade/framework.py index 125ed19..864d315 100644 --- a/src/unitgrade/framework.py +++ b/src/unitgrade/framework.py @@ -353,6 +353,7 @@ class UTestCase(unittest.TestCase): return super().run(result) from unitgrade.artifacts import StdCapturing from unitgrade.utils import DKPupDB + self._error_fed_during_run = [] # Initialize this to be empty. db = DKPupDB(self._artifact_file(), register_ephemeral=True) db.set("state", "running") @@ -530,6 +531,8 @@ class UTestCase(unittest.TestCase): def __init__(self, *args, skip_remote_check=False, **kwargs): super().__init__(*args, **kwargs) + # print(f"INIT CALED IN {self}") + self._load_cache() self._assert_cache_index = 0 # Perhaps do a sanity check here to see if the cache is up to date? To do that, we must make sure the @@ -539,15 +542,19 @@ class UTestCase(unittest.TestCase): return import importlib, inspect found_reports = [] - # print("But do I have report", self._report) - # print("I think I am module", self.__module__) - # print("Importlib says", importlib.import_module(self.__module__)) + + good_module_name = self.__module__ + try: + importlib.import_module(good_module_name) + except Exception as e: + good_module_name = os.path.basename(good_module_name)[:-3] + # This will delegate you to the wrong main clsas when running in grade mode. - for name, cls in inspect.getmembers(importlib.import_module(self.__module__), inspect.isclass): - # print("checking", cls) + # for name, cls in inspect.getmembers(importlib.import_module(self.__module__), inspect.isclass): + for name, cls in inspect.getmembers(importlib.import_module(good_module_name), inspect.isclass): if issubclass(cls, Report): for q,_ in cls.questions: - if q == self.__class__: + if self.__class__.__name__ == q.__name__: found_reports.append(cls) if len(found_reports) == 0: pass # This case occurs when the report _grade script is being run. @@ -681,7 +688,14 @@ class UTestCase(unittest.TestCase): @classmethod def _cache_file(cls): - return os.path.dirname(inspect.getabsfile(cls)) + "/unitgrade_data/" + cls.__name__ + ".pkl" + # This seems required because python can throw an exception that cls is a 'built-in'(??) when it + # isn't. I don't know what causes it, but it may be the test system. + try: + module_name = inspect.getabsfile(cls) + except Exception as e: + module_name = cls.__module__ + return os.path.dirname(module_name) + "/unitgrade_data/" + cls.__name__ + ".pkl" + # return os.path.dirname(inspect.getabsfile(cls)) + "/unitgrade_data/" + cls.__name__ + ".pkl" @classmethod def _artifact_file_for_setUpClass(cls): @@ -710,6 +724,8 @@ class UTestCase(unittest.TestCase): if self._cache is not None: # Cache already loaded. We will not load it twice. return # raise Exception("Loaded cache which was already set. What is going on?!") + # str(self.__class__) + cfile = self.__class__._cache_file() if os.path.exists(cfile): try: @@ -843,7 +859,11 @@ class NotebookTestCase(UTestCase): @classmethod def setUpClass(cls) -> None: with Capturing(): - cls._nb = importnb.Notebook.load(cls.notebook) + # print(__file__) + f = cls._cache_file() + # print(f) + file = os.path.dirname(os.path.dirname(f)) + "/" + cls.notebook + cls._nb = importnb.Notebook.load_file(file) @property def nb(self): diff --git a/src/unitgrade/utils.py b/src/unitgrade/utils.py index bc0650e..03b0f58 100644 --- a/src/unitgrade/utils.py +++ b/src/unitgrade/utils.py @@ -53,6 +53,8 @@ class Capturing(list): def __enter__(self, capture_errors=True): # don't put arguments here. self._stdout = sys.stdout if self._stdout == None else self._stdout self._stringio = StringIO() + self._stringio_err = StringIO() + if self.unmute: sys.stdout = Logger(self._stringio) else: @@ -60,7 +62,9 @@ class Capturing(list): if capture_errors: self._sterr = sys.stderr - sys.sterr = StringIO() # memory hole it + # sys.sterr = StringIO() # memory hole it + sys.sterr = self._stringio_err + self.capture_errors = capture_errors return self @@ -70,7 +74,7 @@ class Capturing(list): sys.stdout = self._stdout if self.capture_errors: sys.sterr = self._sterr - + self.errors = self._stringio_err.getvalue() class Capturing2(Capturing): def __exit__(self, *args): diff --git a/src/unitgrade/version.py b/src/unitgrade/version.py index 91eab43..e60dd6e 100644 --- a/src/unitgrade/version.py +++ b/src/unitgrade/version.py @@ -1 +1,3 @@ -__version__ = "0.1.30.2" \ No newline at end of file +__version__ = "0.1.30.5" \ + "" \ + "" \ No newline at end of file -- GitLab