test_headers.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import unittest
  2. import makesite
  3. class HeaderTest(unittest.TestCase):
  4. """Tests for read_headers() function."""
  5. def test_single_header(self):
  6. text = '<!-- key1: val1 -->'
  7. headers = list(makesite.read_headers(text))
  8. self.assertEqual(headers, [('key1', 'val1', 19)])
  9. def test_multiple_headers(self):
  10. text = '<!-- key1: val1 -->\n<!-- key2: val2-->'
  11. headers = list(makesite.read_headers(text))
  12. self.assertEqual(headers, [('key1', 'val1', 20), ('key2', 'val2', 38)])
  13. def test_headers_and_text(self):
  14. text = '<!-- a: 1 -->\n<!-- b: 2 -->\nFoo\n<!-- c: 3 -->'
  15. headers = list(makesite.read_headers(text))
  16. self.assertEqual(headers, [('a', '1', 14), ('b', '2', 28)])
  17. def test_headers_and_blank_line(self):
  18. text = '<!-- a: 1 -->\n<!-- b: 2 -->\n\n<!-- c: 3 -->\n'
  19. headers = list(makesite.read_headers(text))
  20. self.assertEqual(headers, [('a', '1', 14),
  21. ('b', '2', 29),
  22. ('c', '3', 43)])
  23. def test_multiline_header(self):
  24. text = '<!--\na: 1 --><!-- b:\n2 -->\n<!-- c: 3\n-->'
  25. headers = list(makesite.read_headers(text))
  26. self.assertEqual(headers, [('a', '1', 13),
  27. ('b', '2', 27),
  28. ('c', '3', 40)])
  29. def test_no_header(self):
  30. headers = list(makesite.read_headers('Foo'))
  31. self.assertEqual(headers, [])
  32. def test_empty_string(self):
  33. headers = list(makesite.read_headers(''))
  34. self.assertEqual(headers, [])