From 7a723b85c2c0cc7e448e10d04980020cb76cdb88 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 23 Oct 2023 11:48:16 +0100 Subject: [PATCH 1/4] Added regression test for bug that caused image viewer to turn green when an incompatible subset was present --- .../bqplot/image/tests/test_visual.py | 32 +++++++++++++++++++ .../tests/images/py311-test-visual.json | 3 +- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 glue_jupyter/bqplot/image/tests/test_visual.py diff --git a/glue_jupyter/bqplot/image/tests/test_visual.py b/glue_jupyter/bqplot/image/tests/test_visual.py new file mode 100644 index 00000000..60cf4acf --- /dev/null +++ b/glue_jupyter/bqplot/image/tests/test_visual.py @@ -0,0 +1,32 @@ +import numpy as np + +from glue_jupyter import jglue +from glue_jupyter.tests.helpers import visual_widget_test + + +@visual_widget_test +def test_visual_incompatible_subset( + tmp_path, + page_session, + solara_test, +): + + # Regression test for a bug that caused incompatible subsets + # to make the whole image green. + + np.random.seed(12345) + im = np.random.random((64, 64)) + x = np.random.normal(3, 1, 100) + y = np.random.normal(2, 1.5, 100) + + app = jglue() + data1 = app.add_data(image={"image": im})[0] + data2 = app.add_data(catalog={"x": x, "y": y})[0] + scatter = app.imshow(data=data1, show=False) + state1 = data1.pixel_component_ids[1] > 32 + app.data_collection.new_subset_group('image[x] > 32', state1) + state2 = data2.id['x'] > 1 + app.data_collection.new_subset_group('x > 1', state2) + figure = scatter.figure_widget + figure.layout = {"width": "400px", "height": "250px"} + return figure diff --git a/glue_jupyter/tests/images/py311-test-visual.json b/glue_jupyter/tests/images/py311-test-visual.json index c2c0d65c..a8075c3b 100644 --- a/glue_jupyter/tests/images/py311-test-visual.json +++ b/glue_jupyter/tests/images/py311-test-visual.json @@ -1,4 +1,5 @@ { "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d[chromium]": "edd4e65c87369bc6e403f45e87d914223bc13f42c2f90a55535614923e233c00", - "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7" + "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7", + "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_incompatible_subset[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7" } From 5b92f9a6aebebc95128f787c8f2dfda8a4a8497a Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 23 Oct 2023 12:08:02 +0100 Subject: [PATCH 2/4] Add absolute delay before screenshot --- glue_jupyter/bqplot/image/tests/test_visual.py | 4 ++-- glue_jupyter/tests/helpers.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/glue_jupyter/bqplot/image/tests/test_visual.py b/glue_jupyter/bqplot/image/tests/test_visual.py index 60cf4acf..ce84b2d2 100644 --- a/glue_jupyter/bqplot/image/tests/test_visual.py +++ b/glue_jupyter/bqplot/image/tests/test_visual.py @@ -22,11 +22,11 @@ def test_visual_incompatible_subset( app = jglue() data1 = app.add_data(image={"image": im})[0] data2 = app.add_data(catalog={"x": x, "y": y})[0] - scatter = app.imshow(data=data1, show=False) state1 = data1.pixel_component_ids[1] > 32 app.data_collection.new_subset_group('image[x] > 32', state1) state2 = data2.id['x'] > 1 app.data_collection.new_subset_group('x > 1', state2) - figure = scatter.figure_widget + image = app.imshow(data=data1, show=False) + figure = image.figure_widget figure.layout = {"width": "400px", "height": "250px"} return figure diff --git a/glue_jupyter/tests/helpers.py b/glue_jupyter/tests/helpers.py index a87aeb20..4d329b41 100644 --- a/glue_jupyter/tests/helpers.py +++ b/glue_jupyter/tests/helpers.py @@ -49,6 +49,9 @@ def test_wrapper(tmp_path, page_session, *args, **kwargs): viewer = page_session.locator(".test-viewer") viewer.wait_for() + # Wait for an additional 2 seconds + page_session.wait_for_timeout(2000) + screenshot = viewer.screenshot() return DummyFigure(screenshot) From 144419e135cc811738ac419305f414f6b0cb7752 Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 23 Oct 2023 13:30:15 +0100 Subject: [PATCH 3/4] Update hash --- glue_jupyter/bqplot/image/tests/test_visual.py | 2 +- glue_jupyter/tests/images/py311-test-visual.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/glue_jupyter/bqplot/image/tests/test_visual.py b/glue_jupyter/bqplot/image/tests/test_visual.py index ce84b2d2..19fc02ee 100644 --- a/glue_jupyter/bqplot/image/tests/test_visual.py +++ b/glue_jupyter/bqplot/image/tests/test_visual.py @@ -22,11 +22,11 @@ def test_visual_incompatible_subset( app = jglue() data1 = app.add_data(image={"image": im})[0] data2 = app.add_data(catalog={"x": x, "y": y})[0] + image = app.imshow(data=data1, show=False) state1 = data1.pixel_component_ids[1] > 32 app.data_collection.new_subset_group('image[x] > 32', state1) state2 = data2.id['x'] > 1 app.data_collection.new_subset_group('x > 1', state2) - image = app.imshow(data=data1, show=False) figure = image.figure_widget figure.layout = {"width": "400px", "height": "250px"} return figure diff --git a/glue_jupyter/tests/images/py311-test-visual.json b/glue_jupyter/tests/images/py311-test-visual.json index a8075c3b..4a553985 100644 --- a/glue_jupyter/tests/images/py311-test-visual.json +++ b/glue_jupyter/tests/images/py311-test-visual.json @@ -1,5 +1,5 @@ { "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d[chromium]": "edd4e65c87369bc6e403f45e87d914223bc13f42c2f90a55535614923e233c00", "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7", - "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_incompatible_subset[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7" + "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_incompatible_subset[chromium]": "5cb824b79af81ff2fbec1367bf206f11b428076a361745b1fef2e61d912d457d" } From 2cd5309043e105d8e15c0a2fbc7f42ceba4830dc Mon Sep 17 00:00:00 2001 From: Thomas Robitaille Date: Mon, 23 Oct 2023 13:47:10 +0100 Subject: [PATCH 4/4] Fix name in hash file --- glue_jupyter/tests/images/py311-test-visual.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glue_jupyter/tests/images/py311-test-visual.json b/glue_jupyter/tests/images/py311-test-visual.json index 4a553985..7f87262b 100644 --- a/glue_jupyter/tests/images/py311-test-visual.json +++ b/glue_jupyter/tests/images/py311-test-visual.json @@ -1,5 +1,5 @@ { "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d[chromium]": "edd4e65c87369bc6e403f45e87d914223bc13f42c2f90a55535614923e233c00", "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7", - "glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_incompatible_subset[chromium]": "5cb824b79af81ff2fbec1367bf206f11b428076a361745b1fef2e61d912d457d" + "glue_jupyter.bqplot.image.tests.test_visual.test_visual_incompatible_subset[chromium]": "5cb824b79af81ff2fbec1367bf206f11b428076a361745b1fef2e61d912d457d" }