Skip to content

Commit

Permalink
last test for bus tab...
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Bk committed Dec 3, 2024
1 parent 0ca84d4 commit 02d167c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 26 deletions.
84 changes: 60 additions & 24 deletions test/asammdf/gui/widgets/batch/test_BatchWidget_Tab_BusLogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 17 additions & 1 deletion test/asammdf/gui/widgets/test_BaseBatchWidget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unittest
from collections.abc import Iterable, Sequence
import os
from pathlib import Path
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 02d167c

Please sign in to comment.