Skip to content

Commit

Permalink
Solution for linux failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FillBk committed Apr 16, 2024
1 parent efb2887 commit f3c39b5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
28 changes: 19 additions & 9 deletions test/asammdf/gui/widgets/test_FileWidget_Shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ def test_FileWidget_Shortcut_Key_Period(self):
- Press key "Period" <<.>> twice
Evaluate:
- Evaluate number of background colors must be greater when signal is without dots
- Evaluate number of background colors, it must be greater when signal is without dots
"""
# Setup
self.create_window("Plot")
self.add_channels([35])
self.add_channels(channels_list=[35])
plot = self.widget.mdi_area.subWindowList()[0].widget()
# Remove bookmarks if plot is with bookmarks
if not plot.bookmark_btn.isFlat():
Expand All @@ -391,18 +391,27 @@ def test_FileWidget_Shortcut_Key_Period(self):
QTest.mouseClick(plot.hide_axes_btn, Qt.MouseButton.LeftButton)
self.processEvents(0.1)

# Find first dot
x = Pixmap.search_signal_extremes_by_ax(plot.plot.grab(), plot.channel_selection.topLevelItem(0), "X")[0]
y = Pixmap.search_signal_extremes_by_ax(
plot.plot.grab(QRect(x, 0, 1, plot.plot.height())), plot.channel_selection.topLevelItem(0), "Y"
)[0]
rect = QRect(x - 3, y - 3, 4, 4)
# One dot + 1 pixel surface
# Displayed signal
sig = plot.plot.signals[0]
# Coordinates for viewbox, second dot in the center of visual box
x_step = (sig.timestamps[1] - sig.timestamps[0]) / 10
y_step = (sig.samples[1] - sig.samples[0]) / 10
x, y = sig.timestamps[1] - x_step, sig.samples[1] - y_step
w, h = sig.timestamps[1] + x_step, sig.samples[1] + y_step
# Set X and Y ranges for viewbox
plot.plot.viewbox.setXRange(x, w, padding=0)
plot.plot.viewbox.setYRange(y, h, padding=0)
self.processEvents(0.1)
# Get rect from the center of graphical plot
rect = QRect(int(plot.plot.width() / 2) - 4, int(plot.plot.height() / 2) - 4, 8, 9)

# Color map of selected rect
pm_with_dots = Pixmap.color_map(plot.plot.grab(rect))
# Black coverage
with_dots_black_coverage = 0
for cov in pm_with_dots.values():
with_dots_black_coverage += cov.count(Pixmap.COLOR_BACKGROUND)

# Event
QTest.keySequence(self.widget, QKeySequence(self.shortcuts["set_line_style"]))
self.processEvents(0.1)
Expand All @@ -412,6 +421,7 @@ def test_FileWidget_Shortcut_Key_Period(self):
without_dots_black_coverage = 0
for cov in pm_without_dots.values():
without_dots_black_coverage += cov.count(Pixmap.COLOR_BACKGROUND)

# Evaluate
self.assertGreater(without_dots_black_coverage, with_dots_black_coverage)

Expand Down
3 changes: 2 additions & 1 deletion test/asammdf/gui/widgets/test_MainWindow_Shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def openFile(self, measurement_files):
-------
"""
self.processEvents(0.1)
with mock.patch("asammdf.gui.widgets.main.QtWidgets.QFileDialog.getOpenFileNames") as mo_getOpenFileNames:
if measurement_files:
if isinstance(measurement_files, list):
Expand All @@ -62,7 +63,7 @@ def openFile(self, measurement_files):
else:
mo_getOpenFileNames.return_value = [self.measurement_file], ""
QTest.keySequence(self.mw, QKeySequence("Ctrl+O"))
self.processEvents()
self.processEvents(0.1)
mo_getOpenFileNames.assert_called()

def tearDown(self):
Expand Down
1 change: 1 addition & 0 deletions test/asammdf/gui/widgets/test_PlotWidget_ContextMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,7 @@ def test_Menu_EnableDisable_Action_DisableAll(self):
# Add Channels to Group
group_channel = self.plot.channel_selection.findItems("A", QtCore.Qt.MatchFlags())[0]
self.move_channel_to_group(src=self.plot_channel_a, dst=group_channel)
self.processEvents(1)
self.processEvents(0.1)

# Ensure that all items are enabled
Expand Down
3 changes: 2 additions & 1 deletion test/asammdf/gui/widgets/test_PlotWidget_Shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ def test_Plot_Plot_Shortcut_Key_Ctrl_R(self):
mo_RangeEditor.assert_called()
self.assertEqual(self.channels[0].ranges, range_editor_result)

self.processEvents(5)
self.processEvents(1)
self.mouseClick_WidgetItem(self.channels[0])
for _ in range(100):
self.processEvents(0.01)

Expand Down

0 comments on commit f3c39b5

Please sign in to comment.