Skip to content

Commit 5ec6f7a

Browse files
committed
Fix github action to PySide6 apps test
1 parent 9b55272 commit 5ec6f7a

File tree

7 files changed

+95
-64
lines changed

7 files changed

+95
-64
lines changed

.github/workflows/coverage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: sudo apt update -y
2525

2626
- name: 'Install Dependencies'
27-
run: sudo apt install -y patchelf libopengl0 libegl-dev
27+
run: sudo apt install -y patchelf libopengl0 libegl-dev libgles2-mesa-dev nuitka
2828

2929
- name: Install coverage dependencies
3030
run: |

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: sudo apt update -y
2525

2626
- name: 'Install Dependencies'
27-
run: sudo apt install -y patchelf libopengl0 libegl-dev
27+
run: sudo apt install -y patchelf libopengl0 libegl-dev libgles2-mesa-dev nuitka
2828

2929
- name: Install test dependencies for linting
3030
run: |

.github/workflows/test.yml

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,86 @@
44
name: Github CI PyTest
55

66
on:
7-
pull_request:
8-
branches:
9-
- "*"
107
push:
118
branches:
12-
- "*"
9+
- main
10+
- develop
11+
12+
pull_request:
13+
14+
# Cancel running jobs for the same workflow and branch.
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
1318

1419
jobs:
15-
build:
16-
name: Build
20+
package:
1721
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v4
24+
- name: Build and Check Package
25+
uses: hynek/build-and-inspect-python-package@v2.12
26+
27+
test:
28+
29+
needs: [package]
30+
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
fail-fast: false
34+
35+
matrix:
36+
python-version: ["3.12"]
37+
qt-lib: [pyside6]
38+
os: [ubuntu-latest, windows-latest, macos-latest]
39+
40+
# on:
41+
# pull_request:
42+
# branches:
43+
# - "*"
44+
# push:
45+
# branches:
46+
# - "*"
47+
48+
# jobs:
49+
# build:
50+
# name: Build
51+
# runs-on: ubuntu-latest
1852

1953
steps:
20-
- uses: actions/checkout@v3
21-
- uses: actions/setup-python@v4
54+
# - uses: actions/checkout@v4
55+
# - uses: actions/setup-python@v4
56+
# with:
57+
# python-version: "3.12"
58+
59+
- uses: actions/checkout@v4
60+
61+
- name: Set up Python ${{ matrix.python-version }}
62+
uses: actions/setup-python@v5.5.0
2263
with:
23-
python-version: "3.12"
64+
python-version: ${{ matrix.python-version }}
2465

25-
- name: 'Update Packages'
26-
run: sudo apt update -y
66+
- name: Install Dependencies
67+
run: |
68+
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
69+
sudo apt-get update -y
70+
sudo apt-get install -y libgles2-mesa-dev
71+
fi
72+
shell: bash
73+
74+
# - name: 'Update Packages'
75+
# run: sudo apt update -y
2776

28-
- name: 'Install Dependencies'
29-
run: sudo apt install -y patchelf libopengl0 libegl-dev
77+
# - name: 'Install Dependencies'
78+
# run: sudo apt install -y patchelf libopengl0 libegl-dev libgles2-mesa-dev nuitka
3079

3180
- name: Install test dependencies
3281
run: |
3382
pip install ".[dev]"
3483
84+
- name: 'Run PySide6 Tests'
85+
run: |
86+
python -c "from PySide6.QtWidgets import QApplication; app = QApplication([]); print('PySide6 is working!')"
87+
3588
- name: Run tests
3689
run: make test

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ strict_optional = false
137137

138138
[tool.coverage.run]
139139
branch = true
140-
omit = ["tests/*", "src/app_rc.py", "src/__init__.py", "src/main.py", "src/__version__.py"]
140+
omit = ["tests/*", "src/app_rc.py", "src/__init__.py", "src/app.py", "src/__version__.py"]
141141

142142
[tool.pyside6-project]
143-
files = ["main.py"]
143+
files = ["app.py"]

tests/test_comic.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,23 @@ def test_get_comic_path(comic_data):
8080
expected_path = os.path.join(directory, filename)
8181
assert comic.getComicPath() == expected_path
8282

83-
def test_comic_initialization(comic_data):
84-
"""
85-
Test the initialization of the Comic class.
86-
"""
87-
comic, filename, directory, _ = comic_data
88-
assert comic.getFilename() == filename
89-
assert comic.getDirectory() == directory
90-
assert comic.getPages() == []
91-
92-
def test_set_and_get_pages(comic_data):
93-
"""
94-
Test setting and getting pages.
95-
"""
96-
comic, _, _, pages = comic_data
97-
comic.setPages(pages)
98-
assert comic.getPages() == pages
99-
assert len(comic.getPages()) == len(pages)
100-
assert all(isinstance(page, Page) for page in comic.getPages())
83+
84+
def test_comic_initialization(comic_data):
85+
"""
86+
Test the initialization of the Comic class.
87+
"""
88+
comic, filename, directory, _ = comic_data
89+
assert comic.getFilename() == filename
90+
assert comic.getDirectory() == directory
91+
assert comic.getPages() == []
92+
93+
94+
def test_set_and_get_pages(comic_data):
95+
"""
96+
Test setting and getting pages.
97+
"""
98+
comic, _, _, pages = comic_data
99+
comic.setPages(pages)
100+
assert comic.getPages() == pages
101+
assert len(comic.getPages()) == len(pages)
102+
assert all(isinstance(page, Page) for page in comic.getPages())

tests/test_comic_page_handler.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,12 @@
1-
from unittest.mock import patch
2-
31
import pytest
42

53
from src.models.comic import Comic
64
from src.models.comic_handler import ComicHandler
75
from src.models.page import Page
86

97

10-
# Mock the QPixmap class to avoid loading actual images
11-
# and to prevent the need for a GUI environment.
12-
class MagicMockQPixmap:
13-
def loadFromData(self, data):
14-
return MagicMockQPixmap()
15-
16-
178
@pytest.fixture
18-
def comic_handler():
9+
def comic_handler(qtbot):
1910
"""
2011
Fixture to set up a ComicHandler instance with a mock Comic object.
2112
"""
@@ -26,8 +17,7 @@ def comic_handler():
2617

2718
comic.setPages([page_1, page_2, page_3])
2819

29-
with patch("src.models.comic_handler.QPixmap", return_value=MagicMockQPixmap):
30-
handler = ComicHandler(comic)
20+
handler = ComicHandler(comic)
3121

3222
return handler, comic, [page_1, page_2, page_3]
3323

tests/test_comic_page_handler_single_page.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unittest.mock import MagicMock, patch
2-
31
import pytest
42
from PySide6.QtGui import QPixmap
53

@@ -8,19 +6,8 @@
86
from src.models.page import Page
97

108

11-
# Mock the QPixmap class to avoid loading actual images
12-
# and to prevent the need for a GUI environment.
13-
class MagicMockQPixmap(QPixmap):
14-
def __init__(self, *args, **kwargs):
15-
pass
16-
17-
@staticmethod
18-
def loadFromData(*args, **kwargs):
19-
return MagicMock()
20-
21-
229
@pytest.fixture
23-
def comic_handler():
10+
def comic_handler(qtbot):
2411
"""
2512
Fixture to set up a ComicHandlerSinglePage object with a mock comic and pages.
2613
"""
@@ -31,8 +18,7 @@ def comic_handler():
3118

3219
comic.setPages([page_1, page_2, page_3])
3320

34-
with patch("src.models.comic_handler.QPixmap", return_value=MagicMockQPixmap()):
35-
obj = ComicHandlerSinglePage(comic)
21+
obj = ComicHandlerSinglePage(comic)
3622

3723
return obj
3824

@@ -72,4 +58,4 @@ def test_get_current_page_image(comic_handler):
7258
Test that the getCurrentPageImage method returns a QPixmap object.
7359
"""
7460
pixmap = comic_handler.getCurrentPageImage()
75-
assert isinstance(pixmap, MagicMockQPixmap) # Check if it returns a mocked QPixmap
61+
assert isinstance(pixmap, QPixmap) # Check if it returns a mocked QPixmap

0 commit comments

Comments
 (0)