@@ -175,45 +175,30 @@ def set_device_pixel_ratio(ratio):
175175assert qt_canvas .device_pixel_ratio == ratio
176176
177177qt_canvas .manager .show ()
178+ qt_canvas .draw ()
179+ qt_canvas .flush_events ()
178180size = qt_canvas .size ()
179- set_device_pixel_ratio (3 )
180-
181- # The DPI and the renderer width/height change
182- assert fig .dpi == 360
183- assert qt_canvas .renderer .width == 1800
184- assert qt_canvas .renderer .height == 720
185-
186- # The actual widget size and figure logical size don't change.
187- assert size .width ()== 600
188- assert size .height ()== 240
189- assert qt_canvas .get_width_height ()== (600 ,240 )
190- assert (fig .get_size_inches ()== (5 ,2 )).all ()
191-
192- set_device_pixel_ratio (2 )
193-
194- # The DPI and the renderer width/height change
195- assert fig .dpi == 240
196- assert qt_canvas .renderer .width == 1200
197- assert qt_canvas .renderer .height == 480
198-
199- # The actual widget size and figure logical size don't change.
200- assert size .width ()== 600
201- assert size .height ()== 240
202- assert qt_canvas .get_width_height ()== (600 ,240 )
203- assert (fig .get_size_inches ()== (5 ,2 )).all ()
204-
205- set_device_pixel_ratio (1.5 )
206-
207- # The DPI and the renderer width/height change
208- assert fig .dpi == 180
209- assert qt_canvas .renderer .width == 900
210- assert qt_canvas .renderer .height == 360
211-
212- # The actual widget size and figure logical size don't change.
213- assert size .width ()== 600
214- assert size .height ()== 240
215- assert qt_canvas .get_width_height ()== (600 ,240 )
216- assert (fig .get_size_inches ()== (5 ,2 )).all ()
181+
182+ options = [
183+ (None ,360 ,1800 ,720 ),# Use ratio at startup time.
184+ (3 ,360 ,1800 ,720 ),# Change to same ratio.
185+ (2 ,240 ,1200 ,480 ),# Change to different ratio.
186+ (1.5 ,180 ,900 ,360 ),# Fractional ratio.
187+ ]
188+ for ratio ,dpi ,width ,height in options :
189+ if ratio is not None :
190+ set_device_pixel_ratio (ratio )
191+
192+ # The DPI and the renderer width/height change
193+ assert fig .dpi == dpi
194+ assert qt_canvas .renderer .width == width
195+ assert qt_canvas .renderer .height == height
196+
197+ # The actual widget size and figure logical size don't change.
198+ assert size .width ()== 600
199+ assert size .height ()== 240
200+ assert qt_canvas .get_width_height ()== (600 ,240 )
201+ assert (fig .get_size_inches ()== (5 ,2 )).all ()
217202
218203
219204@pytest .mark .backend ('QtAgg' ,skip_on_importerror = True )