Skip to content

Commit

Permalink
mini changes
Browse files Browse the repository at this point in the history
  • Loading branch information
F-Bk committed Nov 5, 2024
1 parent 5381292 commit 88d3644
Showing 1 changed file with 28 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def setUp(self):
"""
super().setUp()
self.copy_mdf_files_to_workspace()
self.measurement_file = str(Path(self.test_workspace, self.default_test_file))
self.measurement_file = str(Path(self.resource, self.default_test_file))

self.setUpBatchWidget(measurement_files=[self.measurement_file])

Expand All @@ -86,7 +85,16 @@ def setUp(self):
randint(0, int(count / 2) - 1), randint(int(count / 2) + 1, count - 1)
)

def test_Apply_as_MDF(self):
# set test_workspace folder as output folder
with mock.patch(
"asammdf.gui.widgets.batch.QtWidgets.QFileDialog.getExistingDirectory"
) as mo_getExistingDirectory:
mo_getExistingDirectory.return_value = self.test_workspace
QtTest.QTest.mouseClick(self.widget.modify_output_folder_btn, QtCore.Qt.MouseButton.LeftButton)

self.assertEqual(self.widget.modify_output_folder.text().strip(), self.test_workspace)

def test_output_format_MDF(self):
"""
When QThreads are running, event-loops needs to be processed.
Events:
Expand All @@ -97,12 +105,12 @@ def test_Apply_as_MDF(self):
- File was created.
- Ensure that output file has only selected channels
"""
# Expected result
saved_file = Path(self.test_workspace, self.default_test_file)

# Ensure output format
self.widget.output_format.setCurrentText("MDF")

# Expected result
saved_file = Path(self.test_workspace, self.default_test_file.replace(".", ".modified."))

# Event
QtTest.QTest.mouseClick(self.widget.apply_btn, QtCore.Qt.MouseButton.LeftButton)
# Wait for thread to finish
Expand All @@ -117,7 +125,7 @@ def test_Apply_as_MDF(self):
for channel in self.selected_channels:
self.assertIn(channel, mdf_file.channels_db.keys())

def test_Apply_as_ASC(self):
def test_output_format_ASC(self):
"""
When QThreads are running, event-loops needs to be processed.
Events:
Expand Down Expand Up @@ -148,7 +156,7 @@ def test_Apply_as_ASC(self):
with open(saved_file) as asc_file:
self.assertEqual(asc_file.read(), expected_text)

def test_Apply_as_CSV(self):
def test_output_format_CSV(self):
"""
When QThreads are running, event-loops needs to be processed.
Events:
Expand Down Expand Up @@ -183,7 +191,7 @@ def test_Apply_as_CSV(self):

# ToDo is necessary to evaluate dataframe values (for each signal, it's value at specific timestamp)?

def test_Apply_as_HDF5(self):
def test_output_format_HDF5(self):
"""
When QThreads are running, event-loops needs to be processed.
Events:
Expand Down Expand Up @@ -215,42 +223,7 @@ def test_Apply_as_HDF5(self):
for channel in group:
self.assertIn(channel, value)


class TestModifyAndExport(TestBatchWidget):
def setUp(self):
"""
Events
- Open 'BatchWidget' with valid measurement.
- Select random channels
- Set test workspace folder as output folder
Evaluate
- Modify output folder line text is equal to test workspace folder
"""
super().setUp()
self.test_file = Path(self.resource, self.default_test_file)

self.setUpBatchWidget(measurement_files=[str(self.test_file)])

# Go to Tab: "Modify & Export": Index 1
self.widget.aspects.setCurrentIndex(self.modify_aspect)
self.widget.filter_view.setCurrentText("Natural sort")
self.processEvents(0.1)

count = self.widget.filter_tree.topLevelItemCount()
self.channels = self.select_channels(randint(0, int(count / 2) - 1), randint(int(count / 2) + 1, count - 1))
self.output_file = Path(self.test_workspace, self.default_test_file)

# set test_workspace folder as output folder
with mock.patch(
"asammdf.gui.widgets.batch.QtWidgets.QFileDialog.getExistingDirectory"
) as mo_getExistingDirectory:
mo_getExistingDirectory.return_value = self.test_workspace
QtTest.QTest.mouseClick(self.widget.modify_output_folder_btn, QtCore.Qt.MouseButton.LeftButton)

self.assertEqual(self.widget.modify_output_folder.text().strip(), self.test_workspace)

def test_cut_group_0(self):
def test_cut_checkbox_0(self):
"""
Events
- Check cut group checkbox
Expand All @@ -266,13 +239,16 @@ def test_cut_group_0(self):
- Timestamps stop for all channels is equal to difference between stop and start time
"""
# Expected values
with self.OpenMDF(self.test_file) as mdf_file:

self.output_file = Path(self.test_workspace, self.default_test_file)

with self.OpenMDF(self.measurement_file) as mdf_file:
self.start_time = mdf_file.start_time.astimezone().replace(tzinfo=None)
self.ts_min = min(
[
ch.timestamps.min()
for ch in mdf_file.iter_channels()
if ch.timestamps.min() != 0 and ch.name in self.channels
if ch.timestamps.min() != 0 and ch.name in self.selected_channels
]
)

Expand Down Expand Up @@ -303,7 +279,7 @@ def test_cut_group_0(self):
self.assertEqual(channel.timestamps.min(), 0)
self.assertEqual(channel.timestamps.max(), stop_cut - start_cut)

def test_cut_group_1(self):
def test_cut_checkbox_1(self):
"""
Events
- Check cut group checkbox
Expand All @@ -317,13 +293,15 @@ def test_cut_group_1(self):
- Timestamps stop for all channels is equal to difference between stop and start time
"""
# Expected values
with self.OpenMDF(self.test_file) as mdf_file:
self.output_file = Path(self.test_workspace, self.default_test_file)

with self.OpenMDF(self.measurement_file) as mdf_file:
self.start_time = mdf_file.start_time
self.ts_min = min(
[
ch.timestamps.min()
for ch in mdf_file.iter_channels()
if ch.timestamps.min() != 0 and ch.name in self.channels
if ch.timestamps.min() != 0 and ch.name in self.selected_channels
]
)

Expand Down

0 comments on commit 88d3644

Please sign in to comment.