More tests
All checks were successful
CI / test (push) Successful in 4m40s
Lint / test (push) Successful in 31s
Trivy / test (push) Successful in 23s

This commit is contained in:
Miguel Jacq 2025-11-21 14:30:38 +11:00
parent e8db5bcf7d
commit ca3c839c7d
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
5 changed files with 1184 additions and 3 deletions

View file

@ -1,3 +1,4 @@
import base64
import pytest
from PySide6.QtCore import Qt, QPoint
@ -1808,3 +1809,453 @@ def test_insert_alarm_marker_on_checkbox_line_does_not_merge_lines(editor, qtbot
# Second line has the alarm marker
assert "Foobar" in lines[1]
assert "⏰ 16:54" in lines[1]
def test_render_images_with_corrupted_data(qtbot, app):
"""Test rendering images with corrupted data that creates null QImage"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
# Create some binary data that will decode but not form a valid image
corrupted_data = base64.b64encode(b"not an image file").decode("utf-8")
markdown = f"![corrupted](data:image/png;base64,{corrupted_data})"
editor.from_markdown(markdown)
qtbot.wait(50)
# Should still work without crashing
text = editor.to_markdown()
assert len(text) >= 0
def test_insert_alarm_marker(qtbot, app):
"""Test inserting alarm markers"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
# Insert alarm marker
editor.insert_alarm_marker("14:30")
qtbot.wait(50)
content = editor.to_markdown()
assert "14:30" in content or "" in content
def test_editor_with_tables(qtbot, app):
"""Test editor with markdown tables"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
table_markdown = """
| Header 1 | Header 2 |
|----------|----------|
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |
"""
editor.from_markdown(table_markdown)
qtbot.wait(50)
result = editor.to_markdown()
assert "Header 1" in result or "|" in result
def test_editor_with_code_blocks(qtbot, app):
"""Test editor with code blocks"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
code_markdown = """
Some text
```python
def hello():
print("world")
```
More text
"""
editor.from_markdown(code_markdown)
qtbot.wait(50)
result = editor.to_markdown()
assert "def hello" in result or "python" in result
def test_editor_undo_redo(qtbot, app):
"""Test undo/redo functionality"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
# Type some text
editor.from_markdown("Initial text")
qtbot.wait(50)
# Add more text
editor.insertPlainText(" additional")
qtbot.wait(50)
# Undo
editor.undo()
qtbot.wait(50)
# Redo
editor.redo()
qtbot.wait(50)
assert len(editor.to_markdown()) > 0
def test_editor_cut_copy_paste(qtbot, app):
"""Test cut/copy/paste operations"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
editor.from_markdown("Test content for copy")
qtbot.wait(50)
# Select all
editor.selectAll()
# Copy
editor.copy()
qtbot.wait(50)
# Move to end and paste
cursor = editor.textCursor()
cursor.movePosition(QTextCursor.End)
editor.setTextCursor(cursor)
editor.paste()
qtbot.wait(50)
# Should have content twice (or clipboard might be empty in test env)
assert len(editor.to_markdown()) > 0
def test_editor_with_blockquotes(qtbot, app):
"""Test editor with blockquotes"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
quote_markdown = """
Normal text
> This is a quote
> With multiple lines
More normal text
"""
editor.from_markdown(quote_markdown)
qtbot.wait(50)
result = editor.to_markdown()
assert ">" in result or "quote" in result
def test_editor_with_horizontal_rules(qtbot, app):
"""Test editor with horizontal rules"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
hr_markdown = """
Section 1
---
Section 2
"""
editor.from_markdown(hr_markdown)
qtbot.wait(50)
result = editor.to_markdown()
assert "Section" in result
def test_editor_with_mixed_content(qtbot, app):
"""Test editor with mixed markdown content"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
mixed_markdown = """
# Heading
This is **bold** and *italic* text.
- [ ] Todo item
- [x] Completed item
```python
code()
```
[Link](https://example.com)
> Quote
| Table | Header |
|-------|--------|
| A | B |
"""
editor.from_markdown(mixed_markdown)
qtbot.wait(50)
result = editor.to_markdown()
# Should contain various markdown elements
assert len(result) > 50
def test_editor_insert_text_at_cursor(qtbot, app):
"""Test inserting text at cursor position"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
editor.from_markdown("Start Middle End")
qtbot.wait(50)
# Move cursor to middle
cursor = editor.textCursor()
cursor.setPosition(6)
editor.setTextCursor(cursor)
# Insert text
editor.insertPlainText("INSERTED ")
qtbot.wait(50)
result = editor.to_markdown()
assert "INSERTED" in result
def test_editor_delete_operations(qtbot, app):
"""Test delete operations"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
editor = MarkdownEditor(theme_manager=themes)
qtbot.addWidget(editor)
editor.show()
editor.from_markdown("Text to delete")
qtbot.wait(50)
# Select some text and delete
cursor = editor.textCursor()
cursor.setPosition(0)
cursor.setPosition(4, QTextCursor.KeepAnchor)
editor.setTextCursor(cursor)
cursor.removeSelectedText()
qtbot.wait(50)
result = editor.to_markdown()
assert "Text" not in result or len(result) < 15
def test_markdown_highlighter_dark_theme(qtbot, app):
"""Test markdown highlighter with dark theme - covers lines 74-75"""
# Create theme manager with dark theme
themes = ThemeManager(app, ThemeConfig(theme=Theme.DARK))
# Create a text document
doc = QTextDocument()
# Create highlighter with dark theme
highlighter = MarkdownHighlighter(doc, themes)
# Set some markdown text
doc.setPlainText("# Heading\n\nSome **bold** text\n\n```python\ncode\n```")
# The highlighter should work with dark theme
assert highlighter is not None
assert highlighter.code_block_format is not None
def test_markdown_highlighter_light_theme(qtbot, app):
"""Test markdown highlighter with light theme"""
# Create theme manager with light theme
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
# Create a text document
doc = QTextDocument()
# Create highlighter with light theme
highlighter = MarkdownHighlighter(doc, themes)
# Set some markdown text
doc.setPlainText("# Heading\n\nSome **bold** text")
# The highlighter should work with light theme
assert highlighter is not None
assert highlighter.code_block_format is not None
def test_markdown_highlighter_system_dark_theme(qtbot, app, monkeypatch):
"""Test markdown highlighter with system dark theme"""
# Create theme manager with system theme
themes = ThemeManager(app, ThemeConfig(theme=Theme.SYSTEM))
# Mock the system to be dark
monkeypatch.setattr(themes, "_is_system_dark", True)
# Create a text document
doc = QTextDocument()
# Create highlighter
highlighter = MarkdownHighlighter(doc, themes)
# Set some markdown text
doc.setPlainText("# Dark Theme Heading\n\n**Bold text**")
# The highlighter should use dark theme colors
assert highlighter is not None
def test_markdown_highlighter_with_headings(qtbot, app):
"""Test highlighting various heading levels"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
# H1 Heading
## H2 Heading
### H3 Heading
#### H4 Heading
##### H5 Heading
###### H6 Heading
"""
doc.setPlainText(markdown)
# Should highlight all headings
assert highlighter.h1_format is not None
assert highlighter.h2_format is not None
def test_markdown_highlighter_with_emphasis(qtbot, app):
"""Test highlighting bold and italic"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
**Bold text**
*Italic text*
***Bold and italic***
__Also bold__
_Also italic_
"""
doc.setPlainText(markdown)
# Should have emphasis formats
assert highlighter is not None
def test_markdown_highlighter_with_code(qtbot, app):
"""Test highlighting inline code and code blocks"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
Inline `code` here.
```python
def hello():
print("world")
```
More text.
"""
doc.setPlainText(markdown)
# Should highlight code
assert highlighter.code_block_format is not None
def test_markdown_highlighter_with_links(qtbot, app):
"""Test highlighting links"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
[Link text](https://example.com)
<https://auto-link.com>
"""
doc.setPlainText(markdown)
# Should have link format
assert highlighter is not None
def test_markdown_highlighter_with_lists(qtbot, app):
"""Test highlighting lists"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
- Unordered item 1
- Unordered item 2
1. Ordered item 1
2. Ordered item 2
- [ ] Unchecked task
- [x] Checked task
"""
doc.setPlainText(markdown)
# Should highlight lists
assert highlighter is not None
def test_markdown_highlighter_with_blockquotes(qtbot, app):
"""Test highlighting blockquotes"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = """
> This is a quote
> With multiple lines
"""
doc.setPlainText(markdown)
# Should highlight quotes
assert highlighter is not None
def test_markdown_highlighter_theme_change(qtbot, app):
"""Test changing theme after creation"""
themes = ThemeManager(app, ThemeConfig(theme=Theme.LIGHT))
doc = QTextDocument()
highlighter = MarkdownHighlighter(doc, themes)
markdown = "# Heading\n\n**Bold**"
doc.setPlainText(markdown)
# Change to dark theme
themes.apply(Theme.DARK)
qtbot.wait(50)
# Highlighter should update
# We can't directly test the visual change, but verify it doesn't crash
assert highlighter is not None