<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os, mapnik
from timeit import Timer, time
from nose.tools import *
from utilities import execution_path, run_all

def setup():
    # All of the paths used are relative, if we run the tests
    # from another directory we need to chdir()
    os.chdir(execution_path('.'))

def test_image_premultiply():
    im = mapnik.Image(256,256)
    eq_(im.premultiplied(),False)
    # Premultiply should return true that it worked
    eq_(im.premultiply(), True)
    eq_(im.premultiplied(),True)
    # Premultipling again should return false as nothing should happen
    eq_(im.premultiply(), False)
    eq_(im.premultiplied(),True)
    # Demultiply should return true that it worked
    eq_(im.demultiply(), True)
    eq_(im.premultiplied(),False)
    # Demultiply again should not work and return false as it did nothing
    eq_(im.demultiply(), False)
    eq_(im.premultiplied(),False)

@raises(RuntimeError)
def test_negative_image_dimensions():<commit_msg>Added a new test for set_color_to_alpha<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os, mapnik
from timeit import Timer, time
from nose.tools import *
from utilities import execution_path, run_all, get_unique_colors

def setup():
    # All of the paths used are relative, if we run the tests
    # from another directory we need to chdir()
    os.chdir(execution_path('.'))

def test_image_premultiply():
    im = mapnik.Image(256,256)
    eq_(im.premultiplied(),False)
    # Premultiply should return true that it worked
    eq_(im.premultiply(), True)
    eq_(im.premultiplied(),True)
    # Premultipling again should return false as nothing should happen
    eq_(im.premultiply(), False)
    eq_(im.premultiplied(),True)
    # Demultiply should return true that it worked
    eq_(im.demultiply(), True)
    eq_(im.premultiplied(),False)
    # Demultiply again should not work and return false as it did nothing
    eq_(im.demultiply(), False)
    eq_(im.premultiplied(),False)

def test_set_color_to_alpha():
    im = mapnik.Image(256,256)
    im.background = mapnik.Color('rgba(12,12,12,255)')
    eq_(get_unique_colors(im), ['rgba(12,12,12,255)'])
    im.set_color_to_alpha(mapnik.Color('rgba(12,12,12,0)'))
    eq_(get_unique_colors(im), ['rgba(0,0,0,0)'])

@raises(RuntimeError)
def test_negative_image_dimensions():
{'fraction_non_alphanumeric': 0.1181894383906119, 'fraction_numerical': 0.020536462699077954, 'mean_word_length': 4.304444444444444, 'pattern_counts': {'":': 0, '<': 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': '2741951', 'n_tokens_mistral': 851, 'n_tokens_neox': 785, 'n_words': 214}