52 lines
2.0 KiB
Python
52 lines
2.0 KiB
Python
# This test can be run stand-alone with something like:
|
|
# > PYTHONPATH=. python2 openerp/tests/test_misc.py
|
|
|
|
import unittest2
|
|
from ..tools import misc
|
|
|
|
class append_content_to_html(unittest2.TestCase):
|
|
""" Test some of our generic utility functions """
|
|
|
|
def test_append_to_html(self):
|
|
test_samples = [
|
|
('<!DOCTYPE...><HTML encoding="blah">some <b>content</b></HtMl>', '--\nYours truly', True,
|
|
'<!DOCTYPE...><html encoding="blah">some <b>content</b>\n<pre>--\nYours truly</pre>\n</html>'),
|
|
('<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,
|
|
'<html><body>some <b>content</b>\n\n\n<p>--</p>\n<p>Yours truly</p>\n\n\n</body></html>'),
|
|
]
|
|
for html, content, flag, expected in test_samples:
|
|
self.assertEqual(misc.append_content_to_html(html,content,flag), expected, 'append_content_to_html is broken')
|
|
|
|
class test_countingstream(unittest2.TestCase):
|
|
def test_empty_stream(self):
|
|
s = misc.CountingStream(iter([]))
|
|
self.assertEqual(s.index, -1)
|
|
self.assertIsNone(next(s, None))
|
|
self.assertEqual(s.index, 0)
|
|
|
|
def test_single(self):
|
|
s = misc.CountingStream(xrange(1))
|
|
self.assertEqual(s.index, -1)
|
|
self.assertEqual(next(s, None), 0)
|
|
self.assertIsNone(next(s, None))
|
|
self.assertEqual(s.index, 1)
|
|
|
|
def test_full(self):
|
|
s = misc.CountingStream(xrange(42))
|
|
for _ in s:
|
|
pass
|
|
self.assertEqual(s.index, 42)
|
|
|
|
def test_repeated(self):
|
|
""" Once the CountingStream has stopped iterating, the index should not
|
|
increase anymore (the internal state should not be allowed to change)
|
|
"""
|
|
s = misc.CountingStream(iter([]))
|
|
self.assertIsNone(next(s, None))
|
|
self.assertEqual(s.index, 0)
|
|
self.assertIsNone(next(s, None))
|
|
self.assertEqual(s.index, 0)
|
|
|
|
if __name__ == '__main__':
|
|
unittest2.main()
|