|
12 | 12 | import numpy as np |
13 | 13 | from numpy.testing import assert_array_equal |
14 | 14 |
|
15 | | -from AnyQt.QtCore import QSettings |
| 15 | +from AnyQt.QtCore import QSettings, Qt |
| 16 | +from AnyQt.QtGui import QIcon |
16 | 17 | from AnyQt.QtWidgets import QFileDialog |
| 18 | +from AnyQt.QtTest import QSignalSpy |
17 | 19 |
|
18 | 20 | from orangewidget.tests.utils import simulate |
19 | 21 | from orangewidget.widget import OWBaseWidget |
@@ -352,6 +354,42 @@ def test_dialog(self): |
352 | 354 | opts1 = d.options() |
353 | 355 |
|
354 | 356 |
|
| 357 | +class TestModel(GuiTest): |
| 358 | + def test_model(self): |
| 359 | + path = TestOWCSVFileImport.data_regions_path |
| 360 | + model = owcsvimport.VarPathItemModel() |
| 361 | + model.setItemPrototype(owcsvimport.ImportItem()) |
| 362 | + it1 = owcsvimport.ImportItem() |
| 363 | + it1.setVarPath(PathItem.VarPath("prefix", "data-regions.tab")) |
| 364 | + it2 = owcsvimport.ImportItem() |
| 365 | + it2.setVarPath(PathItem.AbsPath(path)) |
| 366 | + model.appendRow([it1]) |
| 367 | + model.appendRow([it2]) |
| 368 | + |
| 369 | + def data(row, role): |
| 370 | + return model.data(model.index(row, 0), role) |
| 371 | + |
| 372 | + self.assertIsInstance(data(0, Qt.DecorationRole), QIcon) |
| 373 | + self.assertIsInstance(data(1, Qt.DecorationRole), QIcon) |
| 374 | + |
| 375 | + self.assertEqual(data(0, Qt.DisplayRole), "data-regions.tab") |
| 376 | + self.assertEqual(data(1, Qt.DisplayRole), "data-regions.tab") |
| 377 | + |
| 378 | + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab (missing)") |
| 379 | + self.assertTrue(samepath(data(1, Qt.ToolTipRole), path)) |
| 380 | + |
| 381 | + self.assertIsNotNone(data(0, Qt.ForegroundRole)) |
| 382 | + self.assertIsNone(data(1, Qt.ForegroundRole)) |
| 383 | + spy = QSignalSpy(model.dataChanged) |
| 384 | + model.setReplacementEnv({"prefix": os.path.dirname(path)}) |
| 385 | + self.assertSequenceEqual( |
| 386 | + [[model.index(0, 0), model.index(1, 0), []]], |
| 387 | + list(spy) |
| 388 | + ) |
| 389 | + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab") |
| 390 | + self.assertIsNone(data(0, Qt.ForegroundRole)) |
| 391 | + |
| 392 | + |
355 | 393 | class TestUtils(unittest.TestCase): |
356 | 394 | def test_load_csv(self): |
357 | 395 | contents = ( |
|
0 commit comments