-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_loadtest.py
More file actions
95 lines (77 loc) · 2.8 KB
/
test_loadtest.py
File metadata and controls
95 lines (77 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the BSD 3-Clause
# (see plotpy/LICENSE for details)
"""Load test: instantiating a large number of image widgets"""
# guitest: show
import numpy as np
import pytest
from guidata.qthelpers import qt_app_context
# import cProfile
# from pstats import Stats
from qtpy import QtWidgets as QW
from plotpy.builder import make
class PlotTab(QW.QWidget):
"""Tab containing a grid of image widgets"""
def __init__(self):
super().__init__()
layout = QW.QGridLayout()
self.setLayout(layout)
def add_plot(self, iplt, irow, icol):
"""Add a plot to the grid"""
widget = make.widget(self, title="Plot #%d" % (iplt + 1), type="image")
widget.setMinimumSize(200, 150)
xdata = np.linspace(-10, 10)
ydata = np.sin(xdata + np.random.randint(0, 100) * 0.01 * np.pi)
curve_item = make.curve(xdata, ydata, color="b")
widget.plot.add_item(curve_item)
self.layout().addWidget(widget, irow, icol, 1, 1)
class LoadTest(QW.QMainWindow):
"""Main window containing a tab widget with a large number of plots"""
def __init__(self, nplots=150, ncols=6, nrows=5):
super().__init__()
self.tabw = QW.QTabWidget()
self.setCentralWidget(self.tabw)
irow, icol, itab = 0, 0, 0
add_tab_at_next_step = True
for iplt in range(nplots):
if add_tab_at_next_step:
plottab = self.add_tab(itab)
add_tab_at_next_step = False
plottab.add_plot(iplt, irow, icol)
icol += 1
if icol == ncols:
icol = 0
irow += 1
if irow == nrows:
irow = 0
itab += 1
add_tab_at_next_step = True
self.refresh()
def add_tab(self, itab):
"""Add a tab to the tab widget"""
plottab = PlotTab()
self.tabw.addTab(plottab, "Tab #%d" % (itab + 1))
return plottab
def refresh(self):
"""Force window to show up and refresh (for test purpose only)"""
self.show()
QW.QApplication.processEvents()
@pytest.mark.skip(reason="Not relevant in automated test suite")
def test_loadtest():
"""Run load test"""
with qt_app_context(exec_loop=True):
# import time
# t0 = time.time()
# with cProfile.Profile() as pr:
win = LoadTest(nplots=60, ncols=6, nrows=5)
win.show()
# print((time.time() - t0))
# with open('profiling_stats.txt', 'w') as stream:
# stats = Stats(pr, stream=stream)
# stats.strip_dirs()
# stats.sort_stats('cumulative')
# stats.dump_stats('.prof_stats')
# stats.print_stats()
if __name__ == "__main__":
test_loadtest()