From 02d167c11d523b69cbd131affec58c83efbaf6f7 Mon Sep 17 00:00:00 2001 From: "Bodnariuc Florin (uif30975)" Date: Tue, 3 Dec 2024 02:56:07 +0200 Subject: [PATCH] last test for bus tab... --- .../batch/test_BatchWidget_Tab_BusLogging.py | 84 +++++++++++++------ .../test_BatchWidget_Tab_ModifyAndExport.py | 2 +- .../gui/widgets/test_BaseBatchWidget.py | 18 +++- 3 files changed, 78 insertions(+), 26 deletions(-) diff --git a/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_BusLogging.py b/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_BusLogging.py index 8e02c8246..2472e6b59 100644 --- a/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_BusLogging.py +++ b/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_BusLogging.py @@ -43,6 +43,13 @@ def setUp(self): self.assertEqual(self.widget.lin_database_list.count(), 0) def load_database(self, path: Path | str | None = None, is_can=True): + """ + Load database to CAN/LIN database list + Parameters + ---------- + path := path to .dbc file; if None: default .dbc path will be used + is_can := CAN or LIN + """ if not path: path = self.dbc_path with mock.patch("asammdf.gui.widgets.batch.QtWidgets.QFileDialog.getOpenFileNames") as mo_getOpenFileNames: @@ -52,6 +59,27 @@ def load_database(self, path: Path | str | None = None, is_can=True): else: QtTest.QTest.mouseClick(self.widget.load_lin_database_btn, QtCore.Qt.MouseButton.LeftButton) + def get_prefix(self): + """ + Get prefix for channels names. + Example: + - 'CAN1.OBD2.' + Returns + ------- + prefix: str + """ + # Prepare expected results + with OpenMDF(self.mdf_path) as mdf_file, open(self.dbc_path) as dbc_file: + for key, value in mdf_file.bus_logging_map.items(): + if value: + prefix = key + for new_key, new_value in value.items(): + if value: + prefix += str(new_key) + self.assertTrue(prefix) # there is a suffix for feature channels + prefix += "." + DBC.BO(dbc_file.readlines()).name + "." + return prefix + def test_load_can_database_btn(self): """ Events: @@ -173,17 +201,22 @@ def test_extract_bus_btn(self): self.assertEqual(max(timestamps_max), max_from_mdf) def test_extract_bus_csv_btn_0(self): - """ """ + """ + When QThreads are running, event-loops needs to be processed. + Events: + - Set prefix text + - Ensure that all checkboxes are unchecked + - Press PushButton Export to csv. + + Evaluate: + - CSV files was created. + - New channels was created from .dbc and .mf4 files + - CSV files is mf4 channels groups + - Channels names and groups names contain prefix + - Signals samples are added to CSV + """ # Prepare expected results - with OpenMDF(self.mdf_path) as mdf_file, open(self.dbc_path) as dbc_file: - for key, value in mdf_file.bus_logging_map.items(): - if value: - prefix = key - for new_key, new_value in value.items(): - if value: - prefix += str(new_key) - self.assertTrue(prefix) # there is a suffix for feature channels - prefix += "." + DBC.BO(dbc_file.readlines()).name + "." + prefix = self.get_prefix() to_replace = [" ", '"', ":"] # Precondition @@ -194,7 +227,7 @@ def test_extract_bus_csv_btn_0(self): self.toggle_checkboxes(widget=self.widget.extract_bus_tab, check=False) # uncheck all checkboxes # Expected results - output_file = Path.with_suffix(self.mdf_path, f".bus_logging.mf4") + output_file = Path.with_suffix(self.mdf_path, ".bus_logging.mf4") # Set Prefix self.widget.prefix.setText(self.id().split(".")[-1]) @@ -247,17 +280,20 @@ def test_extract_bus_csv_btn_0(self): self.assertAlmostEqual(ch.timestamps.max(), table.timestamps.max(), places=10) def test_extract_bus_csv_btn_1(self): - """ """ - # Prepare expected results - with OpenMDF(self.mdf_path) as mdf_file, open(self.dbc_path) as dbc_file: - for key, value in mdf_file.bus_logging_map.items(): - if value: - prefix = key - for new_key, new_value in value.items(): - if value: - prefix += str(new_key) - self.assertTrue(prefix) # there is a suffix for feature channels - prefix += "." + DBC.BO(dbc_file.readlines()).name + "." + """ + Events: + - Set prefix text + - Ensure that all checkboxes are checked + - Press PushButton Export to csv. + + Evaluate: + - CSV file is created + - Timestamps start from 0 + measurement start time + - CSV file contain new channels from .mf4 file + - Channels names contain prefix + - Signals samples are added to CSV + """ + prefix = self.get_prefix() to_replace = [" ", '"', ":"] # Precondition @@ -268,8 +304,8 @@ def test_extract_bus_csv_btn_1(self): self.toggle_checkboxes(widget=self.widget.extract_bus_tab, check=True) # uncheck all checkboxes # Expected results - csv_path = Path.with_suffix(self.mdf_path, f".bus_logging.csv") - output_file = Path.with_suffix(self.mdf_path, f".bus_logging.mf4") + csv_path = Path.with_suffix(self.mdf_path, ".bus_logging.csv") + output_file = Path.with_suffix(self.mdf_path, ".bus_logging.mf4") # Set Prefix self.widget.prefix.setText(self.id().split(".")[-1]) diff --git a/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_ModifyAndExport.py b/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_ModifyAndExport.py index eb35276df..dc8dbb58d 100644 --- a/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_ModifyAndExport.py +++ b/test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_ModifyAndExport.py @@ -1,9 +1,9 @@ #!/usr/bin/env python import datetime -import unittest from math import ceil from pathlib import Path from random import randint +import unittest from unittest import mock import urllib import urllib.request diff --git a/test/asammdf/gui/widgets/test_BaseBatchWidget.py b/test/asammdf/gui/widgets/test_BaseBatchWidget.py index 84bc8a559..0a1e0bc10 100644 --- a/test/asammdf/gui/widgets/test_BaseBatchWidget.py +++ b/test/asammdf/gui/widgets/test_BaseBatchWidget.py @@ -1,4 +1,3 @@ -import unittest from collections.abc import Iterable, Sequence import os from pathlib import Path @@ -118,6 +117,13 @@ def get_selected_groups(self, channels: list) -> dict: return groups def mouse_click_on_btn_with_progress(self, btn: QPushButton): + """ + Click on the button with progress bar and wait until progress bar will be closed. + + Parameters + ---------- + btn := QPushButton + """ # Mouse click on button QTest.mouseClick(btn, QtCore.Qt.MouseButton.LeftButton) # Wait for progress bar thread to finish @@ -126,6 +132,16 @@ def mouse_click_on_btn_with_progress(self, btn: QPushButton): self.processEvents() def toggle_checkboxes(self, widget: QWidget, check=True): + """ + Iterate given widget to find QCheckBox items. + All founded checkboxes will have 'check' check state + + Parameters + ---------- + widget := widget to iterate + check := check state (True/False) + + """ # set checkboxes check state for checkbox in widget.findChildren(QtWidgets.QCheckBox): if checkbox.isChecked() != check: