202 lines
6.7 KiB
Python
202 lines
6.7 KiB
Python
from __future__ import annotations
|
|
from unittest.mock import patch, MagicMock
|
|
import pytest
|
|
|
|
|
|
class TestImGuiScope:
|
|
def test_enter_calls_begin_with_args(self) -> None:
|
|
from src.imgui_scopes import ImGuiScope
|
|
mock_begin = MagicMock(return_value=True)
|
|
mock_end = MagicMock()
|
|
scope = ImGuiScope(mock_begin, mock_end, "arg1", kwarg="val")
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("arg1", kwarg="val")
|
|
|
|
def test_exit_calls_end_when_entered(self) -> None:
|
|
from src.imgui_scopes import ImGuiScope
|
|
mock_begin = MagicMock(return_value=True)
|
|
mock_end = MagicMock()
|
|
scope = ImGuiScope(mock_begin, mock_end)
|
|
with scope:
|
|
pass
|
|
mock_end.assert_called_once()
|
|
|
|
def test_exit_does_not_call_end_when_not_entered(self) -> None:
|
|
from src.imgui_scopes import ImGuiScope
|
|
mock_begin = MagicMock(return_value=False)
|
|
mock_end = MagicMock()
|
|
scope = ImGuiScope(mock_begin, mock_end)
|
|
with scope:
|
|
pass
|
|
mock_end.assert_not_called()
|
|
|
|
def test_enter_returns_opened_value(self) -> None:
|
|
from src.imgui_scopes import ImGuiScope
|
|
mock_begin = MagicMock(return_value=True)
|
|
mock_end = MagicMock()
|
|
scope = ImGuiScope(mock_begin, mock_end)
|
|
result = scope.__enter__()
|
|
assert result is True
|
|
|
|
def test_enter_handles_tuple_return(self) -> None:
|
|
from src.imgui_scopes import ImGuiScope
|
|
mock_begin = MagicMock(return_value=(True, "extra"))
|
|
mock_end = MagicMock()
|
|
scope = ImGuiScope(mock_begin, mock_end)
|
|
with scope:
|
|
pass
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiWindow:
|
|
def test_imgui_window_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_window, ImGuiScope
|
|
scope = imgui_window("Test")
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_window_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_window
|
|
with patch("src.imgui_scopes.imgui.begin", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end") as mock_end:
|
|
scope = imgui_window("Test")
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("Test", True, 0)
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiTable:
|
|
def test_imgui_table_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_table, ImGuiScope
|
|
scope = imgui_table("TestTable", 3)
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_table_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_table
|
|
with patch("src.imgui_scopes.imgui.begin_table", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_table") as mock_end:
|
|
scope = imgui_table("TestTable", 3)
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("TestTable", 3, 0)
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiMenuBar:
|
|
def test_imgui_menu_bar_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_menu_bar, ImGuiScope
|
|
scope = imgui_menu_bar()
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_menu_bar_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_menu_bar
|
|
with patch("src.imgui_scopes.imgui.begin_menu_bar", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_menu_bar") as mock_end:
|
|
scope = imgui_menu_bar()
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with()
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiMenu:
|
|
def test_imgui_menu_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_menu, ImGuiScope
|
|
scope = imgui_menu("File")
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_menu_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_menu
|
|
with patch("src.imgui_scopes.imgui.begin_menu", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_menu") as mock_end:
|
|
scope = imgui_menu("File")
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("File")
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiChild:
|
|
def test_imgui_child_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_child, ImGuiScope
|
|
scope = imgui_child("child_id", 100, 200)
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_child_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_child
|
|
with patch("src.imgui_scopes.imgui.begin_child", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_child") as mock_end:
|
|
scope = imgui_child("child_id", 100, 200)
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("child_id", 100, 200, 0)
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiGroup:
|
|
def test_imgui_group_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_group, ImGuiScope
|
|
scope = imgui_group()
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_group_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_group
|
|
with patch("src.imgui_scopes.imgui.begin_group", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_group") as mock_end:
|
|
scope = imgui_group()
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with()
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiPopup:
|
|
def test_imgui_popup_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_popup, ImGuiScope
|
|
scope = imgui_popup("popup_id")
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_popup_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_popup
|
|
with patch("src.imgui_scopes.imgui.begin_popup", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_popup") as mock_end:
|
|
scope = imgui_popup("popup_id")
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("popup_id")
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestImguiTooltip:
|
|
def test_imgui_tooltip_returns_scope(self) -> None:
|
|
from src.imgui_scopes import imgui_tooltip, ImGuiScope
|
|
scope = imgui_tooltip()
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_imgui_tooltip_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import imgui_tooltip
|
|
with patch("src.imgui_scopes.imgui.begin_tooltip", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui.end_tooltip") as mock_end:
|
|
scope = imgui_tooltip()
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with()
|
|
mock_end.assert_called_once()
|
|
|
|
|
|
class TestNodeEditorScope:
|
|
def test_node_editor_scope_returns_scope(self) -> None:
|
|
from src.imgui_scopes import node_editor_scope, ImGuiScope
|
|
scope = node_editor_scope("TestNode")
|
|
assert isinstance(scope, ImGuiScope)
|
|
|
|
def test_node_editor_scope_calls_begin_end(self) -> None:
|
|
from src.imgui_scopes import node_editor_scope
|
|
with patch("src.imgui_scopes.imgui_node_editor.begin", return_value=True) as mock_begin:
|
|
with patch("src.imgui_scopes.imgui_node_editor.end") as mock_end:
|
|
scope = node_editor_scope("TestNode")
|
|
with scope:
|
|
pass
|
|
mock_begin.assert_called_once_with("TestNode")
|
|
mock_end.assert_called_once() |