<commit_before>from __future__ import print_function

import hashlib
import sys
import unittest
import pgmagick
from pgmagick.api import Image, Draw


print(pgmagick.gminfo().version)
LIBGM_VERSION = [int(v) for v in pgmagick.gminfo().version.split('.')]


class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Catrom')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_catrom_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6, 'Cubic')
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_with_filtertype_cubic_digest = m.hexdigest()
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')
        m = hashlib.md5()
        with open('t.jpg', 'rb') as fp:
            m.update(fp.read())
            scale_digest = m.hexdigest()
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_digest)
        self.assertNotEqual(scale_with_filtertype_catrom_digest, scale_with_filtertype_cubic_digest)

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):<commit_msg>fix test<commit_after>from __future__ import print_function

import hashlib
import sys
import unittest
import pgmagick
from pgmagick.api import Image, Draw


print(pgmagick.gminfo().version)
LIBGM_VERSION = [int(v) for v in pgmagick.gminfo().version.split('.')]


class ImageTestCase(unittest.TestCase):

    def setUp(self):
        self.img = Image((600, 400), 'red')

    def test_unicodefilename(self):
        self.img.write('unicode.png')
        img = Image(u'unicode.png')
        img.scale(0.5)
        img.write(u'unicode.jpg')

    def test_nonarg(self):
        Image()

    def test_arg(self):
        Image((600, 400), 'red')

    def test_arg_float(self):
        Image((600.5, 400.4), 'red')

    def test_blur(self):
        self.img.blur(2, 2.3)
        self.img.write('t.jpg')

    def test_blur_channel(self):
        self.img.blur_channel('cyan')
        self.img.write('t.jpg')

    def test_scale(self):
        img = Image((600, 400), 'gradient:#ffffff-#000000')
        img.scale(0.6)
        img.write('t.jpg')

    def test_scale_with_filtertype(self):
        testset = {"Catrom": None, "Cubic": None, "None": None}
        for k, v in testset.items():
            img = Image((600, 400), 'gradient:#ffffff-#000000')
            if sys.platform.lower() == 'darwin':
                img.font("/Library/Fonts/Arial.ttf")
            img.annotate("hello", (100, 100))
            if k != "None":
                img.scale(0.6, k)
            else:
                img.scale(0.6)
            img.write('t.jpg')
            img.write('t_{}.jpg'.format(k))
            m = hashlib.md5()
            with open('t.jpg', 'rb') as fp:
                m.update(fp.read())
                testset[k] = m.hexdigest()

        self.assertNotEqual(testset["Catrom"], testset["None"])
        self.assertNotEqual(testset["Cubic"], testset["None"])
        self.assertNotEqual(testset["Catrom"], testset["Cubic"])

    def test_composite_arg_list(self):
        base = Image((300, 200), 'green')
        layer = Image((300, 200), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 50, 100)
        layer.draw(drawer)
        base.composite(layer, (10, 10), 'over')
        base.write('t.png')

    def test_composite_arg_gravity(self):
        base = Image((300, 200), 'green')
        layer = Image((150, 100), 'transparent')
        drawer = Draw()
        drawer.circle(50, 50, 20, 20)
        layer.draw(drawer)
        base.composite(layer, 'center', 'over')
        base.write('t.png')

    def test_crop(self):
{'fraction_non_alphanumeric': 0.1567804691970246, 'fraction_numerical': 0.04501239748235743, 'mean_word_length': 2.385409941897999, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1847799', 'n_tokens_mistral': 1996, 'n_tokens_neox': 1757, 'n_words': 334}