|
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 |
@@ -381,6 +383,42 @@ def test_dialog(): |
381 | 383 | opts1 = d.options() |
382 | 384 |
|
383 | 385 |
|
| 386 | +class TestModel(GuiTest): |
| 387 | + def test_model(self): |
| 388 | + path = TestOWCSVFileImport.data_regions_path |
| 389 | + model = owcsvimport.VarPathItemModel() |
| 390 | + model.setItemPrototype(owcsvimport.ImportItem()) |
| 391 | + it1 = owcsvimport.ImportItem() |
| 392 | + it1.setVarPath(PathItem.VarPath("prefix", "data-regions.tab")) |
| 393 | + it2 = owcsvimport.ImportItem() |
| 394 | + it2.setVarPath(PathItem.AbsPath(path)) |
| 395 | + model.appendRow([it1]) |
| 396 | + model.appendRow([it2]) |
| 397 | + |
| 398 | + def data(row, role): |
| 399 | + return model.data(model.index(row, 0), role) |
| 400 | + |
| 401 | + self.assertIsInstance(data(0, Qt.DecorationRole), QIcon) |
| 402 | + self.assertIsInstance(data(1, Qt.DecorationRole), QIcon) |
| 403 | + |
| 404 | + self.assertEqual(data(0, Qt.DisplayRole), "data-regions.tab") |
| 405 | + self.assertEqual(data(1, Qt.DisplayRole), "data-regions.tab") |
| 406 | + |
| 407 | + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab (missing)") |
| 408 | + self.assertTrue(samepath(data(1, Qt.ToolTipRole), path)) |
| 409 | + |
| 410 | + self.assertIsNotNone(data(0, Qt.ForegroundRole)) |
| 411 | + self.assertIsNone(data(1, Qt.ForegroundRole)) |
| 412 | + spy = QSignalSpy(model.dataChanged) |
| 413 | + model.setReplacementEnv({"prefix": os.path.dirname(path)}) |
| 414 | + self.assertSequenceEqual( |
| 415 | + [[model.index(0, 0), model.index(1, 0), []]], |
| 416 | + list(spy) |
| 417 | + ) |
| 418 | + self.assertEqual(data(0, Qt.ToolTipRole), "${prefix}/data-regions.tab") |
| 419 | + self.assertIsNone(data(0, Qt.ForegroundRole)) |
| 420 | + |
| 421 | + |
384 | 422 | class TestUtils(unittest.TestCase): |
385 | 423 | def test_load_csv(self): |
386 | 424 | contents = ( |
|
0 commit comments