[ADD] big bit on new import: pretty much everything but o2m
[odoo/odoo.git] / openerp / tests / test_misc.py
index 7661f25..54ae698 100644 (file)
@@ -2,12 +2,12 @@
 # > PYTHONPATH=. python2 openerp/tests/test_misc.py
 
 import unittest2
+from ..tools import misc
 
-class test_misc(unittest2.TestCase):
+class append_content_to_html(unittest2.TestCase):
     """ Test some of our generic utility functions """
 
     def test_append_to_html(self):
-        from openerp.tools import append_content_to_html
         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>'),
@@ -15,7 +15,37 @@ class test_misc(unittest2.TestCase):
              '<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(append_content_to_html(html,content,flag), expected, 'append_content_to_html is broken')
+            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()
\ No newline at end of file
+    unittest2.main()