From: Joshua May Date: Mon, 14 Oct 2019 01:57:51 +0000 (-0700) Subject: Moved snapshot tests to their own file, and added template testing X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=eac59cbfce65668b40163fcfc09bab0acabec98c;p=sirius.git Moved snapshot tests to their own file, and added template testing --- diff --git a/sirius/coding/snapshots/snap_test_image_coding.py b/sirius/coding/snapshots/snap_test_image_coding.py deleted file mode 100644 index d10dcb1..0000000 --- a/sirius/coding/snapshots/snap_test_image_coding.py +++ /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 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 index 0000000..06aa55c --- /dev/null +++ b/sirius/coding/snapshots/snap_test_image_coding_snapshots.py @@ -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 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 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 diff --git a/sirius/coding/test_image_coding.py b/sirius/coding/test_image_coding.py index 2d529c7..c8b684f 100644 --- a/sirius/coding/test_image_coding.py +++ b/sirius/coding/test_image_coding.py @@ -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': 'Hello, world!', - } - - 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 index 0000000..7c0f858 --- /dev/null +++ b/sirius/coding/test_image_coding_snapshots.py @@ -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': 'Hello, world!', + } + + for name, html in fixtures.items(): + self._check_html(name, html) + + def test_snapshot_template_fixtures(self): + fixtures = { + 'hello_world': '

Hello, world!

', + } + + for name, snippet in fixtures.items(): + self._check_html(name, templating.default_template(snippet, 'anonymous')) \ No newline at end of file