Skip to content

Commit

Permalink
Table: Make locking optional; enable it in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Jun 11, 2021
1 parent 490a9b7 commit e7d9d57
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Orange/canvas/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from Orange.data import Table

Table.LOCKING = True
10 changes: 9 additions & 1 deletion Orange/data/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ def __init__(self, source, destination):

# noinspection PyPep8Naming
class Table(Sequence, Storage):
LOCKING = False

__file__ = None
name = "untitled"

Expand Down Expand Up @@ -446,6 +448,9 @@ def _lock_parts(self):
(self._W, self._Unlocked_W, "weights"))

def _update_locks(self, force=False, unlock_bases=()):
if not Table.LOCKING:
return

def sync(*xs):
for x in xs:
try:
Expand Down Expand Up @@ -540,7 +545,10 @@ def warn_deprecated(method):
if not args:
if not kwargs:
self = super().__new__(cls)
self._unlocked = 0
if Table.LOCKING:
self._unlocked = 0
else:
self._unlocked = sum(f for _, f, _ in self._lock_parts())
return self
else:
raise TypeError("Table() must not be called directly")
Expand Down
21 changes: 21 additions & 0 deletions Orange/data/tests/test_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import os

import numpy as np
import scipy.sparse as sp
Expand Down Expand Up @@ -252,6 +253,18 @@ def test_with_column(self):


class TestTableLocking(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.orig_locking = Table.LOCKING
if os.getenv("CI"):
assert Table.LOCKING
else:
Table.LOCKING = True

@classmethod
def tearDownClass(cls):
Table.LOCKING = cls.orig_locking

def setUp(self):
a, b, c, d, e, f, g = map(ContinuousVariable, "abcdefg")
domain = Domain([a, b, c], d, [e, f])
Expand Down Expand Up @@ -325,6 +338,14 @@ def test_force_unlocking(self):
tab.X[0, 0] = 0
tab.Y[0] = 0

def test_locking_flag(self):
try:
default = Table.LOCKING
Table.LOCKING = False
self.setUp()
self.table.X[0, 0] = 0
finally:
Table.LOCKING = default

class TestTableFilters(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 2 additions & 0 deletions Orange/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import numpy as np
import Orange

Orange.data.Table.LOCKING = True


@contextmanager
def named_file(content, encoding=None, suffix=''):
Expand Down
5 changes: 5 additions & 0 deletions Orange/widgets/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import os
import unittest

import Orange
import Orange.widgets


Orange.data.Table.LOCKING = True


def load_tests(loader, tests, pattern):
# Need to guard against inf. recursion. This package will be found again
# within the discovery process.
Expand Down
3 changes: 3 additions & 0 deletions Orange/widgets/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
from Orange.widgets.widget import OWWidget


Table.LOCKING = True


class WidgetTest(WidgetTestBase):
def assert_table_equal(self, table1, table2):
if table1 is None or table2 is None:
Expand Down

0 comments on commit e7d9d57

Please sign in to comment.