diff --git a/Orange/data/tests/test_variable.py b/Orange/data/tests/test_variable.py index 98bf8f2a9e1..a0109c47e25 100644 --- a/Orange/data/tests/test_variable.py +++ b/Orange/data/tests/test_variable.py @@ -1,12 +1,13 @@ # Test methods with long descriptive names can omit docstrings # pylint: disable=missing-docstring # pylint: disable=protected-access - +import os import sys import math import unittest import pickle import pkgutil +import warnings from datetime import datetime, timezone from io import StringIO @@ -16,7 +17,7 @@ import Orange from Orange.data import Variable, ContinuousVariable, DiscreteVariable, \ - StringVariable, TimeVariable, Unknown, Value + StringVariable, TimeVariable, Unknown, Value, Table from Orange.data.io import CSVReader from Orange.preprocess.transformation import Identity from Orange.tests.base import create_pickling_tests @@ -500,6 +501,25 @@ def test_remove_ordered(self): """ self.assertLess(Orange.__version__, "3.29.0") + @staticmethod + def test_pickle_backward_compatibility(): + """ + Test that pickle made with an older version of Orange are correctly + loaded after changes in DiscreteVariable + """ + with warnings.catch_warnings(): + # travis/gh-action tests change OrangeDeprecationWarning to error + # temporary disable it + warnings.simplefilter('default', OrangeDeprecationWarning) + this_dir = os.path.dirname(os.path.realpath(__file__)) + datasets_dir = os.path.join( + this_dir, "..", "..", "tests", "datasets" + ) + # pickle with values as list + Table(os.path.join(datasets_dir, "sailing-orange-3-20.pkl")) + # pickle with values as tuple list + Table(os.path.join(datasets_dir, "iris-orange-3-25.pkl")) + @variabletest(ContinuousVariable) class TestContinuousVariable(VariableTest): diff --git a/Orange/data/variable.py b/Orange/data/variable.py index fc7a14d2767..21d03ed653a 100644 --- a/Orange/data/variable.py +++ b/Orange/data/variable.py @@ -602,6 +602,9 @@ def copy(self, compute_value=Variable._CopyComputeValue, return var +TupleList = tuple # backward compatibility (for pickled table) + + class DiscreteVariable(Variable): """ Descriptor for symbolic, discrete variables. Values of discrete variables diff --git a/Orange/tests/datasets/iris-orange-3-25.pkl b/Orange/tests/datasets/iris-orange-3-25.pkl new file mode 100644 index 00000000000..3b5d5daa3d4 Binary files /dev/null and b/Orange/tests/datasets/iris-orange-3-25.pkl differ