Skip to content

Commit

Permalink
Select Rows: Add test for partial matches
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Dec 13, 2019
1 parent 7323aac commit fa537b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Orange/widgets/data/owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def encode_setting(self, context, setting, value):
def decode_setting(self, setting, value, domain=None):
value = super().decode_setting(setting, value, domain)
if setting.name == 'conditions':
# Use this after 2021/1/1:
# Use this after 2022/2/2:
# for i, (attr, _, op, values) in enumerate(value):
for i, condition in enumerate(value):
attr = condition[0]
Expand All @@ -78,7 +78,7 @@ def match(self, context, domain, attrs, metas):
conditions = context.values["conditions"]
all_vars = attrs
all_vars.update(metas)
# Use this after 2021/1/1:
# Use this after 2022/2/2:
# if all(all_vars.get(name) == tpe for name, tpe, *_ in conditions):
if all(all_vars.get(name) == tpe if len(rest) == 2 else name in all_vars
for name, tpe, *rest in conditions):
Expand Down Expand Up @@ -715,7 +715,7 @@ def send_report(self):
("Non-matching data",
nonmatch_inst > 0 and "{} instances".format(nonmatch_inst))))

# Uncomment this on 2021/1/1
# Uncomment this on 2022/2/2
#
# @classmethod
# def migrate_context(cls, context, version):
Expand Down
21 changes: 17 additions & 4 deletions Orange/widgets/data/tests/test_owselectrows.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ def test_restores_continuous_filter_in_sl_SI_locale(self):
values = self.widget.conditions[0][2]
self.assertTrue(values[0].startswith("5,2"))

@override_locale(QLocale.C)
def test_partial_matches(self):
iris = Table("iris")
domain = iris.domain
self.widget = self.widget_with_context(
domain, [[domain[0].name, 2, ("5.2",)]])
iris2 = iris.transform(Domain(domain.attributes[:2], None))
self.send_signal(self.widget.Inputs.data, iris2)
condition = self.widget.conditions[0]
self.assertEqual(condition[0], "sepal length")
self.assertEqual(condition[1], 2)
self.assertTrue(condition[2][0].startswith("5.2"))

def test_load_settings(self):
iris = Table("iris")[:5]
self.send_signal(self.widget.Inputs.data, iris)
Expand Down Expand Up @@ -261,7 +274,7 @@ def test_change_var_type(self):
new_iris = iris.transform(new_domain)
self.send_signal(self.widget.Inputs.data, new_iris)

# Uncomment this on 2021/1/1
# Uncomment this on 2022/2/2
#
# def test_migration_to_version_1(self):
# iris = Table("iris")
Expand All @@ -284,10 +297,10 @@ def test_support_old_settings(self):
self.assertEqual(condition[1], 2)
self.assertTrue(condition[2][0].startswith("5.2"))

def test_end_support_for_version_0(self):
if time.gmtime().tm_year == 2021:
def test_end_support_for_version_1(self):
if time.gmtime() >= (2022, 2, 2):
self.fail("""
Happy new year 2021!
Happy 22/2/2!
Now remove support for version==None settings in
SelectRowsContextHandler.decode_setting and SelectRowsContextHandler.match,
Expand Down

0 comments on commit fa537b1

Please sign in to comment.