diff --git a/plug-ins/python/tests/test-file-plug-ins/gimplogger.py b/plug-ins/python/tests/test-file-plug-ins/gimplogger.py index 6c8660a2e8..89478f38e5 100755 --- a/plug-ins/python/tests/test-file-plug-ins/gimplogger.py +++ b/plug-ins/python/tests/test-file-plug-ins/gimplogger.py @@ -36,6 +36,7 @@ class GimpLogger (object): self.verbose = verbose self.debugging = debugging + self.enabled = True if debugging: log_level = logging.DEBUG @@ -46,15 +47,25 @@ class GimpLogger (object): else: log_filemode = 'w' - logging.basicConfig( - filename=logfile, - filemode=log_filemode, - encoding='utf-8', - level=log_level, - format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') + try: + logging.basicConfig( + filename=logfile, + filemode=log_filemode, + encoding='utf-8', + level=log_level, + format='%(asctime)s | %(name)s | %(levelname)s | %(message)s') - logging.debug("Starting logger...") - logging.debug("Log file: %s", os.path.abspath(logfile)) + logging.debug("Starting logger...") + logging.debug("Log file: %s", os.path.abspath(logfile)) + except PermissionError: + self.enabled = False + msg = ("We do not have permission to create a log file at " + + os.path.abspath(logfile) + ". " + + "Please use env var GIMP_TESTS_LOG_FILE to set up a location.") + if interactive: + Gimp.message(msg) + else: + print(msg) def set_interactive(self, interactive): if self.interactive != interactive: diff --git a/plug-ins/python/tests/test-file-plug-ins/test-file-plug-ins.py b/plug-ins/python/tests/test-file-plug-ins/test-file-plug-ins.py index 7bd04d3469..d9cb3cccaf 100755 --- a/plug-ins/python/tests/test-file-plug-ins/test-file-plug-ins.py +++ b/plug-ins/python/tests/test-file-plug-ins/test-file-plug-ins.py @@ -45,13 +45,13 @@ PRINT_VERBOSE = False LOG_APPEND = False -test_cfg = GimpConfig() - -log = GimpLogger(False, test_cfg.log_file, LOG_APPEND, PRINT_VERBOSE, DEBUGGING) - - class PythonTest (Gimp.PlugIn): + def __init__(self): + Gimp.PlugIn.__init__(self) + self.test_cfg = None + self.log = None + ## GimpPlugIn virtual methods ## def do_set_i18n(self, _name): # We don't support internationalization here... @@ -93,31 +93,38 @@ class PythonTest (Gimp.PlugIn): YEARS) #year return procedure + def init_logging(self): + self.test_cfg = GimpConfig() + + self.log = GimpLogger(True, self.test_cfg.log_file, LOG_APPEND, PRINT_VERBOSE, DEBUGGING) + def run_import_tests(self, procedure, _run_mode, _image, _n_drawables, _drawable, _config, _data): - log.set_interactive(True) + self.init_logging() - runner = GimpTestRunner(log, "import", test_cfg) - runner.run_tests() + if self.log.enabled: + runner = GimpTestRunner(self.log, "import", self.test_cfg) + runner.run_tests() return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error()) def run_export_tests(self, procedure, _run_mode, _image, _n_drawables, _drawable, _config, _data): - log.set_interactive(True) + self.init_logging() - runner = GimpExportTestRunner(log, "export", test_cfg) - if not runner: - log.error("Failed to create export test runner!") - else: - runner.load_test_configs() + if self.log.enabled: + runner = GimpExportTestRunner(self.log, "export", self.test_cfg) + if not runner: + self.log.error("Failed to create export test runner!") + else: + runner.load_test_configs() - bmp_tests = BmpExportTests("bmp", log) - runner.add_test(bmp_tests) + bmp_tests = BmpExportTests("bmp", self.log) + runner.add_test(bmp_tests) - # Add additional tests here + # Add additional tests here - runner.run_tests() + runner.run_tests() return procedure.new_return_values(Gimp.PDBStatusType.SUCCESS, GLib.Error())