auto flake and corrections

This commit is contained in:
2025-11-08 23:46:15 +01:00
parent 1ea870eef5
commit 781a9b6c08
81 changed files with 4646 additions and 3718 deletions
+33 -33
View File
@@ -3,20 +3,20 @@ Unit tests for LinkedWord and LinkedImage classes.
"""
import unittest
from pyWebLayout.abstract.inline import Word, LinkedWord
from pyWebLayout.abstract.block import Image, LinkedImage
from pyWebLayout.abstract.inline import LinkedWord
from pyWebLayout.abstract.block import LinkedImage
from pyWebLayout.abstract.functional import LinkType
from pyWebLayout.style import Font
class TestLinkedWord(unittest.TestCase):
"""Test cases for LinkedWord class."""
def setUp(self):
"""Set up test fixtures."""
self.font = Font(font_size=16)
self.location = "https://example.com"
def test_linked_word_creation(self):
"""Test creating a LinkedWord."""
linked_word = LinkedWord(
@@ -25,12 +25,12 @@ class TestLinkedWord(unittest.TestCase):
location=self.location,
link_type=LinkType.EXTERNAL
)
self.assertEqual(linked_word.text, "example")
self.assertEqual(linked_word.location, self.location)
self.assertEqual(linked_word.link_type, LinkType.EXTERNAL)
self.assertIsNone(linked_word.link_callback)
def test_linked_word_inherits_from_word(self):
"""Test that LinkedWord inherits Word properties."""
linked_word = LinkedWord(
@@ -38,21 +38,21 @@ class TestLinkedWord(unittest.TestCase):
style=self.font,
location=self.location
)
# Should have Word properties
self.assertEqual(linked_word.text, "test")
self.assertEqual(linked_word.style, self.font)
self.assertIsNone(linked_word.previous)
self.assertIsNone(linked_word.next)
def test_linked_word_with_callback(self):
"""Test LinkedWord with a callback function."""
callback_called = []
def test_callback(location, **params):
callback_called.append((location, params))
return "navigated"
linked_word = LinkedWord(
text="click",
style=self.font,
@@ -61,15 +61,15 @@ class TestLinkedWord(unittest.TestCase):
callback=test_callback,
params={"source": "test"}
)
result = linked_word.execute_link()
linked_word.execute_link()
self.assertEqual(len(callback_called), 1)
self.assertEqual(callback_called[0][0], self.location)
self.assertIn("text", callback_called[0][1])
self.assertEqual(callback_called[0][1]["text"], "click")
self.assertEqual(callback_called[0][1]["source"], "test")
def test_linked_word_execute_external_link(self):
"""Test executing an external link returns the location."""
linked_word = LinkedWord(
@@ -78,10 +78,10 @@ class TestLinkedWord(unittest.TestCase):
location=self.location,
link_type=LinkType.EXTERNAL
)
result = linked_word.execute_link()
self.assertEqual(result, self.location)
def test_linked_word_with_title(self):
"""Test LinkedWord with title/tooltip."""
linked_word = LinkedWord(
@@ -90,9 +90,9 @@ class TestLinkedWord(unittest.TestCase):
location=self.location,
title="Click to visit example.com"
)
self.assertEqual(linked_word.link_title, "Click to visit example.com")
def test_linked_word_chain(self):
"""Test chaining multiple LinkedWords."""
word1 = LinkedWord(
@@ -100,14 +100,14 @@ class TestLinkedWord(unittest.TestCase):
style=self.font,
location=self.location
)
word2 = LinkedWord(
text="here",
style=self.font,
location=self.location,
previous=word1
)
# Check chain
self.assertEqual(word1.next, word2)
self.assertEqual(word2.previous, word1)
@@ -115,13 +115,13 @@ class TestLinkedWord(unittest.TestCase):
class TestLinkedImage(unittest.TestCase):
"""Test cases for LinkedImage class."""
def setUp(self):
"""Set up test fixtures."""
self.source = "logo.png"
self.alt_text = "Company Logo"
self.location = "https://example.com/home"
def test_linked_image_creation(self):
"""Test creating a LinkedImage."""
linked_image = LinkedImage(
@@ -132,14 +132,14 @@ class TestLinkedImage(unittest.TestCase):
height=50,
link_type=LinkType.EXTERNAL
)
self.assertEqual(linked_image.source, self.source)
self.assertEqual(linked_image.alt_text, self.alt_text)
self.assertEqual(linked_image.location, self.location)
self.assertEqual(linked_image.width, 100)
self.assertEqual(linked_image.height, 50)
self.assertEqual(linked_image.link_type, LinkType.EXTERNAL)
def test_linked_image_inherits_from_image(self):
"""Test that LinkedImage inherits Image properties."""
linked_image = LinkedImage(
@@ -147,20 +147,20 @@ class TestLinkedImage(unittest.TestCase):
alt_text=self.alt_text,
location=self.location
)
# Should have Image properties and methods
self.assertEqual(linked_image.source, self.source)
self.assertEqual(linked_image.alt_text, self.alt_text)
self.assertIsNotNone(linked_image.get_dimensions)
def test_linked_image_with_callback(self):
"""Test LinkedImage with a callback function."""
callback_called = []
def image_callback(location, **params):
callback_called.append((location, params))
return "image_clicked"
linked_image = LinkedImage(
source=self.source,
alt_text=self.alt_text,
@@ -168,15 +168,15 @@ class TestLinkedImage(unittest.TestCase):
link_type=LinkType.FUNCTION,
callback=image_callback
)
result = linked_image.execute_link()
linked_image.execute_link()
self.assertEqual(len(callback_called), 1)
self.assertEqual(callback_called[0][0], self.location)
self.assertIn("alt_text", callback_called[0][1])
self.assertEqual(callback_called[0][1]["alt_text"], self.alt_text)
self.assertIn("source", callback_called[0][1])
def test_linked_image_execute_internal_link(self):
"""Test executing an internal link returns the location."""
linked_image = LinkedImage(
@@ -185,7 +185,7 @@ class TestLinkedImage(unittest.TestCase):
location="#section2",
link_type=LinkType.INTERNAL
)
result = linked_image.execute_link()
self.assertEqual(result, "#section2")