<commit_before># coding: utf-8

from __future__ import print_function, unicode_literals, absolute_import

import math

from PIL import Image

from .base import BaseTestCase


Image.LANCZOS = Image.ANTIALIAS

class PillowTestCase(BaseTestCase):
    filter_ids = {
        0: 'ner', 1: 'lzs', 2: 'bil', 3: 'bic',
        4: 'box', 5: 'hmn', 6: 'mtc',
    }

    def create_test_data(self, size, mode):
        return [Image.new(mode, size)]

    @classmethod
    def resize(cls, self, size, resample=Image.NEAREST):
        self.load()

        if self.size == size:
            return self._new(self.im)

        if self.mode in ("1", "P"):
            resample = Image.NEAREST

        if self.mode == 'RGBA':
            return cls.resize(self.convert('RGBa'), size, resample).convert('RGBA')

        if self.mode == 'LA':
            return cls.resize(self.convert('La'), size, resample).convert('LA')

        if resample == Image.NEAREST:
            im = self.im.resize(size, resample)
        else:
            im = self.im.stretch(size, resample)

        return self._new(im)

    @classmethod
    def gaussian_blur(cls, self, radius, n=3):
        if self.mode == 'RGBA':
            return cls.gaussian_blur(self.convert('RGBa'), radius, n).convert('RGBA')

        if self.mode == 'LA':
            return cls.gaussian_blur(self.convert('La'), radius, n).convert('LA')

        # http://www.mia.uni-saarland.de/Publications/gwosdek-ssvm11.pdf
        # [7] Box length.
        L = math.sqrt(12.0 * float(radius) * radius / n + 1.0)
        # [11] Box radius.
        l = (L - 1.0) / 2.0
        # Integer part.
        li = math.floor(l)
        # Reduce the fractional part in accordance with tests.
        a = math.e ** (2.5 * (l - li) / (li + 1)) - 1
        a /= math.e ** (2.5 / (li + 1)) - 1
        box_radius = li + a

        self.load()
        return self._new(self.im.box_blur(box_radius, n))
<commit_msg>use test image in pillow cases<commit_after># coding: utf-8

from __future__ import print_function, unicode_literals, absolute_import

import math

from PIL import Image

from .base import BaseTestCase, root


Image.LANCZOS = Image.ANTIALIAS

class PillowTestCase(BaseTestCase):
    filter_ids = {
        0: 'ner', 1: 'lzs', 2: 'bil', 3: 'bic',
        4: 'box', 5: 'hmn', 6: 'mtc',
    }

    def create_test_data(self, size, mode):
        im = Image.open(root('resources', 'color_circle.png'))
        im = self.resize(im, size, Image.BICUBIC)
        im = im.convert(mode)
        return [ im ]

    @classmethod
    def resize(cls, self, size, resample=Image.NEAREST):
        self.load()

        if self.size == size:
            return self._new(self.im)

        if self.mode in ("1", "P"):
            resample = Image.NEAREST

        if self.mode == 'RGBA':
            return cls.resize(self.convert('RGBa'), size, resample).convert('RGBA')

        if self.mode == 'LA':
            return cls.resize(self.convert('La'), size, resample).convert('LA')

        if resample == Image.NEAREST:
            im = self.im.resize(size, resample)
        else:
            im = self.im.stretch(size, resample)

        return self._new(im)

    @classmethod
    def gaussian_blur(cls, self, radius, n=3):
        if self.mode == 'RGBA':
            return cls.gaussian_blur(self.convert('RGBa'), radius, n).convert('RGBA')

        if self.mode == 'LA':
            return cls.gaussian_blur(self.convert('La'), radius, n).convert('LA')

        # http://www.mia.uni-saarland.de/Publications/gwosdek-ssvm11.pdf
        # [7] Box length.
        L = math.sqrt(12.0 * float(radius) * radius / n + 1.0)
        # [11] Box radius.
        l = (L - 1.0) / 2.0
        # Integer part.
        li = math.floor(l)
        # Reduce the fractional part in accordance with tests.
        a = math.e ** (2.5 * (l - li) / (li + 1)) - 1
        a /= math.e ** (2.5 / (li + 1)) - 1
        box_radius = li + a

        self.load()
        return self._new(self.im.box_blur(box_radius, n))

{'fraction_non_alphanumeric': 0.14916438014467448, 'fraction_numerical': 0.015964080818159143, 'mean_word_length': 2.098918083462133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '485344', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1359, 'n_words': 334}