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