Skip to content

Commit

Permalink
PyTableModel: Allow wrapping empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Apr 7, 2020
1 parent 3f4c786 commit 8ccdd2a
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 8ccdd2a

Please sign in to comment.