Skip to content

Commit 14c5a56

Browse files
authored
Merge pull request #68 from chennes/addTestsForButtons
Add basic test stubs for all widget classes
2 parents 9604a77 + 2d377a0 commit 14c5a56

17 files changed

+837
-63
lines changed

.github/workflows/qt5-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
test:
11+
name: Qt5 Test
1112
runs-on: ubuntu-22.04
1213

1314
steps:

.github/workflows/qt6-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
jobs:
1010
test:
11+
name: Qt6 Test (Python ${{ matrix.python-version }})
1112
runs-on: ubuntu-latest
1213

1314
strategy:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# ***************************************************************************
3+
# * *
4+
# * Copyright (c) 2025 The FreeCAD project association AISBL *
5+
# * *
6+
# * This file is part of the FreeCAD Addon Manager. *
7+
# * *
8+
# * FreeCAD is free software: you can redistribute it and/or modify it *
9+
# * under the terms of the GNU Lesser General Public License as *
10+
# * published by the Free Software Foundation, either version 2.1 of the *
11+
# * License, or (at your option) any later version. *
12+
# * *
13+
# * FreeCAD is distributed in the hope that it will be useful, but *
14+
# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
# * Lesser General Public License for more details. *
17+
# * *
18+
# * You should have received a copy of the GNU Lesser General Public *
19+
# * License along with FreeCAD. If not, see *
20+
# * <https://www.gnu.org/licenses/>. *
21+
# * *
22+
# ***************************************************************************
23+
24+
import unittest
25+
26+
from PySideWrapper import QtWidgets
27+
28+
from Widgets.addonmanager_widget_addon_buttons import WidgetAddonButtons
29+
30+
31+
class TestWidgetAddonButtons(unittest.TestCase):
32+
33+
def test_instantiation(self):
34+
window = QtWidgets.QDialog()
35+
window.setObjectName("Test Widget Addon Buttons")
36+
_buttons = WidgetAddonButtons(window)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# ***************************************************************************
3+
# * *
4+
# * Copyright (c) 2025 The FreeCAD project association AISBL *
5+
# * *
6+
# * This file is part of the FreeCAD Addon Manager. *
7+
# * *
8+
# * FreeCAD is free software: you can redistribute it and/or modify it *
9+
# * under the terms of the GNU Lesser General Public License as *
10+
# * published by the Free Software Foundation, either version 2.1 of the *
11+
# * License, or (at your option) any later version. *
12+
# * *
13+
# * FreeCAD is distributed in the hope that it will be useful, but *
14+
# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
# * Lesser General Public License for more details. *
17+
# * *
18+
# * You should have received a copy of the GNU Lesser General Public *
19+
# * License along with FreeCAD. If not, see *
20+
# * <https://www.gnu.org/licenses/>. *
21+
# * *
22+
# ***************************************************************************
23+
24+
import unittest
25+
26+
from PySideWrapper import QtWidgets
27+
28+
from Widgets.addonmanager_widget_filter_selector import (
29+
WidgetFilterSelector,
30+
StatusFilter,
31+
ContentFilter,
32+
)
33+
34+
35+
class TestWidgetFilterSelector(unittest.TestCase):
36+
37+
def setUp(self):
38+
self.window = QtWidgets.QDialog()
39+
self.window.setObjectName("Test Widget Filter Selector Window")
40+
self.wfs = WidgetFilterSelector(self.window)
41+
42+
def tearDown(self):
43+
self.window.close()
44+
45+
def test_instantiation(self):
46+
self.assertIsInstance(self.wfs, WidgetFilterSelector)
47+
48+
def test_set_status_filter(self):
49+
"""Explicitly setting the status filter should not emit a signal"""
50+
signal_caught = False
51+
52+
def signal_handler():
53+
nonlocal signal_caught
54+
signal_caught = True
55+
56+
self.wfs.filter_changed.connect(signal_handler)
57+
self.wfs.set_status_filter(StatusFilter.ANY)
58+
self.assertFalse(signal_caught)
59+
60+
def test_set_content_filter(self):
61+
"""Explicitly setting the content filter should not emit a signal"""
62+
signal_caught = False
63+
64+
def signal_handler():
65+
nonlocal signal_caught
66+
signal_caught = True
67+
68+
self.wfs.filter_changed.connect(signal_handler)
69+
self.wfs.set_contents_filter(ContentFilter.ANY)
70+
self.assertFalse(signal_caught)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# ***************************************************************************
3+
# * *
4+
# * Copyright (c) 2025 The FreeCAD project association AISBL *
5+
# * *
6+
# * This file is part of the FreeCAD Addon Manager. *
7+
# * *
8+
# * FreeCAD is free software: you can redistribute it and/or modify it *
9+
# * under the terms of the GNU Lesser General Public License as *
10+
# * published by the Free Software Foundation, either version 2.1 of the *
11+
# * License, or (at your option) any later version. *
12+
# * *
13+
# * FreeCAD is distributed in the hope that it will be useful, but *
14+
# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
# * Lesser General Public License for more details. *
17+
# * *
18+
# * You should have received a copy of the GNU Lesser General Public *
19+
# * License along with FreeCAD. If not, see *
20+
# * <https://www.gnu.org/licenses/>. *
21+
# * *
22+
# ***************************************************************************
23+
24+
import unittest
25+
26+
from PySideWrapper import QtWidgets
27+
28+
from Widgets.addonmanager_widget_global_buttons import WidgetGlobalButtonBar
29+
30+
31+
class TestWidgetGlobalButtons(unittest.TestCase):
32+
33+
def setUp(self):
34+
self.window = QtWidgets.QDialog()
35+
self.window.setObjectName("Test Widget Button Bar Window")
36+
self.wbb = WidgetGlobalButtonBar(self.window)
37+
38+
def tearDown(self):
39+
self.window.close()
40+
del self.window
41+
42+
def test_instantiation(self):
43+
self.assertIsInstance(self.wbb, WidgetGlobalButtonBar)
44+
45+
def test_set_number_of_available_updates_to_zero(self):
46+
"""The string saying that there are no available updates shouldn't contain the number 0"""
47+
self.wbb.set_number_of_available_updates(0)
48+
self.assertNotIn("0", self.wbb.update_all_addons.text())
49+
50+
def test_set_number_of_available_updates_to_nonzero(self):
51+
"""The string saying that there are available updates should contain the number"""
52+
self.wbb.set_number_of_available_updates(42)
53+
self.assertIn("42", self.wbb.update_all_addons.text())
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# ***************************************************************************
3+
# * *
4+
# * Copyright (c) 2025 The FreeCAD project association AISBL *
5+
# * *
6+
# * This file is part of the FreeCAD Addon Manager. *
7+
# * *
8+
# * FreeCAD is free software: you can redistribute it and/or modify it *
9+
# * under the terms of the GNU Lesser General Public License as *
10+
# * published by the Free Software Foundation, either version 2.1 of the *
11+
# * License, or (at your option) any later version. *
12+
# * *
13+
# * FreeCAD is distributed in the hope that it will be useful, but *
14+
# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
# * Lesser General Public License for more details. *
17+
# * *
18+
# * You should have received a copy of the GNU Lesser General Public *
19+
# * License along with FreeCAD. If not, see *
20+
# * <https://www.gnu.org/licenses/>. *
21+
# * *
22+
# ***************************************************************************
23+
24+
"""Tests for the PackageDetailsView widget. Many tests are currently just stubs that ensure the
25+
code paths are executed so that the CI can find any errors in Python or Qt5/Qt6 compatibility.
26+
"""
27+
28+
import unittest
29+
from unittest.mock import patch
30+
31+
from PySideWrapper import QtWidgets
32+
33+
from Widgets.addonmanager_widget_package_details_view import (
34+
PackageDetailsView,
35+
UpdateInformation,
36+
WarningFlags,
37+
)
38+
39+
40+
class TestPackageDetailsView(unittest.TestCase):
41+
42+
def setUp(self):
43+
self.window = QtWidgets.QDialog()
44+
self.window.setObjectName("Test Widget Package Details View Window")
45+
self.pdv = PackageDetailsView(self.window)
46+
47+
def tearDown(self):
48+
self.window.close()
49+
del self.window
50+
51+
def test_instantiation(self):
52+
self.assertIsInstance(self.pdv, PackageDetailsView)
53+
54+
def test_set_location_to_empty(self):
55+
"""When location is set empty, the location display is hidden"""
56+
self.pdv.set_location(None)
57+
self.assertTrue(self.pdv.location_label.isHidden())
58+
59+
def test_set_location_to_nonempty(self):
60+
"""When location is set to a string, the display is shown"""
61+
self.pdv.set_location("test")
62+
self.assertFalse(self.pdv.location_label.isHidden())
63+
self.assertIn("test", self.pdv.location_label.text())
64+
65+
def test_set_url_to_empty(self):
66+
"""When URL is set empty, the URL display is hidden"""
67+
self.pdv.set_url(None)
68+
self.assertTrue(self.pdv.url_label.isHidden())
69+
70+
def test_set_url_to_nonempty(self):
71+
"""When URL is set to a string, the URL display is shown"""
72+
self.pdv.set_url("test")
73+
self.assertFalse(self.pdv.url_label.isHidden())
74+
self.assertIn("test", self.pdv.url_label.text())
75+
76+
def test_set_installed_minimal(self):
77+
"""Exercise the set_installed method with the minimum arguments"""
78+
self.pdv.set_installed(True)
79+
80+
def test_set_installed_full(self):
81+
"""Exercise the set_installed method with all arguments"""
82+
self.pdv.set_installed(True, 1234567.89, "version", "branch")
83+
84+
@patch("Widgets.addonmanager_widget_package_details_view.PackageDetailsView.set_location")
85+
def test_set_installed_false(self, mock_set_location):
86+
"""When the package is not installed, the location label is un-set"""
87+
self.pdv.set_installed(False)
88+
mock_set_location.assert_called_with(None)
89+
90+
def test_set_update_available_true(self):
91+
"""Not exhaustive, just test the basic call with update available=True"""
92+
self.pdv.set_update_available(UpdateInformation(update_available=True))
93+
94+
def test_set_update_available_false(self):
95+
"""Not exhaustive, just test the basic call with update_available=False"""
96+
self.pdv.set_update_available(UpdateInformation(update_available=False))
97+
98+
def test_set_disabled_true(self):
99+
self.pdv.set_disabled(True)
100+
101+
def test_set_disabled_false(self):
102+
self.pdv.set_disabled(True)
103+
104+
def test_allow_disabling_true(self):
105+
self.pdv.allow_disabling(True)
106+
107+
def test_allow_disabling_false(self):
108+
self.pdv.allow_disabling(False)
109+
110+
def test_allow_running_true(self):
111+
self.pdv.allow_running(True)
112+
113+
def test_allow_running_false(self):
114+
self.pdv.allow_running(False)
115+
116+
def test_set_warning_flags_obsolete(self):
117+
self.pdv.set_warning_flags(WarningFlags(obsolete=True))
118+
119+
def test_set_warning_flags_py2(self):
120+
self.pdv.set_warning_flags(WarningFlags(python2=True))
121+
122+
def test_set_warning_flags_freecad_version(self):
123+
self.pdv.set_warning_flags(WarningFlags(required_freecad_version="99.0"))
124+
125+
def test_set_warning_flags_non_osi_approved(self):
126+
self.pdv.set_warning_flags(WarningFlags(non_osi_approved=True))
127+
128+
def test_set_warning_flags_non_fsf_libre(self):
129+
self.pdv.set_warning_flags(WarningFlags(non_fsf_libre=True))
130+
131+
def test_set_new_disabled_status_true(self):
132+
self.pdv.set_new_disabled_status(True)
133+
134+
def test_set_new_disabled_status_false(self):
135+
self.pdv.set_new_disabled_status(False)
136+
137+
def test_set_new_branch(self):
138+
self.pdv.set_new_branch("test")
139+
140+
def test_set_updated(self):
141+
self.pdv.set_updated()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-License-Identifier: LGPL-2.1-or-later
2+
# ***************************************************************************
3+
# * *
4+
# * Copyright (c) 2025 The FreeCAD project association AISBL *
5+
# * *
6+
# * This file is part of the FreeCAD Addon Manager. *
7+
# * *
8+
# * FreeCAD is free software: you can redistribute it and/or modify it *
9+
# * under the terms of the GNU Lesser General Public License as *
10+
# * published by the Free Software Foundation, either version 2.1 of the *
11+
# * License, or (at your option) any later version. *
12+
# * *
13+
# * FreeCAD is distributed in the hope that it will be useful, but *
14+
# * WITHOUT ANY WARRANTY; without even the implied warranty of *
15+
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16+
# * Lesser General Public License for more details. *
17+
# * *
18+
# * You should have received a copy of the GNU Lesser General Public *
19+
# * License along with FreeCAD. If not, see *
20+
# * <https://www.gnu.org/licenses/>. *
21+
# * *
22+
# ***************************************************************************
23+
24+
25+
import unittest
26+
from unittest.mock import patch
27+
28+
from PySideWrapper import QtWidgets
29+
30+
from Widgets.addonmanager_widget_readme_browser import WidgetReadmeBrowser
31+
32+
33+
class TestWidgetReadmeBrowser(unittest.TestCase):
34+
def setUp(self):
35+
self.window = QtWidgets.QDialog()
36+
self.window.setObjectName("Test Widget Readme Browser Window")
37+
self.pdv = WidgetReadmeBrowser(self.window)
38+
39+
def tearDown(self):
40+
self.window.close()
41+
del self.window
42+
43+
def test_instantiation(self):
44+
self.assertIsInstance(self.pdv, WidgetReadmeBrowser)

0 commit comments

Comments
 (0)