|
| 1 | +import os |
1 | 2 | import unittest
|
2 | 3 |
|
3 | 4 | import numpy as np
|
4 | 5 | import scipy.sparse as sp
|
5 | 6 |
|
6 | 7 | from orangecontrib.text.corpus import Corpus
|
7 |
| -from orangecontrib.text.vectorization.base import BaseVectorizer |
| 8 | +from orangecontrib.text.vectorization.base import ( |
| 9 | + BaseVectorizer, |
| 10 | + VectorizationComputeValue, |
| 11 | +) |
8 | 12 |
|
9 | 13 |
|
10 | 14 | class BaseVectorizationTest(unittest.TestCase):
|
@@ -32,3 +36,33 @@ def test_variable_attributes(self):
|
32 | 36 |
|
33 | 37 | for a in c2.domain.attributes:
|
34 | 38 | self.assertIn('foo', a.attributes)
|
| 39 | + |
| 40 | + |
| 41 | +class TestVectorizationComputeValue(unittest.TestCase): |
| 42 | + def test_unpickling_old_pickle(self): |
| 43 | + """ |
| 44 | + Before orange3-text version 1.12.0 variable was wrongly set to current |
| 45 | + variable (variable that has this compute value attached) instead of |
| 46 | + original variable which caused fails after latest changes in core |
| 47 | + Orange. Since variable from VectorizationComputeValue is never used in |
| 48 | + practice we do not set it anymore (it is always None for |
| 49 | + VectorizationComputeValue). |
| 50 | + Anyway it is still set in pickles create before 1.12.0. With this test |
| 51 | + we test that old pickle with variables that have VectorizationComputeValue |
| 52 | + are un-pickled correctly. |
| 53 | + """ |
| 54 | + path = os.path.join( |
| 55 | + os.path.dirname(os.path.abspath(__file__)), "data", "old-bow-pickle.pkl" |
| 56 | + ) |
| 57 | + data = Corpus.from_file(path) |
| 58 | + self.assertEqual(len(data), 3) |
| 59 | + self.assertIsInstance(data.domain["!"].compute_value, VectorizationComputeValue) |
| 60 | + self.assertIsInstance( |
| 61 | + data.domain["aboard"].compute_value, VectorizationComputeValue |
| 62 | + ) |
| 63 | + self.assertIsNone(data.domain["!"].compute_value.variable) |
| 64 | + self.assertIsNone(data.domain["aboard"].compute_value.variable) |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + unittest.main() |
0 commit comments