Skip to content

Commit

Permalink
Merge pull request #4631 from janezd/pytablemodel-wrap-empty
Browse files Browse the repository at this point in the history
[FIX] PyTableModel: Allow wrapping empty lists
  • Loading branch information
ales-erjavec authored Apr 9, 2020
2 parents f23c906 + 8ccdd2a commit db4e7ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Orange/widgets/utils/itemmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ def __init__(self, sequence=None, parent=None, editable=False):
self._editable = editable
self._table = None
self._roleData = {}
self.wrap(sequence or [])
if sequence is None:
sequence = []
self.wrap(sequence)

def rowCount(self, parent=QModelIndex()):
return 0 if parent.isValid() else self._rows
Expand Down
8 changes: 8 additions & 0 deletions Orange/widgets/utils/tests/test_itemmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_init(self):
self.model = PyTableModel()
self.assertEqual(self.model.rowCount(), 0)

def test_init_wrap_empty(self):
# pylint: disable=protected-access
t = []
model = PyTableModel(t)
self.assertIs(model._table, t)
t.append([1, 2, 3])
self.assertEqual(list(model), [[1, 2, 3]])

def test_rowCount(self):
self.assertEqual(self.model.rowCount(), 2)
self.assertEqual(len(self.model), 2)
Expand Down

0 comments on commit db4e7ce

Please sign in to comment.