From 83a10da7e33c7c969b46bd8cad53a72ba31f869e Mon Sep 17 00:00:00 2001 From: Marko Toplak Date: Fri, 1 Oct 2021 21:47:51 +0200 Subject: [PATCH] Easier disabling of Table.LOCKING in add-on tests This commit allows the add-ons to set Table.LOCKING to False independent of the order of imports. --- Orange/canvas/tests/__init__.py | 3 ++- Orange/data/table.py | 9 ++++++++- Orange/tests/__init__.py | 3 ++- Orange/widgets/tests/__init__.py | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Orange/canvas/tests/__init__.py b/Orange/canvas/tests/__init__.py index 15b1863c865..132be49d7a1 100644 --- a/Orange/canvas/tests/__init__.py +++ b/Orange/canvas/tests/__init__.py @@ -1,3 +1,4 @@ from Orange.data import Table -Table.LOCKING = True +if Table.LOCKING is None: + Table.LOCKING = True diff --git a/Orange/data/table.py b/Orange/data/table.py index 76d1347022e..85b9d336c9b 100644 --- a/Orange/data/table.py +++ b/Orange/data/table.py @@ -359,7 +359,14 @@ def __init__(self, source, destination): # noinspection PyPep8Naming class Table(Sequence, Storage): - LOCKING = False + + LOCKING = None + """ If the class attribute LOCKING is True, tables will throw exceptions + on in-place modifications unless unlocked explicitly. LOCKING is supposed + to be set to True for testing to help us find bugs. If set to False + or None, no safeguards are in place. Two different values are used for + the same behaviour to distinguish the unchanged default (None) form + explicit deactivation (False) that some add-ons might need. """ __file__ = None name = "untitled" diff --git a/Orange/tests/__init__.py b/Orange/tests/__init__.py index 2c297859375..b27f28a115e 100644 --- a/Orange/tests/__init__.py +++ b/Orange/tests/__init__.py @@ -12,7 +12,8 @@ import numpy as np import Orange -Orange.data.Table.LOCKING = True +if Orange.data.Table.LOCKING is None: + Orange.data.Table.LOCKING = True @contextmanager diff --git a/Orange/widgets/tests/__init__.py b/Orange/widgets/tests/__init__.py index 5a418d34342..9de76632823 100644 --- a/Orange/widgets/tests/__init__.py +++ b/Orange/widgets/tests/__init__.py @@ -4,8 +4,8 @@ import Orange import Orange.widgets - -Orange.data.Table.LOCKING = True +if Orange.data.Table.LOCKING is None: + Orange.data.Table.LOCKING = True def load_tests(loader, tests, pattern):