Skip to content

Commit

Permalink
Speed up unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed Mar 7, 2020
1 parent f24d10b commit 197a4f0
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/QtTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def tearDownClass(cls):
def setUp(self):
ProtocolSniffer.BUFFER_SIZE_MB = 0.5
self.form = MainController()
self.form.ui.actionAuto_detect_new_signals.setChecked(True)
self.form.ui.actionAuto_detect_new_signals.setChecked(False)
if self.SHOW:
self.form.show()

Expand Down
2 changes: 1 addition & 1 deletion tests/SpectrogramTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def stft(self, samples, window_size, overlap_factor=0.5, window_function=np.hann
return np.fft.fft(frames)

def setUp(self):
self.signal = Signal(get_path_for_data_file("two_participants.coco"), "test")
self.signal = Signal(get_path_for_data_file("two_participants.complex16s"), "test")

def test_numpy_impl(self):
sample_rate = 1e6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_auto_interpretation_ask(self):
self.assertEqual(demodulate(ask_signal, mod_type, bit_length, center, noise, tolerance)[0], "b25b6db6c80")

def test_auto_interpretation_overshoot_ook(self):
data = Signal(get_path_for_data_file("ook_overshoot.coco"), "").iq_array
data = Signal(get_path_for_data_file("ook_overshoot.complex16s"), "").iq_array
result = AutoInterpretation.estimate(data)
self.assertEqual(result["modulation_type"], "ASK")
self.assertEqual(result["bit_length"], 500)
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_auto_interpretation_elektromaten(self):
self.assertTrue(demodulated[i].startswith("8"))

def test_auto_interpretation_homematic(self):
data = Signal(get_path_for_data_file("homematic.coco"), "").iq_array
data = Signal(get_path_for_data_file("homematic.complex32s"), "").iq_array

result = AutoInterpretation.estimate(data)
mod_type, bit_length = result["modulation_type"], result["bit_length"]
Expand Down
2 changes: 1 addition & 1 deletion tests/auto_interpretation/test_center_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_ask_50_center_detection(self):
self.assertLessEqual(center, 0.65, msg="{}/{}".format(start, end))

def test_homematic_center_detection(self):
data = Signal(get_path_for_data_file("homematic.coco"), "").iq_array.data
data = Signal(get_path_for_data_file("homematic.complex32s"), "").iq_array.data
rect = afp_demod(data, 0.0012, "FSK")

msg1 = rect[17719:37861]
Expand Down
Binary file removed tests/data/homematic.coco
Binary file not shown.
Binary file added tests/data/homematic.complex32s
Binary file not shown.
Binary file removed tests/data/ook_overshoot.coco
Binary file not shown.
133 changes: 133 additions & 0 deletions tests/data/ook_overshoot.complex16s

Large diffs are not rendered by default.

Binary file removed tests/data/pwm.coco
Binary file not shown.
Binary file added tests/data/pwm.complex16s
Binary file not shown.
Binary file removed tests/data/two_participants.coco
Binary file not shown.
Binary file added tests/data/two_participants.complex16s
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_advanced_modulation_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_pause_threshold(self):
def test_message_length_divisor(self):
assert isinstance(self.form, MainController)
self.form.ui.actionAuto_detect_new_signals.setChecked(False)
self.add_signal_to_form("pwm.coco")
self.add_signal_to_form("pwm.complex16s")
signal_frame = self.form.signal_tab_controller.signal_frames[0] # type: SignalFrame
signal_frame.ui.spinBoxNoiseTreshold.setValue(0.0525)
signal_frame.ui.cbModulationType.setCurrentText("ASK")
Expand All @@ -34,7 +34,7 @@ def test_message_length_divisor(self):
protocol = signal_frame.proto_analyzer

bits = "1000100010001110100011101000111010001000100011101000111010001110100011101000111010001110111011101"
pauses = [77114, 77112, 58221]
pauses = [77114, 77112, 58220]
for i in range(3):
self.assertEqual(protocol.plain_bits_str[i], bits, msg=str(i))
self.assertEqual(protocol.messages[i].pause, pauses[i], msg=str(i))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_analysis_tab_GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
class TestAnalysisTabGUI(QtTestCase):
def setUp(self):
super().setUp()
self.add_signal_to_form("two_participants.coco")
self.add_signal_to_form("two_participants.complex16s")
assert isinstance(self.form, MainController)
self.cfc = self.form.compare_frame_controller # type: CompareFrameController
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.setValue(0)
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.setValue(-0.0574)
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.editingFinished.emit()
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxTolerance.setValue(10)
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxTolerance.editingFinished.emit()

def test_analyze_button_fsk(self):
assert isinstance(self.cfc, CompareFrameController)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_crc_gui_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def test_cc1101_crc(self):

def test_checksum_in_generation_tab(self):
self.add_signal_to_form("esaver.complex16s")
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.setValue(0.3692)
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.editingFinished.emit()

self.form.compare_frame_controller.add_protocol_label(4, 6, 0, 1, edit_label_name=False)
checksum_fieldtype = next(
ft for ft in self.form.compare_frame_controller.field_types if ft.function == ft.Function.CHECKSUM)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class TestPlugins(QtTestCase):
def setUp(self):
super().setUp()
self.add_signal_to_form("esaver.complex16s")
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.setValue(0.3692)
self.form.signal_tab_controller.signal_frames[0].ui.spinBoxCenterOffset.editingFinished.emit()

self.sframe = self.form.signal_tab_controller.signal_frames[0]
self.cframe = self.form.compare_frame_controller # type: CompareFrameController
self.form.ui.tabWidget.setCurrentIndex(1)
Expand Down Expand Up @@ -68,6 +71,14 @@ def test_zero_hide_plugin_function(self):
zh = ZeroHidePlugin()
zh.following_zeros = 3
self.add_signal_to_form("ask.complex")
self.form.signal_tab_controller.signal_frames[1].ui.cbModulationType.setCurrentText("ASK")

self.form.signal_tab_controller.signal_frames[1].ui.spinBoxCenterOffset.setValue(-0.3938)
self.form.signal_tab_controller.signal_frames[1].ui.spinBoxCenterOffset.editingFinished.emit()

self.form.signal_tab_controller.signal_frames[1].ui.spinBoxSamplesPerSymbol.setValue(300)
self.form.signal_tab_controller.signal_frames[1].ui.spinBoxSamplesPerSymbol.editingFinished.emit()

self.form.ui.tabWidget.setCurrentIndex(1)
test_bits = "1011001001011011011011011011011011001000000"
self.assertEqual(self.cframe.proto_analyzer.decoded_proto_bits_str[3], test_bits)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_save_and_load_participants(self):

self.add_signal_to_form("esaver.complex16s")
self.assertEqual(len(self.form.signal_tab_controller.signal_frames[0].proto_analyzer.messages), 3)
self.add_signal_to_form("two_participants.coco")
self.add_signal_to_form("two_participants.complex16s")
self.assertEqual(len(self.form.signal_tab_controller.signal_frames[1].proto_analyzer.messages), 18)
self.add_signal_to_form("fsk.complex")
self.assertEqual(len(self.form.signal_tab_controller.signal_frames[2].proto_analyzer.messages), 1)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_protocol_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_fsk_freq_detection(self):
self.assertEqual(3, int(freq / 10000)) # Freq for 0 is 30K

def test_get_rssi_of_message(self):
signal = Signal(get_path_for_data_file("two_participants.coco"), "RSSI-Test")
signal = Signal(get_path_for_data_file("two_participants.complex16s"), "RSSI-Test")
signal.modulation_type = "FSK"
signal.samples_per_symbol = 100
signal.center = -0.0507
Expand Down
12 changes: 8 additions & 4 deletions tests/test_send_recv_dialog_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tests.QtTestCase import QtTestCase
from tests.utils_testing import get_path_for_data_file
from urh import settings
from urh.controller.GeneratorTabController import GeneratorTabController
from urh.controller.MainController import MainController
from urh.controller.dialogs.ContinuousSendDialog import ContinuousSendDialog
from urh.controller.dialogs.ReceiveDialog import ReceiveDialog
Expand Down Expand Up @@ -216,7 +217,10 @@ def test_continuous_send_dialog(self):

port = self.get_free_port()

gframe = self.form.generator_tab_controller
gframe = self.form.generator_tab_controller # type: GeneratorTabController
for msg in gframe.table_model.protocol.messages:
msg.pause = 5000

expected = IQArray(None, np.float32, gframe.total_modulated_samples)
expected = gframe.modulate_data(expected)
current_index = Value("L", 0)
Expand Down Expand Up @@ -288,13 +292,13 @@ def test_sniff(self):
sniff_dialog.ui.btnStart.click()

for msg in generator_frame.table_model.protocol.messages:
msg.pause = 500e3
msg.pause = 100e3

generator_frame.ui.btnNetworkSDRSend.click()

n = 0
while generator_frame.network_sdr_plugin.is_sending and n < 30:
time.sleep(1)
while generator_frame.network_sdr_plugin.is_sending and n < 50:
time.sleep(0.25)
print("Waiting for messages")

self.assertFalse(generator_frame.network_sdr_plugin.is_sending)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class TestSpectrogram(QtTestCase):
def setUp(self):
self.signal = Signal(self.get_path_for_filename("two_participants.coco"), "test")
self.signal = Signal(self.get_path_for_filename("two_participants.complex16s"), "test")
self.spectrogram = Spectrogram(self.signal.iq_array.data)

def test_create_spectrogram_image(self):
Expand All @@ -35,7 +35,7 @@ def test_channel_separation_with_negative_frequency(self):

def test_cancel_filtering(self):
super().setUp()
self.add_signal_to_form("two_participants.coco")
self.add_signal_to_form("two_participants.complex16s")
signal_frame = self.form.signal_tab_controller.signal_frames[0]
signal_frame.ui.cbSignalView.setCurrentIndex(2)
signal_frame.ui.spinBoxSelectionStart.setValue(100)
Expand Down

0 comments on commit 197a4f0

Please sign in to comment.