-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #186 from TrevisanGMW/dev-feature/unittests
Created UI unittests
- Loading branch information
Showing
10 changed files
with
738 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -298,4 +298,3 @@ def close_parent_window(self): | |
out = window.get_output_box_plain_text() | ||
print(out) | ||
sys.exit(app.exec_()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
from . import test_input_window_text | ||
from . import test_line_text_widget | ||
from . import test_maya_menu | ||
from . import test_progress_bar | ||
from . import test_python_output_view | ||
from . import test_qt_utils | ||
from . import test_resource_library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from PySide2.QtWidgets import QApplication | ||
import unittest | ||
import logging | ||
import sys | ||
import os | ||
|
||
# Logging Setup | ||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# Import Tested Script | ||
test_utils_dir = os.path.dirname(__file__) | ||
tests_dir = os.path.dirname(test_utils_dir) | ||
package_root_dir = os.path.dirname(tests_dir) | ||
for to_append in [package_root_dir, tests_dir]: | ||
if to_append not in sys.path: | ||
sys.path.append(to_append) | ||
from gt.ui.input_window_text import InputWindowText | ||
|
||
|
||
class TestInputWindowText(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
app = QApplication.instance() | ||
if not app: | ||
cls.app = QApplication(sys.argv) | ||
|
||
def setUp(self): | ||
self.window = InputWindowText() | ||
|
||
def test_window_title(self): | ||
expected_title = "New Window Title" | ||
self.window.set_window_title(expected_title) | ||
self.assertEqual(self.window.windowTitle(), expected_title) | ||
|
||
def test_text_field_text(self): | ||
expected_text = "Sample Text" | ||
self.window.set_text_field_text(expected_text) | ||
self.assertEqual(self.window.get_text_field_text(), expected_text) | ||
|
||
def test_text_field_placeholder(self): | ||
expected_placeholder = "Enter text here" | ||
self.window.set_text_field_placeholder(expected_placeholder) | ||
self.assertEqual(self.window.text_field.placeholderText(), expected_placeholder) | ||
|
||
def test_confirm_button_text(self): | ||
expected_button_text = "OK" | ||
self.window.set_confirm_button_text(expected_button_text) | ||
self.assertEqual(self.window.confirm_button.text(), expected_button_text) | ||
|
||
def test_message_label(self): | ||
expected_message = "This is a test message" | ||
self.window.set_message(expected_message) | ||
self.assertEqual(self.window.description_label.text(), expected_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from PySide2.QtWidgets import QApplication, QDialog, QVBoxLayout | ||
from PySide2.QtGui import QColor | ||
import unittest | ||
import logging | ||
import sys | ||
import os | ||
|
||
# Logging Setup | ||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# Import Tested Script | ||
test_utils_dir = os.path.dirname(__file__) | ||
tests_dir = os.path.dirname(test_utils_dir) | ||
package_root_dir = os.path.dirname(tests_dir) | ||
for to_append in [package_root_dir, tests_dir]: | ||
if to_append not in sys.path: | ||
sys.path.append(to_append) | ||
from gt.ui.line_text_widget import LineTextWidget | ||
|
||
|
||
class TestLineTextWidget(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
app = QApplication.instance() | ||
if not app: | ||
cls.app = QApplication(sys.argv) | ||
|
||
def test_line_number_color(self): | ||
line_text_widget = LineTextWidget() | ||
line_text_widget.set_line_number_color(color=QColor(255, 0, 0)) # Set a red color | ||
self.assertEqual(line_text_widget.number_bar.number_color, QColor(255, 0, 0)) | ||
|
||
def test_line_number_bold_color(self): | ||
line_text_widget = LineTextWidget() | ||
line_text_widget.line_number_bold_color(color=QColor(0, 255, 0)) # Set a green color | ||
self.assertEqual(line_text_widget.number_bar.number_bold_color, QColor(0, 255, 0)) | ||
|
||
def test_dialog_with_syntax_highlighter(self): | ||
from gt.ui.syntax_highlighter import PythonSyntaxHighlighter | ||
dialog = QDialog() | ||
layout = QVBoxLayout(dialog) | ||
line_text_widget = LineTextWidget() | ||
dialog.setLayout(layout) | ||
layout.addWidget(line_text_widget) | ||
PythonSyntaxHighlighter(line_text_widget.get_text_edit().document()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from PySide2.QtWidgets import QApplication | ||
import unittest | ||
import logging | ||
import sys | ||
import os | ||
|
||
# Logging Setup | ||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# Import Tested Script | ||
test_utils_dir = os.path.dirname(__file__) | ||
tests_dir = os.path.dirname(test_utils_dir) | ||
package_root_dir = os.path.dirname(tests_dir) | ||
for to_append in [package_root_dir, tests_dir]: | ||
if to_append not in sys.path: | ||
sys.path.append(to_append) | ||
from gt.ui.maya_menu import MayaMenu, MenuItem | ||
from tests import maya_test_tools | ||
|
||
|
||
class TestMayaMenu(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
app = QApplication.instance() | ||
if not app: | ||
cls.app = QApplication(sys.argv) | ||
|
||
def setUp(self): | ||
# Create a MayaMenu object for testing | ||
self.menu = MayaMenu(name="TestMenu", parent=None) | ||
maya_test_tools.import_maya_standalone(initialize=True) | ||
|
||
def tearDown(self): | ||
# Delete the menu after each test | ||
self.menu.delete_menu() | ||
|
||
def test_create_menu(self): | ||
# Test if the menu is created successfully | ||
self.menu.create_menu() | ||
self.assertTrue(self.menu.initialized) | ||
|
||
def test_add_menu_item(self): | ||
# Add a menu item and check if it exists in the menu items list | ||
label = "TestMenuItem" | ||
self.menu.add_menu_item(label) | ||
self.assertTrue(any(item.label == label for item in self.menu.menu_items)) | ||
|
||
def test_add_sub_menu(self): | ||
# Add a sub-menu and check if it exists in the sub_menus list | ||
label = "TestSubMenu" | ||
self.menu.add_sub_menu(label) | ||
self.assertTrue(label in self.menu.sub_menus) | ||
|
||
def test_add_divider(self): | ||
# Add a divider and check if it exists in the menu items list | ||
label = "TestDivider" | ||
self.menu.add_divider(label) | ||
self.assertTrue(any(item.label == label for item in self.menu.menu_items)) | ||
|
||
def test_get_item_parameters(self): | ||
# Test the get_item_parameters method | ||
item = MenuItem(label="label", | ||
command='command', | ||
tooltip='tooltip', | ||
icon='icon', | ||
enable=True, | ||
parent="parent", | ||
divider=True, | ||
divider_label="divider_label", | ||
sub_menu=False, | ||
tear_off=False, | ||
enable_command_repeat=False, | ||
option_box=False, | ||
option_box_icon='') | ||
params = self.menu.get_item_parameters(item) | ||
self.assertEqual(params["label"], "label") | ||
self.assertEqual(params["command"], "command") | ||
self.assertEqual(params["annotation"], "tooltip") | ||
self.assertEqual(params["image"], "icon") | ||
self.assertEqual(params["enable"], True) | ||
self.assertEqual(params["parent"], "parent") | ||
self.assertEqual(params["divider"], True) | ||
self.assertEqual(params["dividerLabel"], "divider_label") | ||
self.assertEqual(params["subMenu"], False) | ||
self.assertEqual(params.get("tearOff"), None) | ||
self.assertEqual(params["enableCommandRepeat"], False) | ||
self.assertEqual(params.get("optionBox"), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from PySide2.QtWidgets import QApplication | ||
import unittest | ||
import logging | ||
import sys | ||
import os | ||
|
||
# Logging Setup | ||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# Import Tested Script | ||
test_utils_dir = os.path.dirname(__file__) | ||
tests_dir = os.path.dirname(test_utils_dir) | ||
package_root_dir = os.path.dirname(tests_dir) | ||
for to_append in [package_root_dir, tests_dir]: | ||
if to_append not in sys.path: | ||
sys.path.append(to_append) | ||
from gt.ui.progress_bar import ProgressBarWindow | ||
|
||
|
||
class TestProgressBar(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
app = QApplication.instance() | ||
if not app: | ||
cls.app = QApplication(sys.argv) | ||
|
||
def setUp(self): | ||
self.window = ProgressBarWindow() | ||
|
||
def test_set_progress_bar_value(self): | ||
window = ProgressBarWindow() | ||
|
||
# Test setting the progress bar value | ||
window.set_progress_bar_value(50) | ||
self.assertEqual(window.progress_bar.value(), 50) | ||
|
||
def test_add_text_to_output_box(self): | ||
window = ProgressBarWindow() | ||
|
||
# Test adding text to the output box | ||
text_to_add = "This is a test message." | ||
window.add_text_to_output_box(text_to_add) | ||
output_text = window.get_output_box_plain_text() | ||
self.assertIn(text_to_add, output_text) | ||
|
||
def test_change_line_color(self): | ||
window = ProgressBarWindow() | ||
|
||
# Test changing the color of a specific line | ||
text_to_add = "This is a test message." | ||
window.add_text_to_output_box(text_to_add) | ||
window.change_line_color(line_number=1, color="red") | ||
|
||
# Get the formatted text and check if it contains the color tag | ||
output_text = window.get_output_box_plain_text() | ||
self.assertIn(text_to_add, output_text) | ||
|
||
def test_change_last_line_color(self): | ||
window = ProgressBarWindow() | ||
|
||
# Test changing the color of the last line | ||
text_to_add1 = "This is line 1." | ||
text_to_add2 = "This is line 2." | ||
window.add_text_to_output_box(text_to_add1) | ||
window.add_text_to_output_box(text_to_add2) | ||
window.change_last_line_color("blue") | ||
|
||
# Get the formatted text and check if the last line contains the color tag | ||
output_text = window.get_output_box_plain_text() | ||
self.assertIn(text_to_add1, output_text) | ||
self.assertIn(text_to_add2, output_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from PySide2.QtWidgets import QApplication | ||
from unittest.mock import MagicMock | ||
import unittest | ||
import logging | ||
import sys | ||
import os | ||
|
||
# Logging Setup | ||
logging.basicConfig() | ||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
# Import Tested Script | ||
test_utils_dir = os.path.dirname(__file__) | ||
tests_dir = os.path.dirname(test_utils_dir) | ||
package_root_dir = os.path.dirname(tests_dir) | ||
for to_append in [package_root_dir, tests_dir]: | ||
if to_append not in sys.path: | ||
sys.path.append(to_append) | ||
from gt.ui.python_output_view import PythonOutputView | ||
|
||
|
||
class TestPythonOutputView(unittest.TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
app = QApplication.instance() | ||
if not app: | ||
cls.app = QApplication(sys.argv) | ||
|
||
def setUp(self): | ||
# Create an instance of PythonOutputView | ||
self.python_output_view = PythonOutputView() | ||
|
||
def test_clear_python_output(self): | ||
# Test clearing Python output | ||
self.python_output_view.output_python_box.get_text_edit().setPlainText("Sample text") | ||
self.python_output_view.clear_python_output() | ||
result = self.python_output_view.get_python_output_text() | ||
expected = "" | ||
self.assertEqual(result, expected) | ||
|
||
def test_set_python_output_text(self): | ||
# Test setting Python output text | ||
self.python_output_view.set_python_output_text("Sample text") | ||
result = self.python_output_view.get_python_output_text() | ||
expected = "Sample text" | ||
self.assertEqual(result, expected) | ||
|
||
def test_get_python_output_text(self): | ||
# Test getting Python output text | ||
self.python_output_view.output_python_box.get_text_edit().setPlainText("Sample text") | ||
result = self.python_output_view.get_python_output_text() | ||
expected = "Sample text" | ||
self.assertEqual(result, expected) |
Oops, something went wrong.