Skip to content

Commit

Permalink
Add test of model/sort-preserving functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carifio24 committed Mar 22, 2023
1 parent 2ade3ea commit 19fc3f9
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions glue/viewers/table/qt/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,65 @@ def test_table_with_dask_column():
colors = ['#aa0000', '#aa0000', '#aa0000', None, None]

check_values_and_color(model, data, colors)


def test_table_preserve_model_after_selection():

# Regression test for a bug that caused table viewers to return
# to default sorting after a new subset was created with the row
# selection tool. This occurred because the model was reset.

app = get_qapp() # noqa

d = Data(a=[1, 2, 3, 4, 5],
b=[3.2, 1.2, 4.5, 3.3, 2.2],
c=['e', 'b', 'c', 'a', 'f'], label='test')

dc = DataCollection([d])

gapp = GlueApplication(dc)

viewer = gapp.new_data_viewer(TableViewer)
viewer.add_data(d)

model = viewer.ui.table.model()

model.sort(1, Qt.AscendingOrder)

data = {'a': [2, 5, 1, 4, 3],
'b': [1.2, 2.2, 3.2, 3.3, 4.5],
'c': ['b', 'f', 'e', 'a', 'c']}
colors = [None for _ in range(5)]

check_values_and_color(model, data, colors)

# Create a new subset using the row selection tool

subset_mode = gapp._session.edit_subset_mode
subset_mode.edit_subset = None
viewer.toolbar.actions['table:rowselect'].toggle()

def press_key(key):
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, key, Qt.NoModifier)
app.postEvent(viewer.ui.table, event)
app.processEvents()

# Select the second row
press_key(Qt.Key_Tab)
press_key(Qt.Key_Down)
press_key(Qt.Key_Enter)

process_events()

# Check that the table model is still the same, which it
# should be since we aren't changing the viewer Data

post_model = viewer.ui.table.model()
assert post_model == model

# Check that the order is still the same

color = d.subsets[0].style.color
colors[1] = color

check_values_and_color(post_model, data, colors)

0 comments on commit 19fc3f9

Please sign in to comment.