Misc cleanup

This commit is contained in:
Jeremy Stretch 2024-02-06 13:42:21 -05:00
parent 3ef9007427
commit 8e2e4979b0
2 changed files with 22 additions and 13 deletions

View File

@ -394,9 +394,18 @@ class BaseScript:
return ordered_vars return ordered_vars
def run(self, data, commit): def run(self, data, commit):
raise NotImplementedError("The script must define a run() method.") """
Override this method with custom script logic.
"""
# Backward compatibility for legacy Reports
self.pre_run()
self.run_tests()
self.post_run()
#
# Form rendering # Form rendering
#
def get_fieldsets(self): def get_fieldsets(self):
fieldsets = [] fieldsets = []
@ -435,7 +444,9 @@ class BaseScript:
return form return form
#
# Logging # Logging
#
def _log(self, message, obj=None, level=LogLevelChoices.LOG_DEFAULT): def _log(self, message, obj=None, level=LogLevelChoices.LOG_DEFAULT):
""" """
@ -484,7 +495,9 @@ class BaseScript:
self._log(message, obj, level=LogLevelChoices.LOG_FAILURE) self._log(message, obj, level=LogLevelChoices.LOG_FAILURE)
self._failed = True self._failed = True
#
# Convenience functions # Convenience functions
#
def load_yaml(self, filename): def load_yaml(self, filename):
""" """
@ -511,6 +524,10 @@ class BaseScript:
return data return data
#
# Legacy Report functionality
#
def run_tests(self): def run_tests(self):
""" """
Run the report and save its results. Each test method will be executed in order. Run the report and save its results. Each test method will be executed in order.
@ -529,20 +546,15 @@ class BaseScript:
self._current_method = '' self._current_method = ''
def run(self, data, commit):
self.pre_run()
self.run_tests()
self.post_run()
def pre_run(self): def pre_run(self):
""" """
Extend this method to include any tasks which should execute *before* the report is run. Legacy method for operations performed immediately prior to running a Report.
""" """
pass pass
def post_run(self): def post_run(self):
""" """
Extend this method to include any tasks which should execute *after* the report is run. Legacy method for operations performed immediately after running a Report.
""" """
pass pass

View File

@ -49,15 +49,12 @@ def register_features(model, features):
def is_script(obj): def is_script(obj):
""" """
Returns True if the object is a Script. Returns True if the object is a Script or Report.
"""
"""
Returns True if the given object is a Report.
""" """
from .reports import Report from .reports import Report
from .scripts import Script from .scripts import Script
try: try:
return ((issubclass(obj, Report) and obj != Report) or (issubclass(obj, Script) and obj != Script)) return (issubclass(obj, Report) and obj != Report) or (issubclass(obj, Script) and obj != Script)
except TypeError: except TypeError:
return False return False