예제 #1
0
    def test_should_return_true_if_both_files_contain_the_same_content(self):
        tmp = tempfile.gettempdir()
        a = os.path.join(tmp, 'a.txt')
        file_put_contents(a, 'Hello World')

        tmp = tempfile.gettempdir()
        b = os.path.join(tmp, 'b.txt')
        file_put_contents(b, 'Hello World')

        self.assertTrue(is_same_file(a, b))
예제 #2
0
    def test_should_return_false_if_both_files_do_not_contain_the_same_content(
            self):
        tmp = tempfile.gettempdir()
        a = os.path.join(tmp, 'a.txt')
        file_put_contents(a, 'Hello Foo')

        tmp = tempfile.gettempdir()
        b = os.path.join(tmp, 'b.txt')
        file_put_contents(b, 'Hello Bar')

        self.assertFalse(is_same_file(a, b))
예제 #3
0
    def test_should_not_change_pure_vector_image(self):
        src = self.get_test_image_path('test.svg')
        dst = os.path.join(tempfile.gettempdir(), 'resized_svg_image.svg')
        try:
            resize_svg_image(src, dst, 0, 0, crop=False, optimize=False)

            # svg file without any bitmap data embedded should be the same
            # image after resize (without optimizations)...
            self.assertTrue(is_same_file(src, dst))
        finally:
            if os.path.isfile(dst):
                os.unlink(dst)
예제 #4
0
    def test_should_ignore_embedded_bitmap_if_image_data_cannot_be_read_or_processed(self):
        src = self.get_test_image_path('test_svg_with_broken_png.svg')
        dst = os.path.join(tempfile.gettempdir(), 'resized_svg_image.svg')
        try:
            resize_svg_image(src, dst, 0, 0, crop=False, optimize=False)

            # svg file with broken bitmap data should be the same as the
            # original without optimizations (ignored)...
            self.assertTrue(is_same_file(src, dst))
        finally:
            if os.path.isfile(dst):
                os.unlink(dst)
예제 #5
0
    def test_should_ignore_embedded_bitmap_if_image_cannot_be_b64_decoded(self):
        src = self.get_test_image_path('test_svg_with_broken_b64_encoding.svg')
        dst = os.path.join(tempfile.gettempdir(), 'resized_svg_image.svg')
        try:
            resize_svg_image(src, dst, 0, 0, crop=False, optimize=False)

            # svg file with broken bitmap data (base64 decoding error) should
            # contain the same embedded bitmap data as the original
            self.assertTrue(is_same_file(src, dst))
        finally:
            if os.path.isfile(dst):
                os.unlink(dst)
예제 #6
0
    def _assert_downsampling(self, filename):
        src = self.get_test_image_path(filename)
        dst = os.path.join(tempfile.gettempdir(), 'resized_svg_image.svg')
        try:
            resize_svg_image(src, dst, 50, 50)

            # svg file with bitmap data embedded should NOT be the same
            # image after resize...
            self.assertFalse(is_same_file(src, dst))

            # image size should be less
            self.assertTrue(os.path.getsize(dst) < os.path.getsize(src))

            # the resulting image should still be an svg image with path
            # information in it
            content = file_get_contents(dst)
            self.assertIn('<svg', content)
            self.assertIn('<path', content)
        finally:
            if os.path.isfile(dst):
                os.unlink(dst)