91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
import pytest
|
|
import customtkinter as ctk
|
|
import sys
|
|
import os
|
|
# Add the src directory to the Python path
|
|
src_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'src'))
|
|
sys.path.insert(0, src_dir)
|
|
|
|
from views.mainScreen import MainFrame
|
|
|
|
def test_mainframe_initialization(mocker):
|
|
# Mocking the controller to avoid actual UI creation
|
|
mocker.patch('views.mainScreen.MainFrame')
|
|
|
|
# Initialize the MainFrame class
|
|
main_frame = MainFrame(None)
|
|
|
|
# Check if the grid configuration is set correctly
|
|
assert main_frame.grid_rowconfigure(0)['weight'] == 1
|
|
assert main_frame.grid_columnconfigure(0)['weight'] == 1
|
|
assert main_frame.grid_columnconfigure(1)['weight'] == 0
|
|
assert main_frame.grid_columnconfigure(2)['weight'] == 1
|
|
|
|
# Check if the entry_url is created correctly
|
|
assert isinstance(main_frame.entry_url, ctk.CTkEntry)
|
|
|
|
# Check if the check_button is created correctly
|
|
assert isinstance(main_frame.check_button, ctk.CTkButton)
|
|
|
|
# Check if the input_textbox is created correctly
|
|
assert isinstance(main_frame.input_textbox, ctk.CTkTextbox)
|
|
|
|
# Check if the label_frame is created correctly
|
|
assert isinstance(main_frame.label_frame, ctk.CTkFrame)
|
|
|
|
# Check if the result_label is created correctly
|
|
assert isinstance(main_frame.result_label, ctk.CTkLabel)
|
|
|
|
# Check if the confidence_label is created correctly
|
|
assert isinstance(main_frame.confidence_label, ctk.CTkLabel)
|
|
|
|
# Check if the output_textbox is created correctly
|
|
assert isinstance(main_frame.output_textbox, ctk.CTkTextbox)
|
|
|
|
# Check if the scrollview is created correctly
|
|
assert isinstance(main_frame.scrollview, ctk.CTkScrollableFrame)
|
|
|
|
# Check if the header is created correctly
|
|
assert isinstance(main_frame.header, ctk.CTkLabel)
|
|
|
|
# Check if the provider_container is created correctly
|
|
assert isinstance(main_frame.provider_container, ctk.CTkFrame)
|
|
|
|
def test_set_controller(mocker):
|
|
# Mocking the controller to avoid actual UI creation
|
|
mocker.patch('views.mainScreen.MainFrame')
|
|
|
|
# Initialize the MainFrame class
|
|
main_frame = MainFrame(None)
|
|
|
|
# Create a mock controller
|
|
mock_controller = mocker.Mock()
|
|
|
|
# Set the controller
|
|
main_frame.set_controller(mock_controller)
|
|
|
|
# Check if the controller is set correctly
|
|
assert main_frame.controller == mock_controller
|
|
|
|
def test_check_button_event(mocker):
|
|
# Mocking the controller to avoid actual UI creation
|
|
mocker.patch('views.mainScreen.MainFrame')
|
|
|
|
# Initialize the MainFrame class
|
|
main_frame = MainFrame(None)
|
|
|
|
# Create a mock controller
|
|
mock_controller = mocker.Mock()
|
|
|
|
# Set the controller
|
|
main_frame.set_controller(mock_controller)
|
|
|
|
# Call the check_button_event method
|
|
main_frame.check_button_event()
|
|
|
|
# Check if the press_check_button method of the controller is called
|
|
mock_controller.press_check_button.assert_called_once()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pytest.main([__file__]) |