Skip to content

Commit

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

def rowCount(self, parent=QModelIndex()):
return 0 if parent.isValid() else len(self)
Expand Down
8 changes: 8 additions & 0 deletions orangewidget/utils/tests/test_itemmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def test_wrap(self):
self.assertEqual(self.model.rowCount(), 1)
self.assertEqual(self.model.columnCount(), 1)

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_clear(self):
self.model.clear()
self.assertEqual(self.model.rowCount(), 0)
Expand Down

0 comments on commit c0a40f0

Please sign in to comment.