Skip to content

Commit

Permalink
Improve tests (jopohl#730)
Browse files Browse the repository at this point in the history
Improve performance of tests and fix some minor bugs in insert sine dialog and "apply to all" action
  • Loading branch information
jopohl authored Mar 3, 2020
1 parent 34397a4 commit 90d8246
Show file tree
Hide file tree
Showing 32 changed files with 200 additions and 221 deletions.
23 changes: 9 additions & 14 deletions data/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- script: |
touch tests/show_gui
cp tests/.coveragerc .
pytest --junitxml=junit/test-results.xml --cov=src --cov-config=.coveragerc tests
pytest -s --fulltrace --junitxml=junit/test-results.xml --cov=src --cov-config=.coveragerc tests
displayName: 'Run pytest with coverage'
condition: eq(variables['python.version'], '3.7')
Expand All @@ -67,7 +67,7 @@ jobs:
displayName: 'Generate coverage report'
condition: eq(variables['python.version'], '3.7')
- script: pytest -s -v --junitxml=junit/test-results.xml tests
- script: pytest -s --fulltrace --junitxml=junit/test-results.xml tests
displayName: 'Run pytest without coverage'
condition: ne(variables['python.version'], '3.7')

Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
assetUploadMode: 'replace'
addChangeLog: true

- script: pytest -s -v --junitxml=junit/test-results.xml tests
- script: pytest -s --fulltrace --junitxml=junit/test-results.xml tests
displayName: 'Run pytest on windows'

- task: PublishTestResults@2
Expand All @@ -204,19 +204,14 @@ jobs:
urh autoclose
displayName: 'Testrun'
- job: 'OSX'
- job: 'macOS'
pool:
vmImage: 'macOS-10.14'

strategy:
matrix:
Python37:
python.version: '3.7'

steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '$(python.version)'
versionSpec: '3.7'

- script: |
git clone --depth 1 https://gitlab.com/jopohl/sdr_drivers
Expand All @@ -229,13 +224,13 @@ jobs:
- script: |
python -m pip install --upgrade pip
pip install -r data/requirements.txt
pip install pytest pytest-faulthandler
python -m pip install --upgrade -r data/requirements.txt
python -m pip install --upgrade pytest pytest-faulthandler pytest-timeout
displayName: 'Install dependencies'
- script: |
brew install portaudio hackrf librtlsdr airspy
pip install --upgrade wheel twine six appdirs packaging setuptools pyinstaller pyaudio
python -m pip install --upgrade wheel twine six appdirs packaging setuptools pyinstaller pyaudio
python -c "import tempfile, os; open(os.path.join(tempfile.gettempdir(), 'urh_releasing'), 'w').close()"
displayName: "Install build dependencies"
Expand Down Expand Up @@ -293,7 +288,7 @@ jobs:
TWINE_PASSWORD: $(twine.password)
TWINE_REPOSITORY_URL: "https://upload.pypi.org/legacy/"

- script: pytest -s -v --junitxml=junit/test-results.xml tests
- script: pytest -s --fulltrace --timeout=600 --junitxml=junit/test-results.xml tests
displayName: 'Run pytest on macOS'

- task: PublishTestResults@2
Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/MainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, *args):
self.ui.listViewParticipants.setModel(self.participant_legend_model)

gtc = self.generator_tab_controller
gtc.ui.splitter.setSizes([gtc.width() / 0.7, gtc.width() / 0.3])
gtc.ui.splitter.setSizes([int(gtc.width() / 0.7), int(gtc.width() / 0.3)])

self.ui.tab_generator.layout().addWidget(self.generator_tab_controller)

Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/SignalTabController.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def on_apply_to_all_clicked(self, signal: Signal):
proto_needs_update = True

if frame.signal.noise_threshold != signal.noise_threshold:
frame.signal.noise_threshold = signal.noise_threshold
frame.signal.noise_threshold_relative = signal.noise_threshold_relative
proto_needs_update = True

if frame.signal.samples_per_symbol != signal.samples_per_symbol:
Expand Down
4 changes: 2 additions & 2 deletions src/urh/controller/SimulatorTabController.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __init__(self, compare_frame_controller: CompareFrameController,
util.set_splitter_stylesheet(self.ui.splitter)
util.set_splitter_stylesheet(self.ui.splitterLeftRight)

self.ui.splitter.setSizes([self.width() / 0.7, self.width() / 0.3])
self.ui.splitter.setSizes([int(self.width() / 0.7), int(self.width() / 0.3)])

self.ui.treeProtocols.setHeaderHidden(True)
self.tree_model = self.generator_tab_controller.tree_model
Expand Down Expand Up @@ -120,7 +120,7 @@ def __init__(self, compare_frame_controller: CompareFrameController,
frame.layout().setContentsMargins(0, 0, 0, 0)
self.ui.tabWidget.setCornerWidget(frame)

self.ui.splitterLeftRight.setSizes([0.2 * self.width(), 0.8 * self.width()])
self.ui.splitterLeftRight.setSizes([int(0.2 * self.width()), int(0.8 * self.width())])

self.create_connects()

Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/dialogs/ProtocolLabelDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, message: Message, viewtype: int, selected_index=None, parent=
self.setWindowTitle(self.tr("Edit Protocol Labels From Message Type %s") % message.message_type.name)

self.configure_special_config_tabs()
self.ui.splitter.setSizes([self.height() / 2, self.height() / 2])
self.ui.splitter.setSizes([int(self.height() / 2), int(self.height() / 2)])

self.create_connects()

Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/dialogs/SendRecvDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, project_manager: ProjectManager, is_tx: bool, continuous_send
except TypeError:
pass

self.ui.splitter.setSizes([0.4 * self.width(), 0.6 * self.width()])
self.ui.splitter.setSizes([int(0.4 * self.width()), int(0.6 * self.width())])

@property
def is_rx(self) -> bool:
Expand Down
34 changes: 23 additions & 11 deletions src/urh/plugins/InsertSine/InsertSinePlugin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import os

import numpy as np
Expand All @@ -10,6 +11,7 @@
from urh.signalprocessing.IQArray import IQArray
from urh.ui.painting.SceneManager import SceneManager
from urh.util.Formatter import Formatter
from urh.util.Logger import logger


class InsertSinePlugin(SignalEditorPlugin):
Expand Down Expand Up @@ -38,7 +40,11 @@ def __init__(self):
def dialog_ui(self) -> QDialog:
if self.__dialog_ui is None:
dir_name = os.path.dirname(os.readlink(__file__)) if os.path.islink(__file__) else os.path.dirname(__file__)

logging.getLogger().setLevel(logging.WARNING)
self.__dialog_ui = uic.loadUi(os.path.realpath(os.path.join(dir_name, "insert_sine_dialog.ui")))
logging.getLogger().setLevel(logger.level)

self.__dialog_ui.setAttribute(Qt.WA_DeleteOnClose)
self.__dialog_ui.setModal(True)
self.__dialog_ui.doubleSpinBoxAmplitude.setValue(self.__amplitude)
Expand All @@ -62,7 +68,7 @@ def dialog_ui(self) -> QDialog:

@property
def amplitude(self) -> float:
return self.__amplitude * IQArray.min_max_for_dtype(self.original_data.dtype)[1]
return self.__amplitude

@amplitude.setter
def amplitude(self, value: float):
Expand Down Expand Up @@ -126,8 +132,8 @@ def create_dialog_connects(self):
self.on_double_spin_box_sample_rate_editing_finished)
self.dialog_ui.doubleSpinBoxNSamples.editingFinished.connect(self.on_spin_box_n_samples_editing_finished)
self.dialog_ui.lineEditTime.editingFinished.connect(self.on_line_edit_time_editing_finished)
self.dialog_ui.btnAbort.clicked.connect(self.on_btn_abort_clicked)
self.dialog_ui.btnOK.clicked.connect(self.on_btn_ok_clicked)
self.dialog_ui.buttonBox.accepted.connect(self.on_button_box_accept)
self.dialog_ui.buttonBox.rejected.connect(self.on_button_box_reject)
self.__dialog_ui.finished.connect(self.on_dialog_finished)

def get_insert_sine_dialog(self, original_data, position, sample_rate=None, num_samples=None) -> QDialog:
Expand All @@ -154,10 +160,16 @@ def draw_sine_wave(self):

QApplication.instance().setOverrideCursor(Qt.WaitCursor)
self.__set_status_of_editable_elements(enabled=False)

t = np.arange(0, self.num_samples) / self.sample_rate
arg = ((2 * np.pi * self.frequency * t + self.phase) * 1j).astype(np.complex64)
self.complex_wave = self.amplitude * np.exp(arg) # type: np.ndarray
self.draw_data = np.insert(self.original_data[:, 0], self.position, self.complex_wave.real)
arg = 2 * np.pi * self.frequency * t + self.phase

self.complex_wave = np.empty(len(arg), dtype=np.complex64)
self.complex_wave.real = np.cos(arg)
self.complex_wave.imag = np.sin(arg)
self.complex_wave = IQArray(self.amplitude * self.complex_wave).convert_to(self.original_data.dtype)

self.draw_data = np.insert(self.original_data[:, 0], self.position, self.complex_wave[:, 0])
y, h = self.dialog_ui.graphicsViewSineWave.view_rect().y(), self.dialog_ui.graphicsViewSineWave.view_rect().height()
self.insert_indicator.setRect(self.position, y - h, self.num_samples, 2 * h + abs(y))

Expand All @@ -168,7 +180,7 @@ def draw_sine_wave(self):

def __set_status_of_editable_elements(self, enabled: bool):
for obj in ("doubleSpinBoxAmplitude", "doubleSpinBoxFrequency", "doubleSpinBoxPhase",
"doubleSpinBoxSampleRate", "doubleSpinBoxNSamples", "lineEditTime", "btnOK"):
"doubleSpinBoxSampleRate", "doubleSpinBoxNSamples", "lineEditTime", "buttonBox"):
getattr(self.dialog_ui, obj).setEnabled(enabled)

def set_time(self):
Expand Down Expand Up @@ -218,13 +230,13 @@ def on_line_edit_time_editing_finished(self):
self.set_time()

@pyqtSlot()
def on_btn_abort_clicked(self):
self.dialog_ui.close()
def on_button_box_reject(self):
self.dialog_ui.reject()

@pyqtSlot()
def on_btn_ok_clicked(self):
def on_button_box_accept(self):
self.insert_sine_wave_clicked.emit()
self.dialog_ui.close()
self.dialog_ui.accept()

@pyqtSlot()
def on_dialog_finished(self):
Expand Down
Loading

0 comments on commit 90d8246

Please sign in to comment.