Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add unit tests for GUI Widgets. #852

Merged
merged 86 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
e0090c4
Add unittests.
Apr 11, 2023
9f7d4c7
Reformat files.
Apr 11, 2023
fea51b2
Add pytest-timeout deps
Apr 12, 2023
fb08707
Merge branch 'danielhrisca:master' into unittests_gui
tov101 Apr 12, 2023
433f8aa
Fix path
Apr 12, 2023
88afac6
Merge branch 'unittests_gui' of https://github.com/tov101/asammdf
Apr 12, 2023
dbaa4ef
Increase timeout.
Apr 13, 2023
25c57d3
Add shebang..
Apr 13, 2023
5116d95
Add shebang
Apr 13, 2023
f43d234
Reformat in order to support 3.8
Apr 13, 2023
38cfc1b
Increase timeout.
Apr 13, 2023
274fc32
..
Apr 13, 2023
10b688f
...
Apr 13, 2023
5c64e21
Add DISPLAY and XAUTHORITY
Apr 13, 2023
8dd1b66
..
Apr 13, 2023
59b81e9
Debug..
Apr 13, 2023
9360191
retry
Apr 13, 2023
df0e7f1
one more..
Apr 13, 2023
86845c5
..
Apr 13, 2023
da30f5f
Add missing lib.
Apr 13, 2023
bc6123c
Skip some tests.
Apr 18, 2023
ece114a
Add qt dependencies back.
Apr 18, 2023
a84f81c
..
Apr 18, 2023
57d2ffb
Remove skip decorator.
Apr 18, 2023
cf5915b
Freeze pyqtgraph for now.
Apr 18, 2023
07a6a4e
Remove unnecessary parts.
Apr 18, 2023
56750bf
Increase timer.
Apr 18, 2023
28758f0
Debug tests.
Apr 18, 2023
e57c0b1
..
Apr 18, 2023
7f37fe6
retry..
Apr 18, 2023
8ec9554
..
Apr 18, 2023
ca64156
Handle UnboundLocalError
Apr 18, 2023
1fa289c
Fix bugs.
Apr 18, 2023
f7758ee
Increase time for drag and drop test.
Apr 18, 2023
743affc
Try to use QThread for MouseMove action.
Apr 18, 2023
8148cb0
Remove QT_QPA_PLATFORM
Apr 18, 2023
cfea3dc
Try to set QT_QPA_PLATFORM dynamically
Apr 18, 2023
9b6d5f6
Move Release operation in QThread.
Apr 19, 2023
2e408da
Debug
Apr 19, 2023
8dfd556
Set env variable: QT_QPA_PLATFORM
Apr 19, 2023
2af47eb
..
Apr 19, 2023
1dc79ee
Just test it for linux
Apr 19, 2023
cfd8229
..
Apr 19, 2023
be95cf6
retry..
Apr 19, 2023
c88c17d
Retry..
Apr 19, 2023
836caa8
..
Apr 19, 2023
2baf8f2
Retry...
Apr 19, 2023
3f4c2dc
..
Apr 19, 2023
47815f9
Start X Server before.
Apr 19, 2023
a80e5ad
Add Xinit
Apr 19, 2023
6e57c83
Start X Server with sudo
Apr 19, 2023
50c833f
Install zorg.
Apr 19, 2023
3545a00
Debug.
Apr 19, 2023
366e5e4
..
Apr 19, 2023
bc23cf8
Debug..
Apr 19, 2023
454b156
debug..
Apr 19, 2023
10e2e34
......
Apr 19, 2023
eb6d25a
...
Apr 19, 2023
4540a27
retrieve info..
Apr 19, 2023
3aaaf41
....
Apr 19, 2023
3f5b427
Magic..
Apr 19, 2023
e0e2b01
May be this one gold commit?!
Apr 19, 2023
a35e308
Add conditions.
Apr 19, 2023
ed52bb5
Retry..
Apr 19, 2023
51835af
Retry..
Apr 19, 2023
cf79363
..
Apr 19, 2023
371aea8
Revert ?!
Apr 19, 2023
fcfd8a5
Se variables manually.
Apr 19, 2023
aef8b72
Try to set it in python file.
Apr 19, 2023
ac2b402
Try to exclude gui tests in wheel build.
Apr 19, 2023
b6d0888
Try to ignore gui tests in wheel build
Apr 19, 2023
85f012c
add test dependency
Apr 19, 2023
4a09a30
Try to fix dependencies.
Apr 19, 2023
4003a84
retry..
Apr 19, 2023
445d4e1
Fix sintax.
Apr 19, 2023
00ec13e
..
Apr 19, 2023
56c75e5
Fix arg
Apr 19, 2023
b52197f
Change command
Apr 19, 2023
bde05ac
..
Apr 19, 2023
cc94799
...
Apr 19, 2023
1830b93
Fix Builds.
Apr 19, 2023
bdf2aa8
Quit Thread.
Apr 20, 2023
0385229
Try to fix coveralls.yml
Apr 20, 2023
2f8f40b
Run Black and iSort
Apr 20, 2023
e3184b5
Add test for Search Button.
Apr 21, 2023
232e992
Fix syntax error for py38
Apr 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source =
asammdf
omit =
*/asammdf/gui/*
*/asammdf/gui/ui/*
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt install libegl1 libopengl0
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
sudo apt-get install libxcb-xinerama0
sudo apt-get install libxkbcommon-x11-0
fi
pyinstaller asammdf.spec --distpath dist/${RUNNER_OS} --noconfirm --clean

Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@ jobs:
python-version: "3.8"

- name: Install packages
run: pip install tox coveralls
shell: bash
run: |
pip install tox coveralls
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt-get install libegl1 libopengl0
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
sudo apt-get install libxcb-xinerama0
sudo apt-get install libxkbcommon-x11-0
sudo apt-get install xorg
sudo apt-get install -y xvfb
fi

- name: Start Xvfb
run: |
Xvfb :0 -screen 0 1024x768x24 > /dev/null 2>&1 &
export DISPLAY=:0

- name: Run coverage
run: tox -e py38

- name: Stop Xvfb
run: killall Xvfb

# see: https://coveralls-python.readthedocs.io/en/latest/usage/configuration.html#github-actions-support
- name: Upload coverage data to coveralls.io
run: coveralls --service=github
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,30 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install packages
shell: bash
run: |
pip install tox tox-gh-actions
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt-get install libegl1 libopengl0
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
sudo apt-get install libxcb-xinerama0
sudo apt-get install libxkbcommon-x11-0
sudo apt-get install xorg
sudo apt-get install -y xvfb
fi

- name: Start Xvfb
if: matrix.os == 'ubuntu-22.04'
run: |
Xvfb :0 -screen 0 1024x768x24 > /dev/null 2>&1 &
export DISPLAY=:0

# see: https://github.com/ymyzk/tox-gh-actions
- name: Run tests
run: tox

- name: Stop Xvfb
if: matrix.os == 'ubuntu-22.04'
run: killall Xvfb

10 changes: 9 additions & 1 deletion .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ jobs:
run: python -m pip install cibuildwheel

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
shell: bash
env:
CIBW_TEST_COMMAND: "pytest {project}/test --ignore={project}/test/asammdf/gui"
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt-get install libegl1 libopengl0
fi
python -m cibuildwheel --output-dir wheelhouse

- uses: actions/upload-artifact@v3
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ pythonenv*
# Rope project settings
.ropeproject

# PyCharm
.idea/*

# mkdocs documentation
/site

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires = ["numpy", "setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ['py38']
extend-exclude = '''
^/src/asammdf/gui/ui
'''
Expand Down
4 changes: 2 additions & 2 deletions requirements_exe_build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ lxml
natsort
psutil
PySide6==6.2.2
pyqtgraph>=0.12.4; sys_platform=="win32"
pyqtgraph>=0.12.4; sys_platform=="darwin"
pyqtgraph==0.12.4; sys_platform=="win32"
pyqtgraph==0.12.4; sys_platform=="darwin"
pyqtgraph==0.12.4; sys_platform=="linux"
pyqtlet2
pyopengl
Expand Down
3 changes: 2 additions & 1 deletion src/asammdf/blocks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,8 @@ def load_lab(file):
sections[section_name] = s

else:
s.append(line)
if "s" in locals():
s.append(line)

return {name: channels for name, channels in sections.items() if channels}

Expand Down
26 changes: 13 additions & 13 deletions src/asammdf/gui/widgets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,19 +1039,19 @@ def load_channel_list(self, event=None, file_name=None):

elif extension == ".lab":
info = load_lab(file_name)
if info:
section, ok = QtWidgets.QInputDialog.getItem(
None,
"Select section",
"Available sections:",
list(info),
0,
False,
)
if ok:
channels = info[section]
else:
return
if not info:
return
section, ok = QtWidgets.QInputDialog.getItem(
None,
"Select section",
"Available sections:",
list(info),
0,
False,
)
if not ok:
return
channels = info[section]

elif extension in (".cfg", ".txt", ".dspf"):
with open(file_name, "r") as infile:
Expand Down
9 changes: 6 additions & 3 deletions src/asammdf/gui/widgets/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3881,7 +3881,7 @@ def __init__(

if x_axis == "time":
fmt = self._settings.value("plot_xaxis")
if fmt == "seconds":
if fmt == "seconds" or not fmt:
fmt = "phys"
else:
fmt = "phys"
Expand Down Expand Up @@ -6177,12 +6177,13 @@ def open_menu(self, point):
QtCore.QSettings().setValue("plot_cursor_precision", precision)

def update_value(self):
cursor_info_text = ""
if not self.plot.region:
if self.plot.cursor1 is not None:
position = self.plot.cursor1.value()

fmt = self.plot.x_axis.format
if fmt == "phys":
if fmt == "phys" or not fmt:
if self.precision == -1:
cursor_info_text = f"{self.name} = {position}{self.unit}"
else:
Expand All @@ -6195,7 +6196,9 @@ def update_value(self):
seconds=position
)
cursor_info_text = f"{self.name} = {position_date}"
self.setText(cursor_info_text)

if cursor_info_text:
self.setText(cursor_info_text)
else:
self.setText("")

Expand Down
2 changes: 1 addition & 1 deletion src/asammdf/gui/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def get_data(item):

drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.exec_(QtCore.Qt.MoveAction)
drag.exec(QtCore.Qt.MoveAction)


class FileTreeItem(QtWidgets.QTreeWidgetItem):
Expand Down
Empty file added test/asammdf/__init__.py
Empty file.
66 changes: 66 additions & 0 deletions test/asammdf/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
import os
import sys

PYSIDE = "PySide"
PYSIDE2 = "PySide2"
PYSIDE6 = "PySide6"
PYQT4 = "PyQt4"
PYQT5 = "PyQt5"
PYQT6 = "PyQt6"

QT_LIB = os.getenv("PYQTGRAPH_QT_LIB")

if QT_LIB is not None:
try:
__import__(QT_LIB)
except ModuleNotFoundError:
pass
# raise ModuleNotFoundError(
# f"Environment variable PYQTGRAPH_QT_LIB is set to '{os.getenv('PYQTGRAPH_QT_LIB')}',"
# f" but no module with this name was found."
# )

## Automatically determine which Qt package to use (unless specified by
## environment variable).
## This is done by first checking to see whether one of the libraries
## is already imported. If not, then attempt to import in the order
## specified in libOrder.
libOrder = [PYQT6, PYSIDE6, PYQT5, PYSIDE2]
if QT_LIB is None:
for lib in libOrder:
if lib in sys.modules:
QT_LIB = lib
break

if QT_LIB is None:
for lib in libOrder:
qt = lib + ".QtCore"
try:
__import__(qt)
QT_LIB = lib
break
except ImportError:
pass

if QT_LIB is None:
raise Exception(
"PyQtGraph requires one of PyQt5, PyQt6, PySide2 or PySide6; none of these packages could be imported."
)

mandatory = ["QtCore", "QtGui", "QtQuick", "QtTest", "QtWidgets"]
QT_LIB = __import__(f"{QT_LIB}", fromlist=mandatory)
if not QT_LIB:
raise ModuleNotFoundError(
f"At least one of the following modules are not present in {QT_LIB}: {mandatory}"
)

for m in mandatory:
globals()[m] = getattr(QT_LIB, m)

# QtCore = getattr(QT_LIB, "QtCore")
# QtGui = getattr(QT_LIB, "QtGui")
# QtTest = getattr(QT_LIB, "QtTest")
# QtWidgets = getattr(QT_LIB, "QtWidgets")

__all__ = mandatory
Binary file added test/asammdf/gui/resources/ASAP2_Demo_V171.mf4
Binary file not shown.
1 change: 1 addition & 0 deletions test/asammdf/gui/resources/invalid_EmptySection.lab
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[lab]
Loading