Add some tests
This commit is contained in:
parent
ab4e54b543
commit
37b84adab5
3 changed files with 95 additions and 3 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
from .test_element_rendering import *
|
from .test_element_rendering import *
|
||||||
from .test_markup import *
|
from .test_markup import *
|
||||||
|
from .test_rendered_element_cache import *
|
||||||
|
|
||||||
__all__ = []
|
__all__ = []
|
||||||
|
|
||||||
__all__+= test_element_rendering.__all__
|
__all__+= test_element_rendering.__all__
|
||||||
__all__+= test_markup.__all__
|
__all__+= test_markup.__all__
|
||||||
|
__all__+= test_rendered_element_cache.__all__
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ class TestAttributedText(unittest.TestCase):
|
||||||
|
|
||||||
def test_equality_of_empty_text(self):
|
def test_equality_of_empty_text(self):
|
||||||
self.assertEqual(AT(), AT())
|
self.assertEqual(AT(), AT())
|
||||||
|
self.assertEqual(AT(), AT(attribute="value"))
|
||||||
|
|
||||||
def test_string_to_AT_to_string(self):
|
def test_string_to_AT_to_string(self):
|
||||||
for string in self.SAMPLE_STRINGS:
|
for string in self.SAMPLE_STRINGS:
|
||||||
|
|
@ -61,9 +62,11 @@ class TestAttributedText(unittest.TestCase):
|
||||||
def test_slicing_and_putting_back_together_with_attributes(self):
|
def test_slicing_and_putting_back_together_with_attributes(self):
|
||||||
text2 = self.text[:4] + self.text[4:11] + self.text[11:22] + self.text[22:]
|
text2 = self.text[:4] + self.text[4:11] + self.text[11:22] + self.text[22:]
|
||||||
text3 = self.text[:-20] + self.text[-20:-4] + self.text[-4:]
|
text3 = self.text[:-20] + self.text[-20:-4] + self.text[-4:]
|
||||||
|
text4 = self.text[:3] + self.text[3] + self.text[4:]
|
||||||
|
|
||||||
self.assertEqual(self.text, text2)
|
self.assertEqual(self.text, text2)
|
||||||
self.assertEqual(self.text, text3)
|
self.assertEqual(self.text, text3)
|
||||||
|
self.assertEqual(self.text, text4)
|
||||||
|
|
||||||
def test_removing_attributes(self):
|
def test_removing_attributes(self):
|
||||||
text = self.text.remove("attribute", 9, 15)
|
text = self.text.remove("attribute", 9, 15)
|
||||||
|
|
@ -108,6 +111,43 @@ class TestAttributedText(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(text1, text2)
|
self.assertEqual(text1, text2)
|
||||||
|
|
||||||
# TODO test find_all()
|
def test_repeating_by_multiplication(self):
|
||||||
# TODO test split_by()
|
text = AT("a", x=1) + AT("b", y=2)
|
||||||
# TODO test __mul__()
|
repeated_1 = text + text + text + text + text
|
||||||
|
repeated_2 = text * 5
|
||||||
|
repeated_3 = AT().join([text] * 5)
|
||||||
|
|
||||||
|
self.assertEqual(repeated_1, repeated_2)
|
||||||
|
self.assertEqual(repeated_1, repeated_3)
|
||||||
|
|
||||||
|
def test_split_by(self):
|
||||||
|
split = self.text.split_by("attribute")
|
||||||
|
expected = [
|
||||||
|
(AT("This "), None),
|
||||||
|
(
|
||||||
|
AT("is a sam", attribute="value") +
|
||||||
|
AT("p", attribute="value", attribute2="value2") +
|
||||||
|
AT("le stri", attribute="value"),
|
||||||
|
"value"
|
||||||
|
),
|
||||||
|
(AT("ng."), None),
|
||||||
|
]
|
||||||
|
self.assertEqual(split, expected)
|
||||||
|
|
||||||
|
split = self.text.split_by("attribute2")
|
||||||
|
expected = [
|
||||||
|
(
|
||||||
|
AT("This ") +
|
||||||
|
AT("is a sam", attribute="value"),
|
||||||
|
None
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AT("p", attribute="value", attribute2="value2"),
|
||||||
|
"value2"
|
||||||
|
),
|
||||||
|
(
|
||||||
|
AT("le stri", attribute="value") + AT("ng."),
|
||||||
|
None
|
||||||
|
),
|
||||||
|
]
|
||||||
|
self.assertEqual(split, expected)
|
||||||
|
|
|
||||||
50
test/test_rendered_element_cache.py
Normal file
50
test/test_rendered_element_cache.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from cheuph import Element, RenderedElementCache
|
||||||
|
|
||||||
|
__all__ = ["TestRenderedElementCache"]
|
||||||
|
|
||||||
|
class TestRenderedElementCache(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.cache = RenderedElementCache()
|
||||||
|
self.e1 = Element("e1", None)
|
||||||
|
self.e2 = Element("e2", "e1")
|
||||||
|
self.e3 = Element("e3", "xyz")
|
||||||
|
self.e1_2 = Element("e1", "bla")
|
||||||
|
|
||||||
|
def test_adding_and_getting(self):
|
||||||
|
self.assertEqual(self.cache.get("e1"), None)
|
||||||
|
self.assertEqual(self.cache.get("e2"), None)
|
||||||
|
|
||||||
|
self.cache.add(self.e1)
|
||||||
|
self.assertEqual(self.cache.get("e1"), self.e1)
|
||||||
|
|
||||||
|
self.cache.add(self.e2)
|
||||||
|
self.assertEqual(self.cache.get("e2"), self.e2)
|
||||||
|
|
||||||
|
self.cache.add(self.e1_2)
|
||||||
|
self.assertEqual(self.cache.get("e1"), self.e1_2)
|
||||||
|
|
||||||
|
self.assertEqual(self.cache.get("e3"), None)
|
||||||
|
self.cache.add(self.e3)
|
||||||
|
self.assertEqual(self.cache.get("e3"), self.e3)
|
||||||
|
|
||||||
|
def test_invalidating(self):
|
||||||
|
self.assertEqual(self.cache.get("e1"), None)
|
||||||
|
self.assertEqual(self.cache.get("e2"), None)
|
||||||
|
self.cache.add(self.e1)
|
||||||
|
self.cache.add(self.e2)
|
||||||
|
self.assertEqual(self.cache.get("e1"), self.e1)
|
||||||
|
self.assertEqual(self.cache.get("e2"), self.e2)
|
||||||
|
|
||||||
|
self.cache.invalidate("e1")
|
||||||
|
|
||||||
|
self.assertEqual(self.cache.get("e1"), None)
|
||||||
|
self.assertEqual(self.cache.get("e2"), self.e2)
|
||||||
|
|
||||||
|
self.cache.add(self.e1)
|
||||||
|
self.cache.invalidate_all()
|
||||||
|
|
||||||
|
self.assertEqual(self.cache.get("e1"), None)
|
||||||
|
self.assertEqual(self.cache.get("e2"), None)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue