1 # This test can be run stand-alone with something like:
2 # > PYTHONPATH=. python2 openerp/tests/test_misc.py
5 from ..tools import misc
7 class append_content_to_html(unittest2.TestCase):
8 """ Test some of our generic utility functions """
10 def test_append_to_html(self):
12 ('<!DOCTYPE...><HTML encoding="blah">some <b>content</b></HtMl>', '--\nYours truly', True,
13 '<!DOCTYPE...><html encoding="blah">some <b>content</b>\n<pre>--\nYours truly</pre>\n</html>'),
14 ('<html><body>some <b>content</b></body></html>', '<!DOCTYPE...>\n<html><body>\n<p>--</p>\n<p>Yours truly</p>\n</body>\n</html>', False,
15 '<html><body>some <b>content</b>\n\n\n<p>--</p>\n<p>Yours truly</p>\n\n\n</body></html>'),
17 for html, content, flag, expected in test_samples:
18 self.assertEqual(misc.append_content_to_html(html,content,flag), expected, 'append_content_to_html is broken')
20 class test_countingstream(unittest2.TestCase):
21 def test_empty_stream(self):
22 s = misc.CountingStream(iter([]))
23 self.assertEqual(s.index, -1)
24 self.assertIsNone(next(s, None))
25 self.assertEqual(s.index, 0)
27 def test_single(self):
28 s = misc.CountingStream(xrange(1))
29 self.assertEqual(s.index, -1)
30 self.assertEqual(next(s, None), 0)
31 self.assertIsNone(next(s, None))
32 self.assertEqual(s.index, 1)
35 s = misc.CountingStream(xrange(42))
38 self.assertEqual(s.index, 42)
40 def test_repeated(self):
41 """ Once the CountingStream has stopped iterating, the index should not
42 increase anymore (the internal state should not be allowed to change)
44 s = misc.CountingStream(iter([]))
45 self.assertIsNone(next(s, None))
46 self.assertEqual(s.index, 0)
47 self.assertIsNone(next(s, None))
48 self.assertEqual(s.index, 0)
50 if __name__ == '__main__':