]> git.aero2k.de Git - sirius.git/commitdiff
Moved snapshot tests to their own file, and added template testing
authorJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 01:57:51 +0000 (18:57 -0700)
committerJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 01:57:51 +0000 (18:57 -0700)
sirius/coding/snapshots/snap_test_image_coding.py [deleted file]
sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png [deleted file]
sirius/coding/snapshots/snap_test_image_coding_snapshots.py [new file with mode: 0644]
sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png [new file with mode: 0644]
sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png [new file with mode: 0644]
sirius/coding/test_image_coding.py
sirius/coding/test_image_coding_snapshots.py [new file with mode: 0644]

diff --git a/sirius/coding/snapshots/snap_test_image_coding.py b/sirius/coding/snapshots/snap_test_image_coding.py
deleted file mode 100644 (file)
index d10dcb1..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# -*- coding: utf-8 -*-
-# snapshottest: v1 - https://goo.gl/zC4yUc
-from __future__ import unicode_literals
-
-from snapshottest import Snapshot
-from snapshottest.file import FileSnapshot
-
-
-snapshots = Snapshot()
-
-snapshots['ImageSnapshotCase::test_snapshot_fixtures hello_world'] = FileSnapshot('snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png')
diff --git a/sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png b/sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png
deleted file mode 100644 (file)
index b8389f2..0000000
Binary files a/sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png and /dev/null differ
diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots.py b/sirius/coding/snapshots/snap_test_image_coding_snapshots.py
new file mode 100644 (file)
index 0000000..06aa55c
--- /dev/null
@@ -0,0 +1,13 @@
+# -*- coding: utf-8 -*-
+# snapshottest: v1 - https://goo.gl/zC4yUc
+from __future__ import unicode_literals
+
+from snapshottest import Snapshot
+from snapshottest.file import FileSnapshot
+
+
+snapshots = Snapshot()
+
+snapshots['ImageCodingSnapshotCase::test_snapshot_fixtures hello_world'] = FileSnapshot('snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png')
+
+snapshots['ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world'] = FileSnapshot('snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png')
diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png
new file mode 100644 (file)
index 0000000..6c11f48
Binary files /dev/null and b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_fixtures hello_world.png differ
diff --git a/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png
new file mode 100644 (file)
index 0000000..54a061e
Binary files /dev/null and b/sirius/coding/snapshots/snap_test_image_coding_snapshots/ImageCodingSnapshotCase::test_snapshot_template_fixtures hello_world.png differ
index 2d529c7aa61ff41a07e3f1568f582aa75490440e..c8b684f3aa00dff71ef9876d66a81ea0797bdced 100644 (file)
@@ -1,13 +1,8 @@
-import os
-from tempfile import TemporaryDirectory
 from PIL import Image, ImageDraw
 import unittest
-import snapshottest
-from snapshottest.file import FileSnapshot
 
 from sirius.coding import image_encoding
 
-
 class ImageCase(unittest.TestCase):
     def test_normal_text(self):
         data = image_encoding.html_to_png(
@@ -25,21 +20,6 @@ class ImageCase(unittest.TestCase):
         self.assertEquals(image.size[0], 384)
         self.assertEquals(image.size[1], 100)
 
-class ImageSnapshotCase(snapshottest.TestCase):
-    def test_snapshot_fixtures(self):
-        fixtures = {
-            'hello_world': '<html><body>Hello, world!</body></html>',
-        }
-
-        for name, html in fixtures.items():
-            with TemporaryDirectory() as tmpdir:
-                data = image_encoding.html_to_png(html)
-                image = Image.open(data)
-
-                temp_file_name = os.path.join(tmpdir, '%s.png' % name)
-                image.save(temp_file_name, format='PNG')
-                self.assertMatchSnapshot(FileSnapshot(temp_file_name), name)
-
 
 class PipeTestCase(unittest.TestCase):
     def test_specific_image_rle(self):
diff --git a/sirius/coding/test_image_coding_snapshots.py b/sirius/coding/test_image_coding_snapshots.py
new file mode 100644 (file)
index 0000000..7c0f858
--- /dev/null
@@ -0,0 +1,38 @@
+import os
+from tempfile import TemporaryDirectory
+from PIL import Image
+
+import snapshottest
+from snapshottest.file import FileSnapshot
+
+from sirius.coding import image_encoding
+from sirius.coding import templating
+
+
+class ImageCodingSnapshotCase(snapshottest.TestCase):
+    def _check_html(self, name, html):
+        print('Cheking fixture named: %s' % name)
+
+        with TemporaryDirectory() as tmpdir:
+            data = image_encoding.html_to_png(html)
+            image = Image.open(data)
+
+            temp_file_name = os.path.join(tmpdir, '%s.png' % name)
+            image.save(temp_file_name, format='PNG')
+            self.assertMatchSnapshot(FileSnapshot(temp_file_name), name)
+
+    def test_snapshot_fixtures(self):
+        fixtures = {
+            'hello_world': '<html><body>Hello, world!</body></html>',
+        }
+
+        for name, html in fixtures.items():
+            self._check_html(name, html)
+
+    def test_snapshot_template_fixtures(self):
+        fixtures = {
+            'hello_world': '<p>Hello, world!</p>',
+        }
+
+        for name, snippet in fixtures.items():
+            self._check_html(name, templating.default_template(snippet, 'anonymous'))
\ No newline at end of file