From 18f842b562144fafdf1661bb02ee1d1d034b9ca1 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Mon, 20 Jul 2020 11:49:02 +0200 Subject: [PATCH] owcsvimport: Add test for model --- Orange/widgets/data/tests/test_owcsvimport.py | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Orange/widgets/data/tests/test_owcsvimport.py b/Orange/widgets/data/tests/test_owcsvimport.py index 1abc8f48922..7955d72deff 100644 --- a/Orange/widgets/data/tests/test_owcsvimport.py +++ b/Orange/widgets/data/tests/test_owcsvimport.py @@ -12,8 +12,10 @@ import numpy as np from numpy.testing import assert_array_equal -from AnyQt.QtCore import QSettings +from AnyQt.QtCore import QSettings, Qt +from AnyQt.QtGui import QIcon from AnyQt.QtWidgets import QFileDialog +from AnyQt.QtTest import QSignalSpy from orangewidget.tests.utils import simulate from orangewidget.widget import OWBaseWidget @@ -352,6 +354,42 @@ def test_dialog(self): opts1 = d.options() +class TestModel(GuiTest): + def test_model(self): + path = TestOWCSVFileImport.data_regions_path + model = owcsvimport.VarPathItemModel() + model.setItemPrototype(owcsvimport.ImportItem()) + it1 = owcsvimport.ImportItem() + it1.setVarPath(PathItem.VarPath("prefix", "data-regions.tab")) + it2 = owcsvimport.ImportItem() + it2.setVarPath(PathItem.AbsPath(path)) + model.appendRow([it1]) + model.appendRow([it2]) + + def data(row, role): + return model.data(model.index(row, 0), role) + + self.assertIsInstance(data(0, Qt.DecorationRole), QIcon) + self.assertIsInstance(data(1, Qt.DecorationRole), QIcon) + + self.assertEqual(data(0, Qt.DisplayRole), "data-regions.tab") + self.assertEqual(data(1, Qt.DisplayRole), "data-regions.tab") + + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab (missing)") + self.assertTrue(samepath(data(1, Qt.ToolTipRole), path)) + + self.assertIsNotNone(data(0, Qt.ForegroundRole)) + self.assertIsNone(data(1, Qt.ForegroundRole)) + spy = QSignalSpy(model.dataChanged) + model.setReplacementEnv({"prefix": os.path.dirname(path)}) + self.assertSequenceEqual( + [[model.index(0, 0), model.index(1, 0), []]], + list(spy) + ) + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab") + self.assertIsNone(data(0, Qt.ForegroundRole)) + + class TestUtils(unittest.TestCase): def test_load_csv(self): contents = (