Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
malthe committed Sep 15, 2023
1 parent c0d0eff commit 3b3625f
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/chameleon/tests/test_bools_plus_sniffing.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
</html>
"""


class BaseTestCase(unittest.TestCase):
def get_template(self, text):
template = PageTemplate(text)
Expand All @@ -62,12 +63,13 @@ def get_template_str(self):

def assert_same(self, s1, s2):
L1 = s1.splitlines()
L1 = list(filter(None, [ ' '.join(x.split()).strip() for x in L1 ]))
L1 = list(filter(None, [' '.join(x.split()).strip() for x in L1]))
L2 = s2.splitlines()
L2 = list(filter(None, [ ' '.join(x.split()).strip() for x in L2 ]))
L2 = list(filter(None, [' '.join(x.split()).strip() for x in L2]))
diff = '\n'.join(list(difflib.unified_diff(L1, L2)))
assert diff == '', diff


class XMLTestCase(BaseTestCase):

input_bytes = xml_bytes
Expand Down Expand Up @@ -98,7 +100,7 @@ def test_bytes_checked_true(self):
"""
result = template(checked=True)
self.assert_same(expected, result)

def test_bytes_checked_false(self):
template = self.get_template_bytes()
expected = """
Expand All @@ -118,7 +120,7 @@ def test_bytes_checked_None(self):
"""
result = template(checked=None)
self.assert_same(expected, result)

def test_bytes_checked_default(self):
template = self.get_template_bytes()
expected = """
Expand All @@ -138,7 +140,7 @@ def test_str_checked_true(self):
"""
result = template(checked=True)
self.assert_same(expected, result)

def test_str_checked_false(self):
template = self.get_template_str()
expected = """
Expand All @@ -158,7 +160,7 @@ def test_str_checked_None(self):
"""
result = template(checked=None)
self.assert_same(expected, result)

def test_str_checked_default(self):
template = self.get_template_str()
expected = """
Expand All @@ -168,7 +170,8 @@ def test_str_checked_default(self):
"""
result = template(checked=template.default_marker.value)
self.assert_same(expected, result)



class XMLWithEncodingTestCase(BaseTestCase):

input_bytes = xml_w_enc_bytes
Expand All @@ -177,11 +180,12 @@ class XMLWithEncodingTestCase(BaseTestCase):
def test_bytes_encoding(self):
template = self.get_template_bytes()
self.assertEqual(template.content_encoding, self.encoding)

def test_str_encoding(self):
template = self.get_template_str()
self.assertEqual(template.content_encoding, self.encoding)


class HTML5TestCase(BaseTestCase):

input_bytes = html5_bytes
Expand Down Expand Up @@ -220,7 +224,7 @@ def test_bytes_checked_true(self):
"""
result = template(checked=True)
self.assert_same(expected, result)

def test_bytes_checked_false(self):
template = self.get_template_bytes()
expected = """
Expand Down Expand Up @@ -258,7 +262,7 @@ def test_bytes_checked_None(self):
"""
result = template(checked=None)
self.assert_same(expected, result)

def test_bytes_checked_default(self):
template = self.get_template_bytes()
expected = """
Expand Down Expand Up @@ -296,7 +300,7 @@ def test_str_checked_true(self):
"""
result = template(checked=True)
self.assert_same(expected, result)

def test_str_checked_false(self):
template = self.get_template_str()
expected = """
Expand Down Expand Up @@ -334,7 +338,7 @@ def test_str_checked_None(self):
"""
result = template(checked=None)
self.assert_same(expected, result)

def test_str_checked_default(self):
template = self.get_template_str()
expected = """
Expand All @@ -354,23 +358,23 @@ def test_str_checked_default(self):
result = template(checked=template.default_marker.value)
self.assert_same(expected, result)


class HTML5WithContentTypeAndEncodingTestCase(BaseTestCase):

input_bytes = html5_w_ct_n_enc_bytes

def test_bytes_content_type(self):
template = self.get_template_bytes()
self.assertEqual(template.content_type, 'foo/bar')

def test_bytes_encoding(self):
template = self.get_template_bytes()
self.assertEqual(template.content_encoding, 'utf-8')

def test_str_content_type(self):
template = self.get_template_str()
self.assertEqual(template.content_type, 'foo/bar')

def test_str_encoding(self):
template = self.get_template_str()
self.assertEqual(template.content_encoding, 'utf-8')

0 comments on commit 3b3625f

Please sign in to comment.