Update tests to work with new Micron renderer improvements.
This commit is contained in:
@@ -62,7 +62,7 @@ def sample_page_request():
|
||||
from ren_browser.pages.page_request import PageRequest
|
||||
|
||||
return PageRequest(
|
||||
destination_hash="1234567890abcdef", page_path="/page/index.mu", field_data=None
|
||||
destination_hash="1234567890abcdef", page_path="/page/index.mu", field_data=None,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class TestAnnounce:
|
||||
def test_announce_with_none_display_name(self):
|
||||
"""Test Announce creation with None display name."""
|
||||
announce = Announce(
|
||||
destination_hash="1234567890abcdef", display_name=None, timestamp=1234567890
|
||||
destination_hash="1234567890abcdef", display_name=None, timestamp=1234567890,
|
||||
)
|
||||
|
||||
assert announce.destination_hash == "1234567890abcdef"
|
||||
|
||||
@@ -59,7 +59,7 @@ class TestLogsModule:
|
||||
assert len(logs.RET_LOGS) == 1
|
||||
assert logs.RET_LOGS[0] == "[2023-01-01T12:00:00] Test RNS message"
|
||||
logs._original_rns_log.assert_called_once_with(
|
||||
"Test RNS message", "arg1", kwarg1="value1"
|
||||
"Test RNS message", "arg1", kwarg1="value1",
|
||||
)
|
||||
assert result == "original_result"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class TestPageRequest:
|
||||
def test_page_request_creation(self):
|
||||
"""Test basic PageRequest creation."""
|
||||
request = PageRequest(
|
||||
destination_hash="1234567890abcdef", page_path="/page/index.mu"
|
||||
destination_hash="1234567890abcdef", page_path="/page/index.mu",
|
||||
)
|
||||
|
||||
assert request.destination_hash == "1234567890abcdef"
|
||||
|
||||
@@ -58,8 +58,8 @@ class TestPlaintextRenderer:
|
||||
class TestMicronRenderer:
|
||||
"""Test cases for the micron renderer.
|
||||
|
||||
The micron renderer parses Micron markup format and returns a Column
|
||||
containing styled Text controls with proper formatting, colors, and layout.
|
||||
The micron renderer parses Micron markup format and returns a ListView
|
||||
containing styled controls with proper formatting, colors, and layout.
|
||||
"""
|
||||
|
||||
def test_render_micron_basic(self):
|
||||
@@ -67,16 +67,14 @@ class TestMicronRenderer:
|
||||
content = "# Heading\n\nSome content"
|
||||
result = render_micron(content)
|
||||
|
||||
# Should return a Column containing Text controls
|
||||
assert isinstance(result, ft.Column)
|
||||
# Should return a ListView containing controls
|
||||
assert isinstance(result, ft.ListView)
|
||||
assert result.expand is True
|
||||
assert result.scroll == ft.ScrollMode.AUTO
|
||||
assert result.spacing == 2
|
||||
|
||||
# Should contain Text controls
|
||||
# Should contain controls
|
||||
assert len(result.controls) > 0
|
||||
for control in result.controls:
|
||||
assert isinstance(control, ft.Text)
|
||||
assert control.selectable is True
|
||||
assert control.font_family == "monospace"
|
||||
|
||||
@@ -85,35 +83,29 @@ class TestMicronRenderer:
|
||||
content = ""
|
||||
result = render_micron(content)
|
||||
|
||||
# Should return a Column
|
||||
assert isinstance(result, ft.Column)
|
||||
# Should return a ListView
|
||||
assert isinstance(result, ft.ListView)
|
||||
assert result.expand is True
|
||||
assert result.scroll == ft.ScrollMode.AUTO
|
||||
|
||||
# May contain empty Text controls
|
||||
for control in result.controls:
|
||||
assert isinstance(control, ft.Text)
|
||||
# May contain empty controls
|
||||
|
||||
def test_render_micron_unicode(self):
|
||||
"""Test micron rendering with Unicode characters."""
|
||||
content = "Unicode content: 你好 🌍 αβγ"
|
||||
result = render_micron(content)
|
||||
|
||||
# Should return a Column
|
||||
assert isinstance(result, ft.Column)
|
||||
# Should return a ListView
|
||||
assert isinstance(result, ft.ListView)
|
||||
assert result.expand is True
|
||||
assert result.scroll == ft.ScrollMode.AUTO
|
||||
|
||||
# Should contain Text controls with the content
|
||||
assert len(result.controls) > 0
|
||||
all_text = ""
|
||||
for control in result.controls:
|
||||
assert isinstance(control, ft.Text)
|
||||
if hasattr(control, 'value') and control.value:
|
||||
all_text += control.value
|
||||
elif hasattr(control, 'spans') and control.spans:
|
||||
for span in control.spans:
|
||||
all_text += span.text
|
||||
# Extract text from the merged control
|
||||
if hasattr(control, "_Control__attrs") and "value" in control._Control__attrs:
|
||||
all_text += control._Control__attrs["value"][0]
|
||||
|
||||
# Should preserve the content
|
||||
assert content in all_text
|
||||
@@ -129,9 +121,9 @@ class TestRendererComparison:
|
||||
plaintext_result = render_plaintext(content)
|
||||
micron_result = render_micron(content)
|
||||
|
||||
# Plaintext returns Text, Micron returns Column
|
||||
# Plaintext returns Text, Micron returns ListView
|
||||
assert isinstance(plaintext_result, ft.Text)
|
||||
assert isinstance(micron_result, ft.Column)
|
||||
assert isinstance(micron_result, ft.ListView)
|
||||
|
||||
def test_renderers_preserve_content(self):
|
||||
"""Test that both renderers preserve the original content."""
|
||||
@@ -142,16 +134,13 @@ class TestRendererComparison:
|
||||
|
||||
assert plaintext_result.value == content
|
||||
|
||||
# For micron result (Column), extract text from controls
|
||||
# For micron result (ListView), extract text from merged controls
|
||||
micron_text = ""
|
||||
for control in micron_result.controls:
|
||||
if isinstance(control, ft.Text):
|
||||
if hasattr(control, 'value') and control.value:
|
||||
micron_text += control.value + "\n"
|
||||
elif hasattr(control, 'spans') and control.spans:
|
||||
for span in control.spans:
|
||||
micron_text += span.text
|
||||
micron_text += "\n"
|
||||
# Extract text from the merged control
|
||||
if hasattr(control, "_Control__attrs") and "value" in control._Control__attrs:
|
||||
micron_text += control._Control__attrs["value"][0] + "\n"
|
||||
|
||||
# Remove trailing newline and compare
|
||||
micron_text = micron_text.rstrip("\n")
|
||||
@@ -169,9 +158,8 @@ class TestRendererComparison:
|
||||
assert plaintext_result.font_family == "monospace"
|
||||
assert plaintext_result.expand is True
|
||||
|
||||
# For micron result (Column), check properties of contained controls
|
||||
# For micron result (ListView), check properties
|
||||
assert micron_result.expand is True
|
||||
assert micron_result.scroll == ft.ScrollMode.AUTO
|
||||
assert micron_result.spacing == 2
|
||||
|
||||
# Check that all Text controls in the column have the expected properties
|
||||
|
||||
@@ -18,7 +18,7 @@ class TestStorageManager:
|
||||
def test_storage_manager_init_without_page(self):
|
||||
"""Test StorageManager initialization without a page."""
|
||||
with patch(
|
||||
"ren_browser.storage.storage.StorageManager._get_storage_directory"
|
||||
"ren_browser.storage.storage.StorageManager._get_storage_directory",
|
||||
) as mock_get_dir:
|
||||
mock_dir = Path("/mock/storage")
|
||||
mock_get_dir.return_value = mock_dir
|
||||
@@ -35,7 +35,7 @@ class TestStorageManager:
|
||||
mock_page = Mock()
|
||||
|
||||
with patch(
|
||||
"ren_browser.storage.storage.StorageManager._get_storage_directory"
|
||||
"ren_browser.storage.storage.StorageManager._get_storage_directory",
|
||||
) as mock_get_dir:
|
||||
mock_dir = Path("/mock/storage")
|
||||
mock_get_dir.return_value = mock_dir
|
||||
@@ -51,12 +51,12 @@ class TestStorageManager:
|
||||
with (
|
||||
patch("os.name", "posix"),
|
||||
patch.dict(
|
||||
"os.environ", {"XDG_CONFIG_HOME": "/home/user/.config"}, clear=True
|
||||
"os.environ", {"XDG_CONFIG_HOME": "/home/user/.config"}, clear=True,
|
||||
),
|
||||
patch("pathlib.Path.mkdir"),
|
||||
):
|
||||
with patch(
|
||||
"ren_browser.storage.storage.StorageManager._ensure_storage_directory"
|
||||
"ren_browser.storage.storage.StorageManager._ensure_storage_directory",
|
||||
):
|
||||
storage = StorageManager()
|
||||
storage._storage_dir = storage._get_storage_directory()
|
||||
@@ -76,7 +76,7 @@ class TestStorageManager:
|
||||
patch("pathlib.Path.mkdir"),
|
||||
):
|
||||
with patch(
|
||||
"ren_browser.storage.storage.StorageManager._ensure_storage_directory"
|
||||
"ren_browser.storage.storage.StorageManager._ensure_storage_directory",
|
||||
):
|
||||
storage = StorageManager()
|
||||
storage._storage_dir = storage._get_storage_directory()
|
||||
@@ -141,7 +141,7 @@ class TestStorageManager:
|
||||
|
||||
assert result is True
|
||||
mock_page.client_storage.set.assert_called_with(
|
||||
"ren_browser_config", config_content
|
||||
"ren_browser_config", config_content,
|
||||
)
|
||||
|
||||
def test_save_config_fallback(self):
|
||||
@@ -169,7 +169,7 @@ class TestStorageManager:
|
||||
assert result is True
|
||||
# Check that the config was set to client storage
|
||||
mock_page.client_storage.set.assert_any_call(
|
||||
"ren_browser_config", config_content
|
||||
"ren_browser_config", config_content,
|
||||
)
|
||||
# Verify that client storage was called at least once
|
||||
assert mock_page.client_storage.set.call_count >= 1
|
||||
@@ -240,7 +240,7 @@ class TestStorageManager:
|
||||
bookmarks_path = storage._storage_dir / "bookmarks.json"
|
||||
assert bookmarks_path.exists()
|
||||
|
||||
with open(bookmarks_path, "r", encoding="utf-8") as f:
|
||||
with open(bookmarks_path, encoding="utf-8") as f:
|
||||
loaded_bookmarks = json.load(f)
|
||||
assert loaded_bookmarks == bookmarks
|
||||
|
||||
@@ -281,7 +281,7 @@ class TestStorageManager:
|
||||
history_path = storage._storage_dir / "history.json"
|
||||
assert history_path.exists()
|
||||
|
||||
with open(history_path, "r", encoding="utf-8") as f:
|
||||
with open(history_path, encoding="utf-8") as f:
|
||||
loaded_history = json.load(f)
|
||||
assert loaded_history == history
|
||||
|
||||
@@ -418,7 +418,7 @@ class TestStorageManagerEdgeCases:
|
||||
storage = StorageManager()
|
||||
|
||||
with patch(
|
||||
"pathlib.Path.write_text", side_effect=PermissionError("Access denied")
|
||||
"pathlib.Path.write_text", side_effect=PermissionError("Access denied"),
|
||||
):
|
||||
test_path = Path("/mock/path")
|
||||
result = storage._is_writable(test_path)
|
||||
|
||||
@@ -29,7 +29,7 @@ class TestBuildUI:
|
||||
@patch("ren_browser.tabs.tabs.TabsManager")
|
||||
@patch("ren_browser.controls.shortcuts.Shortcuts")
|
||||
def test_build_ui_appbar_setup(
|
||||
self, mock_shortcuts, mock_tabs, mock_fetcher, mock_announce_service, mock_page
|
||||
self, mock_shortcuts, mock_tabs, mock_fetcher, mock_announce_service, mock_page,
|
||||
):
|
||||
"""Test that build_ui sets up the app bar correctly."""
|
||||
mock_tab_manager = Mock()
|
||||
@@ -51,7 +51,7 @@ class TestBuildUI:
|
||||
@patch("ren_browser.tabs.tabs.TabsManager")
|
||||
@patch("ren_browser.controls.shortcuts.Shortcuts")
|
||||
def test_build_ui_drawer_setup(
|
||||
self, mock_shortcuts, mock_tabs, mock_fetcher, mock_announce_service, mock_page
|
||||
self, mock_shortcuts, mock_tabs, mock_fetcher, mock_announce_service, mock_page,
|
||||
):
|
||||
"""Test that build_ui sets up the drawer correctly."""
|
||||
mock_tab_manager = Mock()
|
||||
|
||||
Reference in New Issue
Block a user