]> git.aero2k.de Git - sirius.git/commitdiff
We got our first snapshot tests for HTML rendering
authorJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 01:20:21 +0000 (18:20 -0700)
committerJoshua May <notjosh@gmail.com>
Mon, 14 Oct 2019 01:20:21 +0000 (18:20 -0700)
requirements.txt
sirius/coding/snapshots/__init__.py [new file with mode: 0644]
sirius/coding/snapshots/snap_test_image_coding.py [new file with mode: 0644]
sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png [new file with mode: 0644]
sirius/coding/test_image_coding.py

index 8ab88a2f6bb5f24d09e3a46ef2c4b7f1f5a268bf..93e819e9cbc9089de7484f14b21b761f184cfc1b 100755 (executable)
@@ -36,5 +36,6 @@ requests==2.22.0
 requests-oauthlib==1.2.0
 selenium==3.141.0
 six==1.12.0
+git+git://github.com/syrusakbary/snapshottest.git@4ac2b4fb09e9e7728bebb11967c164a914775d1d#snapshottest
 twitter==1.18.0
 websocket-client==0.56.0
diff --git a/sirius/coding/snapshots/__init__.py b/sirius/coding/snapshots/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sirius/coding/snapshots/snap_test_image_coding.py b/sirius/coding/snapshots/snap_test_image_coding.py
new file mode 100644 (file)
index 0000000..d10dcb1
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- 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
new file mode 100644 (file)
index 0000000..6c11f48
Binary files /dev/null and b/sirius/coding/snapshots/snap_test_image_coding/ImageSnapshotCase::test_snapshot_fixtures hello_world.png differ
index 081b8af6c55e3b7546bb6b44d0ebfcca635e24ec..2d529c7aa61ff41a07e3f1568f582aa75490440e 100644 (file)
@@ -1,5 +1,9 @@
+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
 
@@ -21,6 +25,21 @@ 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):