]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
unit test for dumping as utf-8 to a file 218/head
authorAlex Morega <alex@grep.ro>
Sat, 18 May 2013 11:22:30 +0000 (14:22 +0300)
committerAlex Morega <alex@grep.ro>
Sat, 18 May 2013 11:23:37 +0000 (14:23 +0300)
jinja2/testsuite/api.py

index 53854372825e9d5ed5457df85b1d564ed6649abd..4f6a1d0ea0df303783d71ed2d35681a916a5cba2 100644 (file)
@@ -9,6 +9,9 @@
     :license: BSD, see LICENSE for more details.
 """
 import unittest
+import os
+import tempfile
+import shutil
 
 from jinja2.testsuite import JinjaTestCase
 
@@ -167,6 +170,17 @@ class StreamingTestCase(JinjaTestCase):
         stream.disable_buffering()
         assert not stream.buffered
 
+    def test_dump_stream(self):
+        tmp = tempfile.mkdtemp()
+        try:
+            tmpl = env.from_string(u"\u2713")
+            stream = tmpl.stream()
+            stream.dump(os.path.join(tmp, 'dump.txt'), 'utf-8')
+            with open(os.path.join(tmp, 'dump.txt'), 'rb') as f:
+                self.assertEqual(f.read(), b'\xe2\x9c\x93')
+        finally:
+            shutil.rmtree(tmp)
+
 
 class UndefinedTestCase(JinjaTestCase):