Lenard Lindstrom avatar Lenard Lindstrom committed af8675f

test suite now pygame.tests subpackage as well

Comments (0)

Files changed (49)

async_sub.py

-################################################################################
-"""
-
-Modification of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554
-
-"""
-
-#################################### IMPORTS ###################################
-
-import os
-import subprocess
-import errno
-import time
-import sys
-import unittest
-import tempfile
-
-if subprocess.mswindows:
-    from win32file import ReadFile, WriteFile
-    from win32pipe import PeekNamedPipe
-    import win32api
-    import msvcrt
-    
-else:
-    from signal import SIGINT, SIGTERM, SIGKILL
-    import select
-    import fcntl
-
-################################### CONSTANTS ##################################
-
-PIPE = subprocess.PIPE
-
-################################################################################
-
-class Popen(subprocess.Popen):
-    def recv(self, maxsize=None):
-        return self._recv('stdout', maxsize)
-    
-    def recv_err(self, maxsize=None):
-        return self._recv('stderr', maxsize)
-
-    def send_recv(self, input='', maxsize=None):
-        return self.send(input), self.recv(maxsize), self.recv_err(maxsize)
-    
-    def read_async(self,  wait=.1, e=1, tr=5, stderr=0):
-        if tr < 1:
-            tr = 1
-        x = time.time()+ wait
-        y = []
-        r = ''
-        pr = self.recv
-        if stderr:
-            pr = self.recv_err
-        while time.time() < x or r:
-            r = pr()
-            if r is None:
-                if e:
-                    raise Exception("Other end disconnected!")
-                else:
-                    break
-            elif r:
-                y.append(r)
-            else:
-                time.sleep(max((x-time.time())/tr, 0))
-        return ''.join(y)
-        
-    def send_all(self, data):
-        while len(data):
-            sent = self.send(data)
-            if sent is None:
-                raise Exception("Other end disconnected!")
-            data = buffer(data, sent)
-    
-    def get_conn_maxsize(self, which, maxsize):
-        if maxsize is None:
-            maxsize = 1024
-        elif maxsize < 1:
-            maxsize = 1
-        return getattr(self, which), maxsize
-    
-    def _close(self, which):
-        getattr(self, which).close()
-        setattr(self, which, None)
-    
-    if subprocess.mswindows:
-        def kill(self):
-            # Recipes
-            #http://me.in-berlin.de/doc/python/faq/windows.html#how-do-i-emulate-os-kill-in-windows
-            #http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/347462
-            
-            """kill function for Win32"""
-            
-            win32api.TerminateProcess(int(self._handle), 0) # returns None
-                                           # handle,  # exit code
-
-        def send(self, input):
-            if not self.stdin:
-                return None
-
-            try:
-                x = msvcrt.get_osfhandle(self.stdin.fileno())
-                (errCode, written) = WriteFile(x, input)
-            except ValueError:
-                return self._close('stdin')
-            except (subprocess.pywintypes.error, Exception), why:
-                if why[0] in (109, errno.ESHUTDOWN):
-                    return self._close('stdin')
-                raise
-
-            return written
-
-        def _recv(self, which, maxsize):
-            conn, maxsize = self.get_conn_maxsize(which, maxsize)
-            if conn is None:
-                return None
-            
-            try:
-                x = msvcrt.get_osfhandle(conn.fileno())
-                (read, nAvail, nMessage) = PeekNamedPipe(x, 0)
-                if maxsize < nAvail:
-                    nAvail = maxsize
-                if nAvail > 0:
-                    (errCode, read) = ReadFile(x, nAvail, None)
-            except ValueError:
-                return self._close(which)
-            except (subprocess.pywintypes.error, Exception), why:
-                if why[0] in (109, errno.ESHUTDOWN):
-                    return self._close(which)
-                raise
-            
-            if self.universal_newlines:
-                read = self._translate_newlines(read)
-            return read
-
-    else:
-        def kill(self):
-            for i, sig in enumerate([SIGTERM, SIGKILL] * 2):
-                if i % 2 == 0: os.kill(self.pid, sig)
-                time.sleep((i * (i % 2) / 5.0)  + 0.01)
-
-                killed_pid, stat = os.waitpid(self.pid, os.WNOHANG)
-                if killed_pid != 0: return
-                
-        def send(self, input):
-            if not self.stdin:
-                return None
-
-            if not select.select([], [self.stdin], [], 0)[1]:
-                return 0
-
-            try:
-                written = os.write(self.stdin.fileno(), input)
-            except OSError, why:
-                if why[0] == errno.EPIPE: #broken pipe
-                    return self._close('stdin')
-                raise
-
-            return written
-
-        def _recv(self, which, maxsize):
-            conn, maxsize = self.get_conn_maxsize(which, maxsize)
-            if conn is None:
-                return None
-            
-            flags = fcntl.fcntl(conn, fcntl.F_GETFL)
-            if not conn.closed:
-                fcntl.fcntl(conn, fcntl.F_SETFL, flags| os.O_NONBLOCK)
-            
-            try:
-                if not select.select([conn], [], [], 0)[0]:
-                    return ''
-                
-                r = conn.read(maxsize)
-                if not r:
-                    return self._close(which)
-    
-                if self.universal_newlines:
-                    r = self._translate_newlines(r)
-                return r
-            finally:
-                if not conn.closed:
-                    fcntl.fcntl(conn, fcntl.F_SETFL, flags)
-
-################################################################################
-
-def proc_in_time_or_kill(cmd, time_out, wd = None, env = None):
-    proc = Popen (
-        cmd, cwd = wd, env = env,
-        stdin = subprocess.PIPE, stdout = subprocess.PIPE, 
-        stderr = subprocess.STDOUT, universal_newlines = 1
-    )
-
-    ret_code = None
-    response = []
-
-    t = time.time()
-    while ret_code is None and ((time.time() -t) < time_out):
-        ret_code = proc.poll()
-        response += [proc.read_async(wait=0.1, e=0)]
-
-    if ret_code is None:
-        ret_code = '"Process timed out (time_out = %s secs) ' % time_out
-        try:
-            proc.kill()
-            ret_code += 'and was successfully terminated"'
-        except Exception, e:
-            ret_code += 'and termination failed (exception: %s)"' % e
-
-    return ret_code, ''.join(response)
-
-################################################################################
-
-class AsyncTest(unittest.TestCase):
-    def test_proc_in_time_or_kill(self):
-        ret_code, response = proc_in_time_or_kill(
-            [sys.executable, '-c', 'while 1: pass'], time_out = 1
-        )
-        
-        self.assert_( 'rocess timed out' in ret_code )
-        self.assert_( 'successfully terminated' in ret_code )
-
-################################################################################
-
-def _example():
-    if sys.platform == 'win32':
-        shell, commands, tail = ('cmd', ('echo "hello"', 'echo "HELLO WORLD"'), '\r\n')
-    else:
-        shell, commands, tail = ('sh', ('ls', 'echo HELLO WORLD'), '\n')
-    
-    a = Popen(shell, stdin=PIPE, stdout=PIPE)
-    print a.read_async(),
-    for cmd in commands:
-        a.send_all(cmd + tail)
-        print a.read_async(),
-    a.send_all('exit' + tail)
-    print a.read_async(e=0)
-    a.wait()
-
-################################################################################
-    
-if __name__ == '__main__':
-    if 1: unittest.main()
-    else: _example()
 skip = set(['pygame.locals', 'pygame.constants',
             'pygame.base', 'pygame.threads'])
 
-sys.path.append('.')
 os.chdir('test')
 test_file = sys.argv[1]
 del sys.argv[1]
 	return __rect_constructor, (r.x, r.y, r.w, r.h)
 copy_reg.pickle(Rect, __rect_reduce, __rect_constructor)
 
+def test():
+    from pygame import tests
+    tests.run()
+
 #cleanup namespace
 del pygame, os, sys, rwobject, surflock, MissingModule, copy_reg
-#################################### IMPORTS ###################################
-import test.unittest as unittest
+"""Run one or more Pygame unittest modules in the test directory
 
-import sys
-import os
-import re
-import subprocess
-import time
-import optparse
-import pygame.threads, pygame
-import random
+For command line options use the --help option.
 
-from test_runner import prepare_test_env, run_test, combine_results, \
-                        test_failures, get_test_results, from_namespace, \
-                        TEST_RESULTS_START
+"""
 
-from pprint import pformat
+import test
 
-main_dir, test_subdir, fake_test_subdir = prepare_test_env()
-test_runner_py = os.path.join(main_dir, "test_runner.py")
-
-import test_utils
-import unittest_patch
-
-################################### CONSTANTS ##################################
-# Defaults:
-#    See optparse options below for more options (test_runner.py)
-#
-
-# Any tests in IGNORE will not be ran
-IGNORE = set ([
-    "scrap_test",
-])
-
-# Subprocess has less of a need to worry about interference between tests
-SUBPROCESS_IGNORE = set ([
-    "scrap_test",
-])
-
-################################################################################
-# Set the command line options
-#
-# Defined in test_runner.py as it shares options, added to here
-
-from test_runner import opt_parser
-
-opt_parser.set_usage("""
-
-Runs all or some of the test/xxxx_test.py tests.
-
-$ run_tests.py sprite threads -sd
-
-Runs the sprite and threads module tests isolated in subprocesses, dumping all
-failing tests info in the form of a dict.
-
-""")
-
-options, args = opt_parser.parse_args()
-
-################################################################################
-# Change to working directory and compile a list of test modules
-# If options.fake, then compile list of fake xxxx_test.py from run_tests__tests
-
-TEST_MODULE_RE = re.compile('^(.+_test)\.py$')
-
-if options.fake:
-    test_subdir = os.path.join(fake_test_subdir, options.fake )
-    sys.path.append(test_subdir)
-    working_dir = test_subdir
-else:
-    working_dir = main_dir
-
-
-# Added in because some machines will need os.environ else there will be false
-# failures in subprocess mode. Same issue as python2.6. Needs some env vars.
-
-test_env = os.environ.copy()
-test_env["PYTHONPATH"] = os.pathsep.join (
-    [pth for pth in ([test_subdir] + [test_env.get("PYTHONPATH")]) if pth]
-)
-
-os.chdir(working_dir)
-
-if args:
-    test_modules = [
-        m.endswith('_test') and m or ('%s_test' % m) for m in args
-    ]
-else:
-    if options.subprocess: ignore = SUBPROCESS_IGNORE
-    else: ignore = IGNORE
-
-    test_modules = []
-    for f in sorted(os.listdir(test_subdir)):
-        for match in TEST_MODULE_RE.findall(f):
-            if match not in ignore:
-                test_modules.append(match)
-
-################################################################################
-# Meta results
-
-results = {}
-meta_results = {'__meta__' : {}}
-meta = meta_results['__meta__']
-
-################################################################################
-# Randomization
-
-if options.randomize or options.seed:
-    seed = options.seed or time.time()
-    meta['random_seed'] = seed
-    print "\nRANDOM SEED USED: %s\n" % seed
-    random.seed(seed)
-    random.shuffle(test_modules)
-        
-################################################################################
-# Single process mode
-
-if not options.subprocess:
-    unittest_patch.patch(options)
-
-    t = time.time()
-    for module in test_modules:
-        results.update(run_test(module, options = options))
-    t = time.time() - t
-
-################################################################################
-# Subprocess mode
-#
-
-if options.subprocess:
-    from async_sub import proc_in_time_or_kill
-
-    def sub_test(module):
-        print 'loading', module
-
-        pass_on_args = [a for a in sys.argv[1:] if a not in args]
-        cmd = [options.python, test_runner_py, module ] + pass_on_args
-
-        return module, (cmd, test_env, working_dir), proc_in_time_or_kill (
-            cmd, options.time_out,  env = test_env,  wd = working_dir,
-        )
-
-    if options.multi_thread:
-        def tmap(f, args):
-            return pygame.threads.tmap (
-                f, args, stop_on_error = False,
-                num_workers = options.multi_thread
-            )
-    else: tmap = map
-
-    t = time.time()
-
-    for module, cmd, (return_code, raw_return) in tmap(sub_test, test_modules):
-        test_file = '%s.py' % os.path.join(test_subdir, module)
-        cmd, test_env, working_dir = cmd
-
-        test_results = get_test_results(raw_return)
-        if test_results: results.update(test_results)
-        else: results[module] = {}
-
-        add_to_results = [
-            'return_code', 'raw_return',  'cmd', 'test_file',
-            'test_env', 'working_dir', 'module',
-        ]
-
-        results[module].update(from_namespace(locals(), add_to_results))
-    
-    t = time.time() -t
-
-################################################################################
-# Output Results
-#
-
-untrusty_total, combined = combine_results(results, t)
-total, fails = test_failures(results)
-
-meta['total_tests'] = total
-meta['combined'] = combined
-results.update(meta_results)
-
-if not options.subprocess:
-    assert total == untrusty_total
-
-if not options.dump:
-    print combined
-else:
-    results = options.all and results or fails
-    print TEST_RESULTS_START
-    print pformat(results)
-
-if options.file:
-    results_file = open(options.file, 'w')
-    try:        results_file.write(pformat(results))
-    finally:    results_file.close()
-
-################################################################################
+test.run()
 
 #extra files to install
 data_path = os.path.join(distutils.sysconfig.get_python_lib(), 'pygame')
-data_files = []
+pygame_data_files = []
+data_files = [('pygame', pygame_data_files)]
 
 
 #add non .py files in lib directory
 for f in glob.glob(os.path.join('lib', '*')):
     if not f[-3:] == '.py' and not f[-4:] == '.doc' and os.path.isfile(f):
-        data_files.append(f)
+        pygame_data_files.append(f)
+
+#examples
+data_files.append(('pygame/examples/data',
+                   glob.glob(os.path.join('examples', 'data', '*'))))
 
 # Required. This will be filled if doing a Windows build.
 cmdclass = {}
         if f == '_':
             print "WARNING, DLL for %s library not found." % lib
         else:
-            data_files.append(f)
+            pygame_data_files.append(f)
 
     class WinBuildExt(build_ext):
         """This build_ext sets necessary environment variables for MinGW"""
 
 cmdclass['test'] = TestCommand
 
+# Prune empty file lists.
+date_files = [(path, files) for path, files in data_files if files]
 
 
 
 #call distutils with all needed info
 PACKAGEDATA = {
        "cmdclass":    cmdclass,
-       "packages":    ['pygame', 'pygame.gp2x', 'pygame.threads'],
+       "packages":    ['pygame', 'pygame.gp2x', 'pygame.threads',
+                       'pygame.tests'],
        "package_dir": {'pygame': 'lib',
                        'pygame.threads': 'lib/threads',
-                       'pygame.gp2x': 'lib/gp2x'},
+                       'pygame.gp2x': 'lib/gp2x',
+                       'pygame.tests': 'test'},
+       "package_data": {'pygame.tests': ['test_utils/*.py',
+                                         'fixtures/xbm_cursors/*.xbm']},
        "headers":     headers,
        "ext_modules": extensions,
-       "data_files":  [['pygame', data_files]],
+       "data_files":  data_files,
 }
 PACKAGEDATA.update(METADATA)
 PACKAGEDATA.update(EXTRAS)
+def run():
+    if __name__ == 'pygame.tests':
+        from pygame.tests.test_utils.run_tests import run
+    else:
+        from test.test_utils.run_tests import run
+    run()

test/base_test.py

-import test_utils
-import test.unittest as unittest
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import test_not_implemented, unittest
+else:
+    from test.test_utils import test_not_implemented, unittest
 import pygame
-from test_utils import test_not_implemented
 
 init_called = quit_called = 0
 def __PYGAMEinit__(): #called automatically by pygame.init()
         self.fail() 
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()

test/blit_test.py

-import test_utils
-import test.unittest as unittest
-import test_utils
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import unittest
+else:
+    from test.test_utils import unittest
 import pygame
 from pygame.locals import *
 

test/bufferproxy_test.py

 #################################### IMPORTS ###################################
 
-import test_utils
-import test.unittest as unittest
-from test_utils import test_not_implemented
+if __name__ == '__main__':
+    import sys
+    import os
+    parent_dir = os.path.split(os.path.split(os.path.abspath(__file__))[0])[0]
+    sys.path.insert(0, parent_dir)
 
+try:
+    from test.test_utils import test_not_implemented, unittest
+except:
+    from pygame.tests.test_utils import test_not_implemented, unittest
 import pygame
 
 ################################################################################
 ################################################################################
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()

test/cdrom_test.py

 
 __tags__ = ['interactive']
 
-import test_utils
-import test.unittest as unittest
-from test_utils import test_not_implemented, question, prompt
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils \
+         import test_not_implemented, question, prompt, unittest
+else:
+    from test.test_utils \
+         import test_not_implemented, question, prompt, unittest
 
 import pygame
 
 ################################################################################
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()

test/color_test.py

-#################################### IMPORTS ###################################
-
-from __future__ import generators
-
-import test_utils
-import test.unittest as unittest
-
-import pygame
-import math
-
-from test_utils import test_not_implemented
-
-################################### CONSTANTS ##################################
-
-rgba_vals = [0, 1, 62, 63, 126, 127, 255]
-
-rgba_combinations =  [ (r,g,b,a) for r in rgba_vals
-                                 for g in rgba_vals
-                                 for b in rgba_vals
-                                 for a in rgba_vals ]
-
-################################################################################
-
-def rgba_combos_Color_generator ():
-    for rgba in rgba_combinations:
-        yield pygame.Color(*rgba)
-
-# Python gamma correct
-def gamma_correct (rgba_0_255, gamma):
-    corrected = round(255.0 * math.pow(rgba_0_255/255.0, gamma))
-    return max(min( int(corrected), 255), 0)
-
-################################################################################
-
-# TODO: add tests for
-# correct_gamma()  -- test against statically defined verified correct values
-# coerce ()        --  ??
-
-def _assignr (x, y):
-    x.r = y
-
-def _assigng (x, y):
-    x.g = y
-
-def _assignb (x, y):
-    x.b = y
-
-def _assigna (x, y):
-    x.a = y
-
-def _assign_item (x, p, y):
-    x[p] = y
-
-class ColorTypeTest (unittest.TestCase):
-    def test_invalid_html_hex_codes(self):
-        # This was a problem with the way 2 digit hex numbers were
-        # calculated. The test_hex_digits test is related to the fix.
-        Color = pygame.color.Color
-        self.failUnlessRaises(ValueError, lambda: Color('# f000000'))
-        self.failUnlessRaises(ValueError, lambda: Color('#f 000000'))
-        self.failUnlessRaises(ValueError, lambda: Color('#-f000000'))
-
-    def test_hex_digits(self):
-        # This is an implementation specific test.
-        # Two digit hex numbers are calculated using table lookups
-        # for the upper and lower digits.
-        Color = pygame.color.Color
-        self.assertEqual(Color('#00000000').r, 0x00)
-        self.assertEqual(Color('#10000000').r, 0x10)
-        self.assertEqual(Color('#20000000').r, 0x20)
-        self.assertEqual(Color('#30000000').r, 0x30)
-        self.assertEqual(Color('#40000000').r, 0x40)
-        self.assertEqual(Color('#50000000').r, 0x50)
-        self.assertEqual(Color('#60000000').r, 0x60)
-        self.assertEqual(Color('#70000000').r, 0x70)
-        self.assertEqual(Color('#80000000').r, 0x80)
-        self.assertEqual(Color('#90000000').r, 0x90)
-        self.assertEqual(Color('#A0000000').r, 0xA0)
-        self.assertEqual(Color('#B0000000').r, 0xB0)
-        self.assertEqual(Color('#C0000000').r, 0xC0)
-        self.assertEqual(Color('#D0000000').r, 0xD0)
-        self.assertEqual(Color('#E0000000').r, 0xE0)
-        self.assertEqual(Color('#F0000000').r, 0xF0)
-        self.assertEqual(Color('#01000000').r, 0x01)
-        self.assertEqual(Color('#02000000').r, 0x02)
-        self.assertEqual(Color('#03000000').r, 0x03)
-        self.assertEqual(Color('#04000000').r, 0x04)
-        self.assertEqual(Color('#05000000').r, 0x05)
-        self.assertEqual(Color('#06000000').r, 0x06)
-        self.assertEqual(Color('#07000000').r, 0x07)
-        self.assertEqual(Color('#08000000').r, 0x08)
-        self.assertEqual(Color('#09000000').r, 0x09)
-        self.assertEqual(Color('#0A000000').r, 0x0A)
-        self.assertEqual(Color('#0B000000').r, 0x0B)
-        self.assertEqual(Color('#0C000000').r, 0x0C)
-        self.assertEqual(Color('#0D000000').r, 0x0D)
-        self.assertEqual(Color('#0E000000').r, 0x0E)
-        self.assertEqual(Color('#0F000000').r, 0x0F)
-
-    def test_comparison(self):
-        Color = pygame.color.Color
-        self.failUnless(Color(255, 0, 0, 0) == Color(255, 0, 0, 0))
-        self.failUnless(Color(0, 255, 0, 0) == Color(0, 255, 0, 0))
-        self.failUnless(Color(0, 0, 255, 0) == Color(0, 0, 255, 0))
-        self.failUnless(Color(0, 0, 0, 255) == Color(0, 0, 0, 255))
-        self.failIf(Color(0, 0, 0, 0) == Color(255, 0, 0, 0))
-        self.failIf(Color(0, 0, 0, 0) == Color(0, 255, 0, 0))
-        self.failIf(Color(0, 0, 0, 0) == Color(0, 0, 255, 0))
-        self.failIf(Color(0, 0, 0, 0) == Color(0, 0, 0, 255))
-        self.failUnless(Color(0, 0, 0, 0) != Color(255, 0, 0, 0))
-        self.failUnless(Color(0, 0, 0, 0) != Color(0, 255, 0, 0))
-        self.failUnless(Color(0, 0, 0, 0) != Color(0, 0, 255, 0))
-        self.failUnless(Color(0, 0, 0, 0) != Color(0, 0, 0, 255))
-        self.failIf(Color(255, 0, 0, 0) != Color(255, 0, 0, 0))
-        self.failIf(Color(0, 255, 0, 0) != Color(0, 255, 0, 0))
-        self.failIf(Color(0, 0, 255, 0) != Color(0, 0, 255, 0))
-        self.failIf(Color(0, 0, 0, 255) != Color(0, 0, 0, 255))
-
-        self.failUnless(Color(255, 0, 0, 0) == (255, 0, 0, 0))
-        self.failUnless(Color(0, 255, 0, 0) == (0, 255, 0, 0))
-        self.failUnless(Color(0, 0, 255, 0) == (0, 0, 255, 0))
-        self.failUnless(Color(0, 0, 0, 255) == (0, 0, 0, 255))
-        self.failIf(Color(0, 0, 0, 0) == (255, 0, 0, 0))
-        self.failIf(Color(0, 0, 0, 0) == (0, 255, 0, 0))
-        self.failIf(Color(0, 0, 0, 0) == (0, 0, 255, 0))
-        self.failIf(Color(0, 0, 0, 0) == (0, 0, 0, 255))
-        self.failUnless(Color(0, 0, 0, 0) != (255, 0, 0, 0))
-        self.failUnless(Color(0, 0, 0, 0) != (0, 255, 0, 0))
-        self.failUnless(Color(0, 0, 0, 0) != (0, 0, 255, 0))
-        self.failUnless(Color(0, 0, 0, 0) != (0, 0, 0, 255))
-        self.failIf(Color(255, 0, 0, 0) != (255, 0, 0, 0))
-        self.failIf(Color(0, 255, 0, 0) != (0, 255, 0, 0))
-        self.failIf(Color(0, 0, 255, 0) != (0, 0, 255, 0))
-        self.failIf(Color(0, 0, 0, 255) != (0, 0, 0, 255))
-
-        self.failUnless((255, 0, 0, 0) == Color(255, 0, 0, 0))
-        self.failUnless((0, 255, 0, 0) == Color(0, 255, 0, 0))
-        self.failUnless((0, 0, 255, 0) == Color(0, 0, 255, 0))
-        self.failUnless((0, 0, 0, 255) == Color(0, 0, 0, 255))
-        self.failIf((0, 0, 0, 0) == Color(255, 0, 0, 0))
-        self.failIf((0, 0, 0, 0) == Color(0, 255, 0, 0))
-        self.failIf((0, 0, 0, 0) == Color(0, 0, 255, 0))
-        self.failIf((0, 0, 0, 0) == Color(0, 0, 0, 255))
-        self.failUnless((0, 0, 0, 0) != Color(255, 0, 0, 0))
-        self.failUnless((0, 0, 0, 0) != Color(0, 255, 0, 0))
-        self.failUnless((0, 0, 0, 0) != Color(0, 0, 255, 0))
-        self.failUnless((0, 0, 0, 0) != Color(0, 0, 0, 255))
-        self.failIf((255, 0, 0, 0) != Color(255, 0, 0, 0))
-        self.failIf((0, 255, 0, 0) != Color(0, 255, 0, 0))
-        self.failIf((0, 0, 255, 0) != Color(0, 0, 255, 0))
-        self.failIf((0, 0, 0, 255) != Color(0, 0, 0, 255))
-
-        self.failUnless(Color(255, 0, 0, 0) == "#ff000000")
-        self.failUnless(Color(0, 255, 0, 0) == "#00ff0000")
-        self.failUnless(Color(0, 0, 255, 0) == "#0000ff00")
-        self.failUnless(Color(0, 0, 0, 255) == "#000000ff")
-        self.failIf(Color(0, 0, 0, 0) == "#ff000000")
-        self.failIf(Color(0, 0, 0, 0) == "#00ff0000")
-        self.failIf(Color(0, 0, 0, 0) == "#0000ff00")
-        self.failIf(Color(0, 0, 0, 0) == "#000000ff")
-        self.failUnless(Color(0, 0, 0, 0) != "#ff000000")
-        self.failUnless(Color(0, 0, 0, 0) != "#00ff0000")
-        self.failUnless(Color(0, 0, 0, 0) != "#0000ff00")
-        self.failUnless(Color(0, 0, 0, 0) != "#000000ff")
-        self.failIf(Color(255, 0, 0, 0) != "#ff000000")
-        self.failIf(Color(0, 255, 0, 0) != "#00ff0000")
-        self.failIf(Color(0, 0, 255, 0) != "#0000ff00")
-        self.failIf(Color(0, 0, 0, 255) != "#000000ff")
-
-        self.failUnless("#ff000000" == Color(255, 0, 0, 0))
-        self.failUnless("#00ff0000" == Color(0, 255, 0, 0))
-        self.failUnless("#0000ff00" == Color(0, 0, 255, 0))
-        self.failUnless("#000000ff" == Color(0, 0, 0, 255))
-        self.failIf("#ff000000" == Color(0, 0, 0, 0))
-        self.failIf("#00ff0000" == Color(0, 0, 0, 0))
-        self.failIf("#0000ff00" == Color(0, 0, 0, 0))
-        self.failIf("#000000ff" == Color(0, 0, 0, 0))
-        self.failUnless("#ff000000" != Color(0, 0, 0, 0))
-        self.failUnless("#00ff0000" != Color(0, 0, 0, 0))
-        self.failUnless("#0000ff00" != Color(0, 0, 0, 0))
-        self.failUnless("#000000ff" != Color(0, 0, 0, 0))
-        self.failIf("#ff000000" != Color(255, 0, 0, 0))
-        self.failIf("#00ff0000" != Color(0, 255, 0, 0))
-        self.failIf("#0000ff00" != Color(0, 0, 255, 0))
-        self.failIf("#000000ff" != Color(0, 0, 0, 255))
-
-        self.failUnless(Color(255, 0, 0, 0) == 0xff000000)
-        self.failUnless(Color(0, 255, 0, 0) == 0x00ff0000)
-        self.failUnless(Color(0, 0, 255, 0) == 0x0000ff00)
-        self.failUnless(Color(0, 0, 0, 255) == 0x000000ff)
-        self.failIf(Color(0, 0, 0, 0) == 0xff000000)
-        self.failIf(Color(0, 0, 0, 0) == 0x00ff0000)
-        self.failIf(Color(0, 0, 0, 0) == 0x0000ff00)
-        self.failIf(Color(0, 0, 0, 0) == 0x000000ff)
-        self.failUnless(Color(0, 0, 0, 0) != 0xff000000)
-        self.failUnless(Color(0, 0, 0, 0) != 0x00ff0000)
-        self.failUnless(Color(0, 0, 0, 0) != 0x0000ff00)
-        self.failUnless(Color(0, 0, 0, 0) != 0x000000ff)
-        self.failIf(Color(255, 0, 0, 0) != 0xff000000)
-        self.failIf(Color(0, 255, 0, 0) != 0x00ff0000)
-        self.failIf(Color(0, 0, 255, 0) != 0x0000ff00)
-        self.failIf(Color(0, 0, 0, 255) != 0x000000ff)
-
-        self.failUnless(0xff000000 == Color(255, 0, 0, 0))
-        self.failUnless(0x00ff0000 == Color(0, 255, 0, 0))
-        self.failUnless(0x0000ff00 == Color(0, 0, 255, 0))
-        self.failUnless(0x000000ff == Color(0, 0, 0, 255))
-        self.failIf(0xff000000 == Color(0, 0, 0, 0))
-        self.failIf(0x00ff0000 == Color(0, 0, 0, 0))
-        self.failIf(0x0000ff00 == Color(0, 0, 0, 0))
-        self.failIf(0x000000ff == Color(0, 0, 0, 0))
-        self.failUnless(0xff000000 != Color(0, 0, 0, 0))
-        self.failUnless(0x00ff0000 != Color(0, 0, 0, 0))
-        self.failUnless(0x0000ff00 != Color(0, 0, 0, 0))
-        self.failUnless(0x000000ff != Color(0, 0, 0, 0))
-        self.failIf(0xff000000 != Color(255, 0, 0, 0))
-        self.failIf(0x00ff0000 != Color(0, 255, 0, 0))
-        self.failIf(0x0000ff00 != Color(0, 0, 255, 0))
-        self.failIf(0x000000ff != Color(0, 0, 0, 255))
-
-        # Comparison is not implemented for invalid color values
-        class Test(object):
-            def __eq__(self, other):
-                return -1
-            def __ne__(self, other):
-                return -2
-        class TestLong(long):
-            def __eq__(self, other):
-                return -1
-            def __ne__(self, other):
-                return -2
-        class TestStr(str):
-            def __eq__(self, other):
-                return -1
-            def __ne__(self, other):
-                return -2
-        class TestTuple(tuple):
-            def __eq__(self, other):
-                return -1
-            def __ne__(self, other):
-                return -2
-
-        t = Test()
-        t_str = TestStr("Not a color")
-        t_long = TestLong(0xff00000000)
-        t_tuple = TestTuple(('a', 0, 0, 0))
-        black = Color('black')
-        self.assertEqual(black == t, -1)
-        self.assertEqual(t == black, -1)
-        self.assertEqual(black != t, -2)
-        self.assertEqual(t != black, -2)
-        self.assertEqual(black == t_str, -1)
-        self.assertEqual(black != t_str, -2)
-        self.assertEqual(t_str == black, -1)
-        self.assertEqual(t_str != black, -2)
-        self.assertEqual(black == t_long, -1)
-        self.assertEqual(black != t_long, -2)
-        self.assertEqual(t_long == black, -1)
-        self.assertEqual(t_long != black, -2)
-        self.assertEqual(black == t_tuple, -1)
-        self.assertEqual(black != t_tuple, -2)
-        self.assertEqual(t_tuple == black, -1)
-        self.assertEqual(t_tuple != black, -2)
-
-    def test_ignore_whitespace(self):
-        self.assertEquals(pygame.color.Color('red'), pygame.color.Color(' r e d '))
-
-    def test_case_insensitivity_of_string_args(self):
-        self.assertEquals(pygame.color.Color('red'), pygame.color.Color('Red'))
-    
-    def test_color (self):
-        c = pygame.Color (10, 20, 30, 40)
-        self.assertEquals (c.r, 10)
-        self.assertEquals (c.g, 20)
-        self.assertEquals (c.b, 30)
-        self.assertEquals (c.a, 40)
-
-        c = pygame.Color ("indianred3")
-        self.assertEquals (c.r, 205)
-        self.assertEquals (c.g, 85)
-        self.assertEquals (c.b, 85)
-        self.assertEquals (c.a, 255)
-
-        c = pygame.Color (0xAABBCCDD)
-        self.assertEquals (c.r, 0xAA)
-        self.assertEquals (c.g, 0xBB)
-        self.assertEquals (c.b, 0xCC)
-        self.assertEquals (c.a, 0xDD)
-
-        self.assertRaises (ValueError, pygame.Color, 257, 10, 105, 44)
-        self.assertRaises (ValueError, pygame.Color, 10, 257, 105, 44)
-        self.assertRaises (ValueError, pygame.Color, 10, 105, 257, 44)
-        self.assertRaises (ValueError, pygame.Color, 10, 105, 44, 257)
-
-    def test_rgba (self):
-        c = pygame.Color (0)
-        self.assertEquals (c.r, 0)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 0)
-        self.assertEquals (c.a, 0)
-
-        # Test simple assignments
-        c.r = 123
-        self.assertEquals (c.r, 123)
-        self.assertRaises (ValueError, _assignr, c, 537)
-        self.assertEquals (c.r, 123)
-        self.assertRaises (ValueError, _assignr, c, -3)
-        self.assertEquals (c.r, 123)
-
-        c.g = 55
-        self.assertEquals (c.g, 55)
-        self.assertRaises (ValueError, _assigng, c, 348)
-        self.assertEquals (c.g, 55)
-        self.assertRaises (ValueError, _assigng, c, -44)
-        self.assertEquals (c.g, 55)
-
-        c.b = 77
-        self.assertEquals (c.b, 77)
-        self.assertRaises (ValueError, _assignb, c, 256)
-        self.assertEquals (c.b, 77)
-        self.assertRaises (ValueError, _assignb, c, -12)
-        self.assertEquals (c.b, 77)
-
-        c.a = 255
-        self.assertEquals (c.a, 255)
-        self.assertRaises (ValueError, _assigna, c, 312)
-        self.assertEquals (c.a, 255)
-        self.assertRaises (ValueError, _assigna, c, -10)
-        self.assertEquals (c.a, 255)
-        
-    def test_repr (self):
-        c = pygame.Color (68, 38, 26, 69)
-        t = "(68, 38, 26, 69)"
-        self.assertEquals (repr (c), t)
-
-    def test_add (self):
-        c1 = pygame.Color (0)
-        self.assertEquals (c1.r, 0)
-        self.assertEquals (c1.g, 0)
-        self.assertEquals (c1.b, 0)
-        self.assertEquals (c1.a, 0)
-
-        c2 = pygame.Color (20, 33, 82, 193)
-        self.assertEquals (c2.r, 20)
-        self.assertEquals (c2.g, 33)
-        self.assertEquals (c2.b, 82)
-        self.assertEquals (c2.a, 193)
-
-        c3 = c1 + c2
-        self.assertEquals (c3.r, 20)
-        self.assertEquals (c3.g, 33)
-        self.assertEquals (c3.b, 82)
-        self.assertEquals (c3.a, 193)
-
-        c3 = c3 + c2
-        self.assertEquals (c3.r, 40)
-        self.assertEquals (c3.g, 66)
-        self.assertEquals (c3.b, 164)
-        self.assertEquals (c3.a, 255)
-
-    def test_sub (self):
-        c1 = pygame.Color (0xFFFFFFFF)
-        self.assertEquals (c1.r, 255)
-        self.assertEquals (c1.g, 255)
-        self.assertEquals (c1.b, 255)
-        self.assertEquals (c1.a, 255)
-
-        c2 = pygame.Color (20, 33, 82, 193)
-        self.assertEquals (c2.r, 20)
-        self.assertEquals (c2.g, 33)
-        self.assertEquals (c2.b, 82)
-        self.assertEquals (c2.a, 193)
-
-        c3 = c1 - c2
-        self.assertEquals (c3.r, 235)
-        self.assertEquals (c3.g, 222)
-        self.assertEquals (c3.b, 173)
-        self.assertEquals (c3.a, 62)
-
-        c3 = c3 - c2
-        self.assertEquals (c3.r, 215)
-        self.assertEquals (c3.g, 189)
-        self.assertEquals (c3.b, 91)
-        self.assertEquals (c3.a, 0)
-
-    def test_mul (self):
-        c1 = pygame.Color (0x01010101)
-        self.assertEquals (c1.r, 1)
-        self.assertEquals (c1.g, 1)
-        self.assertEquals (c1.b, 1)
-        self.assertEquals (c1.a, 1)
-
-        c2 = pygame.Color (2, 5, 3, 22)
-        self.assertEquals (c2.r, 2)
-        self.assertEquals (c2.g, 5)
-        self.assertEquals (c2.b, 3)
-        self.assertEquals (c2.a, 22)
-
-        c3 = c1 * c2
-        self.assertEquals (c3.r, 2)
-        self.assertEquals (c3.g, 5)
-        self.assertEquals (c3.b, 3)
-        self.assertEquals (c3.a, 22)
-
-        c3 = c3 * c2
-        self.assertEquals (c3.r, 4)
-        self.assertEquals (c3.g, 25)
-        self.assertEquals (c3.b, 9)
-        self.assertEquals (c3.a, 255)
-
-    def test_div (self):
-        c1 = pygame.Color (0x80808080)
-        self.assertEquals (c1.r, 128)
-        self.assertEquals (c1.g, 128)
-        self.assertEquals (c1.b, 128)
-        self.assertEquals (c1.a, 128)
-
-        c2 = pygame.Color (2, 4, 8, 16)
-        self.assertEquals (c2.r, 2)
-        self.assertEquals (c2.g, 4)
-        self.assertEquals (c2.b, 8)
-        self.assertEquals (c2.a, 16)
-
-        c3 = c1 / c2
-        self.assertEquals (c3.r, 64)
-        self.assertEquals (c3.g, 32)
-        self.assertEquals (c3.b, 16)
-        self.assertEquals (c3.a, 8)
-
-        c3 = c3 / c2
-        self.assertEquals (c3.r, 32)
-        self.assertEquals (c3.g, 8)
-        self.assertEquals (c3.b, 2)
-        self.assertEquals (c3.a, 0)
-
-    def test_mod (self):
-        c1 = pygame.Color (0xFFFFFFFF)
-        self.assertEquals (c1.r, 255)
-        self.assertEquals (c1.g, 255)
-        self.assertEquals (c1.b, 255)
-        self.assertEquals (c1.a, 255)
-
-        c2 = pygame.Color (2, 4, 8, 16)
-        self.assertEquals (c2.r, 2)
-        self.assertEquals (c2.g, 4)
-        self.assertEquals (c2.b, 8)
-        self.assertEquals (c2.a, 16)
-
-        c3 = c1 % c2
-        self.assertEquals (c3.r, 1)
-        self.assertEquals (c3.g, 3)
-        self.assertEquals (c3.b, 7)
-        self.assertEquals (c3.a, 15)
-
-    def test_float (self):
-        c = pygame.Color (0xCC00CC00)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 0)
-        self.assertEquals (float (c), float (0xCC00CC00))
-
-        c = pygame.Color (0x33727592)
-        self.assertEquals (c.r, 51)
-        self.assertEquals (c.g, 114)
-        self.assertEquals (c.b, 117)
-        self.assertEquals (c.a, 146)
-        self.assertEquals (float (c), float (0x33727592))
-
-    def test_oct (self):
-        c = pygame.Color (0xCC00CC00)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 0)
-        self.assertEquals (oct (c), oct (0xCC00CC00))
-
-        c = pygame.Color (0x33727592)
-        self.assertEquals (c.r, 51)
-        self.assertEquals (c.g, 114)
-        self.assertEquals (c.b, 117)
-        self.assertEquals (c.a, 146)
-        self.assertEquals (oct (c), oct (0x33727592))
-
-    def test_hex (self):
-        c = pygame.Color (0xCC00CC00)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 0)
-        self.assertEquals (hex (c), hex (0xCC00CC00))
-
-        c = pygame.Color (0x33727592)
-        self.assertEquals (c.r, 51)
-        self.assertEquals (c.g, 114)
-        self.assertEquals (c.b, 117)
-        self.assertEquals (c.a, 146)
-        self.assertEquals (hex (c), hex (0x33727592))
-
-
-    def test_webstyle(self):
-        c = pygame.Color ("#CC00CC11")
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 17)
-        self.assertEquals (hex (c), hex (0xCC00CC11))
-
-        c = pygame.Color ("#CC00CC")
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 255)
-        self.assertEquals (hex (c), hex (0xCC00CCFF))
-
-        c = pygame.Color ("0xCC00CC11")
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 17)
-        self.assertEquals (hex (c), hex (0xCC00CC11))
-
-        c = pygame.Color ("0xCC00CC")
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 255)
-        self.assertEquals (hex (c), hex (0xCC00CCFF))
-
-        self.assertRaises (ValueError, pygame.Color, "#cc00qq")
-        self.assertRaises (ValueError, pygame.Color, "0xcc00qq")
-        self.assertRaises (ValueError, pygame.Color, "09abcdef")
-        self.assertRaises (ValueError, pygame.Color, "09abcde")
-        self.assertRaises (ValueError, pygame.Color, "quarky")
-
-    def test_int (self):
-        # This will be a long
-        c = pygame.Color (0xCC00CC00)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 0)
-        self.assertEquals (int (c), int (0xCC00CC00))
-
-        # This will be an int
-        c = pygame.Color (0x33727592)
-        self.assertEquals (c.r, 51)
-        self.assertEquals (c.g, 114)
-        self.assertEquals (c.b, 117)
-        self.assertEquals (c.a, 146)
-        self.assertEquals (int (c), int (0x33727592))
-
-    def test_long (self):
-        # This will be a long
-        c = pygame.Color (0xCC00CC00)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 0)
-        self.assertEquals (c.b, 204)
-        self.assertEquals (c.a, 0)
-        self.assertEquals (long (c), long (0xCC00CC00))
-
-        # This will be an int
-        c = pygame.Color (0x33727592)
-        self.assertEquals (c.r, 51)
-        self.assertEquals (c.g, 114)
-        self.assertEquals (c.b, 117)
-        self.assertEquals (c.a, 146)
-        self.assertEquals (long (c), long (0x33727592))
-
-    def test_normalize (self):
-        c = pygame.Color (204, 38, 194, 55)
-        self.assertEquals (c.r, 204)
-        self.assertEquals (c.g, 38)
-        self.assertEquals (c.b, 194)
-        self.assertEquals (c.a, 55)
-
-        t = c.normalize ()
-
-        self.assertAlmostEquals (t[0], 0.800000, 5)
-        self.assertAlmostEquals (t[1], 0.149016, 5)
-        self.assertAlmostEquals (t[2], 0.760784, 5)
-        self.assertAlmostEquals (t[3], 0.215686, 5)
-
-    def test_len (self):
-        c = pygame.Color (204, 38, 194, 55)
-        self.assertEquals (len (c), 4)
-
-    def test_get_item (self):
-        c = pygame.Color (204, 38, 194, 55)
-        self.assertEquals (c[0], 204)
-        self.assertEquals (c[1], 38)
-        self.assertEquals (c[2], 194)
-        self.assertEquals (c[3], 55)
-
-    def test_set_item (self):
-        c = pygame.Color (204, 38, 194, 55)
-        self.assertEquals (c[0], 204)
-        self.assertEquals (c[1], 38)
-        self.assertEquals (c[2], 194)
-        self.assertEquals (c[3], 55)
-
-        c[0] = 33
-        self.assertEquals (c[0], 33)
-        c[1] = 48
-        self.assertEquals (c[1], 48)
-        c[2] = 173
-        self.assertEquals (c[2], 173)
-        c[3] = 213
-        self.assertEquals (c[3], 213)
-
-        # Now try some 'invalid' ones
-        self.assertRaises (ValueError, _assign_item, c, 0, 95.485)
-        self.assertEquals (c[0], 33)
-        self.assertRaises (ValueError, _assign_item, c, 1, -83)
-        self.assertEquals (c[1], 48)
-        self.assertRaises (ValueError, _assign_item, c, 2, "Hello")
-        self.assertEquals (c[2], 173)
-        
-    def test_Color_type_works_for_Surface_get_and_set_colorkey(self):
-        s = pygame.Surface((32, 32))
-        
-        c = pygame.Color(33, 22, 11, 255)
-        s.set_colorkey(c)
-
-        get_r, get_g, get_b, get_a = s.get_colorkey()
-
-        self.assert_(get_r == c.r)
-        self.assert_(get_g == c.g)
-        self.assert_(get_b == c.b)
-        self.assert_(get_a == c.a)
-
-########## HSLA, HSVA, CMY, I1I2I3 ALL ELEMENTS WITHIN SPECIFIED RANGE #########
-
-    def test_hsla__all_elements_within_limits (self):
-        for c in rgba_combos_Color_generator():
-            h, s, l, a = c.hsla
-            self.assert_(0 <= h <= 360)
-            self.assert_(0 <= s <= 100)
-            self.assert_(0 <= l <= 100)
-            self.assert_(0 <= a <= 100)
-
-    def test_hsva__all_elements_within_limits (self):
-        for c in rgba_combos_Color_generator():
-            h, s, v, a = c.hsva
-            self.assert_(0 <= h <= 360)
-            self.assert_(0 <= s <= 100)
-            self.assert_(0 <= v <= 100)
-            self.assert_(0 <= a <= 100)
-
-    def test_cmy__all_elements_within_limits (self):
-        for c in rgba_combos_Color_generator():
-            c, m, y = c.cmy
-            self.assert_(0 <= c <= 1)
-            self.assert_(0 <= m <= 1)
-            self.assert_(0 <= y <= 1)
-
-    def test_i1i2i3__all_elements_within_limits (self):        
-        for c in rgba_combos_Color_generator():
-            i1, i2, i3 = c.i1i2i3
-            self.assert_(  0   <= i1 <= 1)
-            self.assert_( -0.5 <= i2 <= 0.5)
-            self.assert_( -0.5 <= i3 <= 0.5)
-
-####################### COLORSPACE PROPERTY SANITY TESTS #######################
-
-    def colorspaces_converted_should_not_raise (self, prop):
-        fails = 0
-
-        x = 0
-        for c in rgba_combos_Color_generator():
-            x += 1
-            
-            other = pygame.Color(0)
-            
-            try:
-                setattr(other, prop, getattr(c, prop))
-                #eg other.hsla = c.hsla
-
-            except ValueError:
-                fails += 1
-
-        self.assert_(x > 0, "x is combination counter, 0 means no tests!")
-        self.assert_((fails, x) == (0, x))
-
-    def test_hsla__sanity_testing_converted_should_not_raise (self):
-        self.colorspaces_converted_should_not_raise('hsla')
-
-    def test_hsva__sanity_testing_converted_should_not_raise (self):
-        self.colorspaces_converted_should_not_raise('hsva')
-
-    def test_cmy__sanity_testing_converted_should_not_raise (self):
-        self.colorspaces_converted_should_not_raise('cmy')
-
-    def test_i1i2i3__sanity_testing_converted_should_not_raise (self):
-        self.colorspaces_converted_should_not_raise('i1i2i3')
-
-################################################################################
-
-    def colorspaces_converted_should_equate_bar_rounding (self, prop):
-        for c in rgba_combos_Color_generator():
-            other = pygame.Color(0)
-
-            try:
-                setattr(other, prop, getattr(c, prop))
-                #eg other.hsla = c.hsla
-                
-                self.assert_(abs(other.r - c.r) <= 1)
-                self.assert_(abs(other.b - c.b) <= 1)
-                self.assert_(abs(other.g - c.g) <= 1)
-                # CMY and I1I2I3 do not care about the alpha
-                if not prop in ("cmy", "i1i2i3"):
-                    self.assert_(abs(other.a - c.a) <= 1)
-                
-            except ValueError:
-                pass        # other tests will notify, this tests equation
-
-    def test_hsla__sanity_testing_converted_should_equate_bar_rounding(self):
-        self.colorspaces_converted_should_equate_bar_rounding('hsla')
-        
-    def test_hsva__sanity_testing_converted_should_equate_bar_rounding(self):
-        self.colorspaces_converted_should_equate_bar_rounding('hsva')
-
-    def test_cmy__sanity_testing_converted_should_equate_bar_rounding(self):
-        self.colorspaces_converted_should_equate_bar_rounding('cmy')
-                    
-    def test_i1i2i3__sanity_testing_converted_should_equate_bar_rounding(self):
-        self.colorspaces_converted_should_equate_bar_rounding('i1i2i3')
-
-################################################################################
-
-    def test_correct_gamma__verified_against_python_implementation(self):
-        "|tags:slow|"
-        # gamma_correct defined at top of page
-
-        gammas = map(lambda i: i / 10.0, range(1, 31)) # [0.1 .. 3.0]
-        gammas_len = len(gammas)
-
-        for i, c in enumerate(rgba_combos_Color_generator()):
-            gamma = gammas[i % gammas_len]
-
-            corrected = pygame.Color(*[gamma_correct(x, gamma) 
-                                                 for x in tuple(c)])
-            lib_corrected = c.correct_gamma(gamma)
-
-            self.assert_(corrected.r == lib_corrected.r)
-            self.assert_(corrected.g == lib_corrected.g)
-            self.assert_(corrected.b == lib_corrected.b)
-            self.assert_(corrected.a == lib_corrected.a)
-
-        # TODO: test against statically defined verified _correct_ values
-        # assert corrected.r == 125 etc.
-
-################################################################################
-
-if __name__ == '__main__':
-    unittest.main()
+#################################### IMPORTS ###################################
+
+from __future__ import generators
+
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import test_not_implemented, unittest
+else:
+    from test.test_utils import test_not_implemented, unittest
+import pygame
+import math
+
+################################### CONSTANTS ##################################
+
+rgba_vals = [0, 1, 62, 63, 126, 127, 255]
+
+rgba_combinations =  [ (r,g,b,a) for r in rgba_vals
+                                 for g in rgba_vals
+                                 for b in rgba_vals
+                                 for a in rgba_vals ]
+
+################################################################################
+
+def rgba_combos_Color_generator ():
+    for rgba in rgba_combinations:
+        yield pygame.Color(*rgba)
+
+# Python gamma correct
+def gamma_correct (rgba_0_255, gamma):
+    corrected = round(255.0 * math.pow(rgba_0_255/255.0, gamma))
+    return max(min( int(corrected), 255), 0)
+
+################################################################################
+
+# TODO: add tests for
+# correct_gamma()  -- test against statically defined verified correct values
+# coerce ()        --  ??
+
+def _assignr (x, y):
+    x.r = y
+
+def _assigng (x, y):
+    x.g = y
+
+def _assignb (x, y):
+    x.b = y
+
+def _assigna (x, y):
+    x.a = y
+
+def _assign_item (x, p, y):
+    x[p] = y
+
+class ColorTypeTest (unittest.TestCase):
+    def test_invalid_html_hex_codes(self):
+        # This was a problem with the way 2 digit hex numbers were
+        # calculated. The test_hex_digits test is related to the fix.
+        Color = pygame.color.Color
+        self.failUnlessRaises(ValueError, lambda: Color('# f000000'))
+        self.failUnlessRaises(ValueError, lambda: Color('#f 000000'))
+        self.failUnlessRaises(ValueError, lambda: Color('#-f000000'))
+
+    def test_hex_digits(self):
+        # This is an implementation specific test.
+        # Two digit hex numbers are calculated using table lookups
+        # for the upper and lower digits.
+        Color = pygame.color.Color
+        self.assertEqual(Color('#00000000').r, 0x00)
+        self.assertEqual(Color('#10000000').r, 0x10)
+        self.assertEqual(Color('#20000000').r, 0x20)
+        self.assertEqual(Color('#30000000').r, 0x30)
+        self.assertEqual(Color('#40000000').r, 0x40)
+        self.assertEqual(Color('#50000000').r, 0x50)
+        self.assertEqual(Color('#60000000').r, 0x60)
+        self.assertEqual(Color('#70000000').r, 0x70)
+        self.assertEqual(Color('#80000000').r, 0x80)
+        self.assertEqual(Color('#90000000').r, 0x90)
+        self.assertEqual(Color('#A0000000').r, 0xA0)
+        self.assertEqual(Color('#B0000000').r, 0xB0)
+        self.assertEqual(Color('#C0000000').r, 0xC0)
+        self.assertEqual(Color('#D0000000').r, 0xD0)
+        self.assertEqual(Color('#E0000000').r, 0xE0)
+        self.assertEqual(Color('#F0000000').r, 0xF0)
+        self.assertEqual(Color('#01000000').r, 0x01)
+        self.assertEqual(Color('#02000000').r, 0x02)
+        self.assertEqual(Color('#03000000').r, 0x03)
+        self.assertEqual(Color('#04000000').r, 0x04)
+        self.assertEqual(Color('#05000000').r, 0x05)
+        self.assertEqual(Color('#06000000').r, 0x06)
+        self.assertEqual(Color('#07000000').r, 0x07)
+        self.assertEqual(Color('#08000000').r, 0x08)
+        self.assertEqual(Color('#09000000').r, 0x09)
+        self.assertEqual(Color('#0A000000').r, 0x0A)
+        self.assertEqual(Color('#0B000000').r, 0x0B)
+        self.assertEqual(Color('#0C000000').r, 0x0C)
+        self.assertEqual(Color('#0D000000').r, 0x0D)
+        self.assertEqual(Color('#0E000000').r, 0x0E)
+        self.assertEqual(Color('#0F000000').r, 0x0F)
+
+    def test_comparison(self):
+        Color = pygame.color.Color
+        self.failUnless(Color(255, 0, 0, 0) == Color(255, 0, 0, 0))
+        self.failUnless(Color(0, 255, 0, 0) == Color(0, 255, 0, 0))
+        self.failUnless(Color(0, 0, 255, 0) == Color(0, 0, 255, 0))
+        self.failUnless(Color(0, 0, 0, 255) == Color(0, 0, 0, 255))
+        self.failIf(Color(0, 0, 0, 0) == Color(255, 0, 0, 0))
+        self.failIf(Color(0, 0, 0, 0) == Color(0, 255, 0, 0))
+        self.failIf(Color(0, 0, 0, 0) == Color(0, 0, 255, 0))
+        self.failIf(Color(0, 0, 0, 0) == Color(0, 0, 0, 255))
+        self.failUnless(Color(0, 0, 0, 0) != Color(255, 0, 0, 0))
+        self.failUnless(Color(0, 0, 0, 0) != Color(0, 255, 0, 0))
+        self.failUnless(Color(0, 0, 0, 0) != Color(0, 0, 255, 0))
+        self.failUnless(Color(0, 0, 0, 0) != Color(0, 0, 0, 255))
+        self.failIf(Color(255, 0, 0, 0) != Color(255, 0, 0, 0))
+        self.failIf(Color(0, 255, 0, 0) != Color(0, 255, 0, 0))
+        self.failIf(Color(0, 0, 255, 0) != Color(0, 0, 255, 0))
+        self.failIf(Color(0, 0, 0, 255) != Color(0, 0, 0, 255))
+
+        self.failUnless(Color(255, 0, 0, 0) == (255, 0, 0, 0))
+        self.failUnless(Color(0, 255, 0, 0) == (0, 255, 0, 0))
+        self.failUnless(Color(0, 0, 255, 0) == (0, 0, 255, 0))
+        self.failUnless(Color(0, 0, 0, 255) == (0, 0, 0, 255))
+        self.failIf(Color(0, 0, 0, 0) == (255, 0, 0, 0))
+        self.failIf(Color(0, 0, 0, 0) == (0, 255, 0, 0))
+        self.failIf(Color(0, 0, 0, 0) == (0, 0, 255, 0))
+        self.failIf(Color(0, 0, 0, 0) == (0, 0, 0, 255))
+        self.failUnless(Color(0, 0, 0, 0) != (255, 0, 0, 0))
+        self.failUnless(Color(0, 0, 0, 0) != (0, 255, 0, 0))
+        self.failUnless(Color(0, 0, 0, 0) != (0, 0, 255, 0))
+        self.failUnless(Color(0, 0, 0, 0) != (0, 0, 0, 255))
+        self.failIf(Color(255, 0, 0, 0) != (255, 0, 0, 0))
+        self.failIf(Color(0, 255, 0, 0) != (0, 255, 0, 0))
+        self.failIf(Color(0, 0, 255, 0) != (0, 0, 255, 0))
+        self.failIf(Color(0, 0, 0, 255) != (0, 0, 0, 255))
+
+        self.failUnless((255, 0, 0, 0) == Color(255, 0, 0, 0))
+        self.failUnless((0, 255, 0, 0) == Color(0, 255, 0, 0))
+        self.failUnless((0, 0, 255, 0) == Color(0, 0, 255, 0))
+        self.failUnless((0, 0, 0, 255) == Color(0, 0, 0, 255))
+        self.failIf((0, 0, 0, 0) == Color(255, 0, 0, 0))
+        self.failIf((0, 0, 0, 0) == Color(0, 255, 0, 0))
+        self.failIf((0, 0, 0, 0) == Color(0, 0, 255, 0))
+        self.failIf((0, 0, 0, 0) == Color(0, 0, 0, 255))
+        self.failUnless((0, 0, 0, 0) != Color(255, 0, 0, 0))
+        self.failUnless((0, 0, 0, 0) != Color(0, 255, 0, 0))
+        self.failUnless((0, 0, 0, 0) != Color(0, 0, 255, 0))
+        self.failUnless((0, 0, 0, 0) != Color(0, 0, 0, 255))
+        self.failIf((255, 0, 0, 0) != Color(255, 0, 0, 0))
+        self.failIf((0, 255, 0, 0) != Color(0, 255, 0, 0))
+        self.failIf((0, 0, 255, 0) != Color(0, 0, 255, 0))
+        self.failIf((0, 0, 0, 255) != Color(0, 0, 0, 255))
+
+        self.failUnless(Color(255, 0, 0, 0) == "#ff000000")
+        self.failUnless(Color(0, 255, 0, 0) == "#00ff0000")
+        self.failUnless(Color(0, 0, 255, 0) == "#0000ff00")
+        self.failUnless(Color(0, 0, 0, 255) == "#000000ff")
+        self.failIf(Color(0, 0, 0, 0) == "#ff000000")
+        self.failIf(Color(0, 0, 0, 0) == "#00ff0000")
+        self.failIf(Color(0, 0, 0, 0) == "#0000ff00")
+        self.failIf(Color(0, 0, 0, 0) == "#000000ff")
+        self.failUnless(Color(0, 0, 0, 0) != "#ff000000")
+        self.failUnless(Color(0, 0, 0, 0) != "#00ff0000")
+        self.failUnless(Color(0, 0, 0, 0) != "#0000ff00")
+        self.failUnless(Color(0, 0, 0, 0) != "#000000ff")
+        self.failIf(Color(255, 0, 0, 0) != "#ff000000")
+        self.failIf(Color(0, 255, 0, 0) != "#00ff0000")
+        self.failIf(Color(0, 0, 255, 0) != "#0000ff00")
+        self.failIf(Color(0, 0, 0, 255) != "#000000ff")
+
+        self.failUnless("#ff000000" == Color(255, 0, 0, 0))
+        self.failUnless("#00ff0000" == Color(0, 255, 0, 0))
+        self.failUnless("#0000ff00" == Color(0, 0, 255, 0))
+        self.failUnless("#000000ff" == Color(0, 0, 0, 255))
+        self.failIf("#ff000000" == Color(0, 0, 0, 0))
+        self.failIf("#00ff0000" == Color(0, 0, 0, 0))
+        self.failIf("#0000ff00" == Color(0, 0, 0, 0))
+        self.failIf("#000000ff" == Color(0, 0, 0, 0))
+        self.failUnless("#ff000000" != Color(0, 0, 0, 0))
+        self.failUnless("#00ff0000" != Color(0, 0, 0, 0))
+        self.failUnless("#0000ff00" != Color(0, 0, 0, 0))
+        self.failUnless("#000000ff" != Color(0, 0, 0, 0))
+        self.failIf("#ff000000" != Color(255, 0, 0, 0))
+        self.failIf("#00ff0000" != Color(0, 255, 0, 0))
+        self.failIf("#0000ff00" != Color(0, 0, 255, 0))
+        self.failIf("#000000ff" != Color(0, 0, 0, 255))
+
+        self.failUnless(Color(255, 0, 0, 0) == 0xff000000)
+        self.failUnless(Color(0, 255, 0, 0) == 0x00ff0000)
+        self.failUnless(Color(0, 0, 255, 0) == 0x0000ff00)
+        self.failUnless(Color(0, 0, 0, 255) == 0x000000ff)
+        self.failIf(Color(0, 0, 0, 0) == 0xff000000)
+        self.failIf(Color(0, 0, 0, 0) == 0x00ff0000)
+        self.failIf(Color(0, 0, 0, 0) == 0x0000ff00)
+        self.failIf(Color(0, 0, 0, 0) == 0x000000ff)
+        self.failUnless(Color(0, 0, 0, 0) != 0xff000000)
+        self.failUnless(Color(0, 0, 0, 0) != 0x00ff0000)
+        self.failUnless(Color(0, 0, 0, 0) != 0x0000ff00)
+        self.failUnless(Color(0, 0, 0, 0) != 0x000000ff)
+        self.failIf(Color(255, 0, 0, 0) != 0xff000000)
+        self.failIf(Color(0, 255, 0, 0) != 0x00ff0000)
+        self.failIf(Color(0, 0, 255, 0) != 0x0000ff00)
+        self.failIf(Color(0, 0, 0, 255) != 0x000000ff)
+
+        self.failUnless(0xff000000 == Color(255, 0, 0, 0))
+        self.failUnless(0x00ff0000 == Color(0, 255, 0, 0))
+        self.failUnless(0x0000ff00 == Color(0, 0, 255, 0))
+        self.failUnless(0x000000ff == Color(0, 0, 0, 255))
+        self.failIf(0xff000000 == Color(0, 0, 0, 0))
+        self.failIf(0x00ff0000 == Color(0, 0, 0, 0))
+        self.failIf(0x0000ff00 == Color(0, 0, 0, 0))
+        self.failIf(0x000000ff == Color(0, 0, 0, 0))
+        self.failUnless(0xff000000 != Color(0, 0, 0, 0))
+        self.failUnless(0x00ff0000 != Color(0, 0, 0, 0))
+        self.failUnless(0x0000ff00 != Color(0, 0, 0, 0))
+        self.failUnless(0x000000ff != Color(0, 0, 0, 0))
+        self.failIf(0xff000000 != Color(255, 0, 0, 0))
+        self.failIf(0x00ff0000 != Color(0, 255, 0, 0))
+        self.failIf(0x0000ff00 != Color(0, 0, 255, 0))
+        self.failIf(0x000000ff != Color(0, 0, 0, 255))
+
+        # Comparison is not implemented for invalid color values
+        class Test(object):
+            def __eq__(self, other):
+                return -1
+            def __ne__(self, other):
+                return -2
+        class TestLong(long):
+            def __eq__(self, other):
+                return -1
+            def __ne__(self, other):
+                return -2
+        class TestStr(str):
+            def __eq__(self, other):
+                return -1
+            def __ne__(self, other):
+                return -2
+        class TestTuple(tuple):
+            def __eq__(self, other):
+                return -1
+            def __ne__(self, other):
+                return -2
+
+        t = Test()
+        t_str = TestStr("Not a color")
+        t_long = TestLong(0xff00000000)
+        t_tuple = TestTuple(('a', 0, 0, 0))
+        black = Color('black')
+        self.assertEqual(black == t, -1)
+        self.assertEqual(t == black, -1)
+        self.assertEqual(black != t, -2)
+        self.assertEqual(t != black, -2)
+        self.assertEqual(black == t_str, -1)
+        self.assertEqual(black != t_str, -2)
+        self.assertEqual(t_str == black, -1)
+        self.assertEqual(t_str != black, -2)
+        self.assertEqual(black == t_long, -1)
+        self.assertEqual(black != t_long, -2)
+        self.assertEqual(t_long == black, -1)
+        self.assertEqual(t_long != black, -2)
+        self.assertEqual(black == t_tuple, -1)
+        self.assertEqual(black != t_tuple, -2)
+        self.assertEqual(t_tuple == black, -1)
+        self.assertEqual(t_tuple != black, -2)
+
+    def test_ignore_whitespace(self):
+        self.assertEquals(pygame.color.Color('red'), pygame.color.Color(' r e d '))
+
+    def test_case_insensitivity_of_string_args(self):
+        self.assertEquals(pygame.color.Color('red'), pygame.color.Color('Red'))
+    
+    def test_color (self):
+        c = pygame.Color (10, 20, 30, 40)
+        self.assertEquals (c.r, 10)
+        self.assertEquals (c.g, 20)
+        self.assertEquals (c.b, 30)
+        self.assertEquals (c.a, 40)
+
+        c = pygame.Color ("indianred3")
+        self.assertEquals (c.r, 205)
+        self.assertEquals (c.g, 85)
+        self.assertEquals (c.b, 85)
+        self.assertEquals (c.a, 255)
+
+        c = pygame.Color (0xAABBCCDD)
+        self.assertEquals (c.r, 0xAA)
+        self.assertEquals (c.g, 0xBB)
+        self.assertEquals (c.b, 0xCC)
+        self.assertEquals (c.a, 0xDD)
+
+        self.assertRaises (ValueError, pygame.Color, 257, 10, 105, 44)
+        self.assertRaises (ValueError, pygame.Color, 10, 257, 105, 44)
+        self.assertRaises (ValueError, pygame.Color, 10, 105, 257, 44)
+        self.assertRaises (ValueError, pygame.Color, 10, 105, 44, 257)
+
+    def test_rgba (self):
+        c = pygame.Color (0)
+        self.assertEquals (c.r, 0)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 0)
+        self.assertEquals (c.a, 0)
+
+        # Test simple assignments
+        c.r = 123
+        self.assertEquals (c.r, 123)
+        self.assertRaises (ValueError, _assignr, c, 537)
+        self.assertEquals (c.r, 123)
+        self.assertRaises (ValueError, _assignr, c, -3)
+        self.assertEquals (c.r, 123)
+
+        c.g = 55
+        self.assertEquals (c.g, 55)
+        self.assertRaises (ValueError, _assigng, c, 348)
+        self.assertEquals (c.g, 55)
+        self.assertRaises (ValueError, _assigng, c, -44)
+        self.assertEquals (c.g, 55)
+
+        c.b = 77
+        self.assertEquals (c.b, 77)
+        self.assertRaises (ValueError, _assignb, c, 256)
+        self.assertEquals (c.b, 77)
+        self.assertRaises (ValueError, _assignb, c, -12)
+        self.assertEquals (c.b, 77)
+
+        c.a = 255
+        self.assertEquals (c.a, 255)
+        self.assertRaises (ValueError, _assigna, c, 312)
+        self.assertEquals (c.a, 255)
+        self.assertRaises (ValueError, _assigna, c, -10)
+        self.assertEquals (c.a, 255)
+        
+    def test_repr (self):
+        c = pygame.Color (68, 38, 26, 69)
+        t = "(68, 38, 26, 69)"
+        self.assertEquals (repr (c), t)
+
+    def test_add (self):
+        c1 = pygame.Color (0)
+        self.assertEquals (c1.r, 0)
+        self.assertEquals (c1.g, 0)
+        self.assertEquals (c1.b, 0)
+        self.assertEquals (c1.a, 0)
+
+        c2 = pygame.Color (20, 33, 82, 193)
+        self.assertEquals (c2.r, 20)
+        self.assertEquals (c2.g, 33)
+        self.assertEquals (c2.b, 82)
+        self.assertEquals (c2.a, 193)
+
+        c3 = c1 + c2
+        self.assertEquals (c3.r, 20)
+        self.assertEquals (c3.g, 33)
+        self.assertEquals (c3.b, 82)
+        self.assertEquals (c3.a, 193)
+
+        c3 = c3 + c2
+        self.assertEquals (c3.r, 40)
+        self.assertEquals (c3.g, 66)
+        self.assertEquals (c3.b, 164)
+        self.assertEquals (c3.a, 255)
+
+    def test_sub (self):
+        c1 = pygame.Color (0xFFFFFFFF)
+        self.assertEquals (c1.r, 255)
+        self.assertEquals (c1.g, 255)
+        self.assertEquals (c1.b, 255)
+        self.assertEquals (c1.a, 255)
+
+        c2 = pygame.Color (20, 33, 82, 193)
+        self.assertEquals (c2.r, 20)
+        self.assertEquals (c2.g, 33)
+        self.assertEquals (c2.b, 82)
+        self.assertEquals (c2.a, 193)
+
+        c3 = c1 - c2
+        self.assertEquals (c3.r, 235)
+        self.assertEquals (c3.g, 222)
+        self.assertEquals (c3.b, 173)
+        self.assertEquals (c3.a, 62)
+
+        c3 = c3 - c2
+        self.assertEquals (c3.r, 215)
+        self.assertEquals (c3.g, 189)
+        self.assertEquals (c3.b, 91)
+        self.assertEquals (c3.a, 0)
+
+    def test_mul (self):
+        c1 = pygame.Color (0x01010101)
+        self.assertEquals (c1.r, 1)
+        self.assertEquals (c1.g, 1)
+        self.assertEquals (c1.b, 1)
+        self.assertEquals (c1.a, 1)
+
+        c2 = pygame.Color (2, 5, 3, 22)
+        self.assertEquals (c2.r, 2)
+        self.assertEquals (c2.g, 5)
+        self.assertEquals (c2.b, 3)
+        self.assertEquals (c2.a, 22)
+
+        c3 = c1 * c2
+        self.assertEquals (c3.r, 2)
+        self.assertEquals (c3.g, 5)
+        self.assertEquals (c3.b, 3)
+        self.assertEquals (c3.a, 22)
+
+        c3 = c3 * c2
+        self.assertEquals (c3.r, 4)
+        self.assertEquals (c3.g, 25)
+        self.assertEquals (c3.b, 9)
+        self.assertEquals (c3.a, 255)
+
+    def test_div (self):
+        c1 = pygame.Color (0x80808080)
+        self.assertEquals (c1.r, 128)
+        self.assertEquals (c1.g, 128)
+        self.assertEquals (c1.b, 128)
+        self.assertEquals (c1.a, 128)
+
+        c2 = pygame.Color (2, 4, 8, 16)
+        self.assertEquals (c2.r, 2)
+        self.assertEquals (c2.g, 4)
+        self.assertEquals (c2.b, 8)
+        self.assertEquals (c2.a, 16)
+
+        c3 = c1 / c2
+        self.assertEquals (c3.r, 64)
+        self.assertEquals (c3.g, 32)
+        self.assertEquals (c3.b, 16)
+        self.assertEquals (c3.a, 8)
+
+        c3 = c3 / c2
+        self.assertEquals (c3.r, 32)
+        self.assertEquals (c3.g, 8)
+        self.assertEquals (c3.b, 2)
+        self.assertEquals (c3.a, 0)
+
+    def test_mod (self):
+        c1 = pygame.Color (0xFFFFFFFF)
+        self.assertEquals (c1.r, 255)
+        self.assertEquals (c1.g, 255)
+        self.assertEquals (c1.b, 255)
+        self.assertEquals (c1.a, 255)
+
+        c2 = pygame.Color (2, 4, 8, 16)
+        self.assertEquals (c2.r, 2)
+        self.assertEquals (c2.g, 4)
+        self.assertEquals (c2.b, 8)
+        self.assertEquals (c2.a, 16)
+
+        c3 = c1 % c2
+        self.assertEquals (c3.r, 1)
+        self.assertEquals (c3.g, 3)
+        self.assertEquals (c3.b, 7)
+        self.assertEquals (c3.a, 15)
+
+    def test_float (self):
+        c = pygame.Color (0xCC00CC00)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 0)
+        self.assertEquals (float (c), float (0xCC00CC00))
+
+        c = pygame.Color (0x33727592)
+        self.assertEquals (c.r, 51)
+        self.assertEquals (c.g, 114)
+        self.assertEquals (c.b, 117)
+        self.assertEquals (c.a, 146)
+        self.assertEquals (float (c), float (0x33727592))
+
+    def test_oct (self):
+        c = pygame.Color (0xCC00CC00)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 0)
+        self.assertEquals (oct (c), oct (0xCC00CC00))
+
+        c = pygame.Color (0x33727592)
+        self.assertEquals (c.r, 51)
+        self.assertEquals (c.g, 114)
+        self.assertEquals (c.b, 117)
+        self.assertEquals (c.a, 146)
+        self.assertEquals (oct (c), oct (0x33727592))
+
+    def test_hex (self):
+        c = pygame.Color (0xCC00CC00)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 0)
+        self.assertEquals (hex (c), hex (0xCC00CC00))
+
+        c = pygame.Color (0x33727592)
+        self.assertEquals (c.r, 51)
+        self.assertEquals (c.g, 114)
+        self.assertEquals (c.b, 117)
+        self.assertEquals (c.a, 146)
+        self.assertEquals (hex (c), hex (0x33727592))
+
+
+    def test_webstyle(self):
+        c = pygame.Color ("#CC00CC11")
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 17)
+        self.assertEquals (hex (c), hex (0xCC00CC11))
+
+        c = pygame.Color ("#CC00CC")
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 255)
+        self.assertEquals (hex (c), hex (0xCC00CCFF))
+
+        c = pygame.Color ("0xCC00CC11")
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 17)
+        self.assertEquals (hex (c), hex (0xCC00CC11))
+
+        c = pygame.Color ("0xCC00CC")
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 255)
+        self.assertEquals (hex (c), hex (0xCC00CCFF))
+
+        self.assertRaises (ValueError, pygame.Color, "#cc00qq")
+        self.assertRaises (ValueError, pygame.Color, "0xcc00qq")
+        self.assertRaises (ValueError, pygame.Color, "09abcdef")
+        self.assertRaises (ValueError, pygame.Color, "09abcde")
+        self.assertRaises (ValueError, pygame.Color, "quarky")
+
+    def test_int (self):
+        # This will be a long
+        c = pygame.Color (0xCC00CC00)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 0)
+        self.assertEquals (int (c), int (0xCC00CC00))
+
+        # This will be an int
+        c = pygame.Color (0x33727592)
+        self.assertEquals (c.r, 51)
+        self.assertEquals (c.g, 114)
+        self.assertEquals (c.b, 117)
+        self.assertEquals (c.a, 146)
+        self.assertEquals (int (c), int (0x33727592))
+
+    def test_long (self):
+        # This will be a long
+        c = pygame.Color (0xCC00CC00)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 0)
+        self.assertEquals (c.b, 204)
+        self.assertEquals (c.a, 0)
+        self.assertEquals (long (c), long (0xCC00CC00))
+
+        # This will be an int
+        c = pygame.Color (0x33727592)
+        self.assertEquals (c.r, 51)
+        self.assertEquals (c.g, 114)
+        self.assertEquals (c.b, 117)
+        self.assertEquals (c.a, 146)
+        self.assertEquals (long (c), long (0x33727592))
+
+    def test_normalize (self):
+        c = pygame.Color (204, 38, 194, 55)
+        self.assertEquals (c.r, 204)
+        self.assertEquals (c.g, 38)
+        self.assertEquals (c.b, 194)
+        self.assertEquals (c.a, 55)
+
+        t = c.normalize ()
+
+        self.assertAlmostEquals (t[0], 0.800000, 5)
+        self.assertAlmostEquals (t[1], 0.149016, 5)
+        self.assertAlmostEquals (t[2], 0.760784, 5)
+        self.assertAlmostEquals (t[3], 0.215686, 5)
+
+    def test_len (self):
+        c = pygame.Color (204, 38, 194, 55)
+        self.assertEquals (len (c), 4)
+
+    def test_get_item (self):
+        c = pygame.Color (204, 38, 194, 55)
+        self.assertEquals (c[0], 204)
+        self.assertEquals (c[1], 38)
+        self.assertEquals (c[2], 194)
+        self.assertEquals (c[3], 55)
+
+    def test_set_item (self):
+        c = pygame.Color (204, 38, 194, 55)
+        self.assertEquals (c[0], 204)
+        self.assertEquals (c[1], 38)
+        self.assertEquals (c[2], 194)
+        self.assertEquals (c[3], 55)
+
+        c[0] = 33
+        self.assertEquals (c[0], 33)
+        c[1] = 48
+        self.assertEquals (c[1], 48)
+        c[2] = 173
+        self.assertEquals (c[2], 173)
+        c[3] = 213
+        self.assertEquals (c[3], 213)
+
+        # Now try some 'invalid' ones
+        self.assertRaises (ValueError, _assign_item, c, 0, 95.485)
+        self.assertEquals (c[0], 33)
+        self.assertRaises (ValueError, _assign_item, c, 1, -83)
+        self.assertEquals (c[1], 48)
+        self.assertRaises (ValueError, _assign_item, c, 2, "Hello")
+        self.assertEquals (c[2], 173)
+        
+    def test_Color_type_works_for_Surface_get_and_set_colorkey(self):
+        s = pygame.Surface((32, 32))
+        
+        c = pygame.Color(33, 22, 11, 255)
+        s.set_colorkey(c)
+
+        get_r, get_g, get_b, get_a = s.get_colorkey()
+
+        self.assert_(get_r == c.r)
+        self.assert_(get_g == c.g)
+        self.assert_(get_b == c.b)
+        self.assert_(get_a == c.a)
+
+########## HSLA, HSVA, CMY, I1I2I3 ALL ELEMENTS WITHIN SPECIFIED RANGE #########
+
+    def test_hsla__all_elements_within_limits (self):
+        for c in rgba_combos_Color_generator():
+            h, s, l, a = c.hsla
+            self.assert_(0 <= h <= 360)
+            self.assert_(0 <= s <= 100)
+            self.assert_(0 <= l <= 100)
+            self.assert_(0 <= a <= 100)
+
+    def test_hsva__all_elements_within_limits (self):
+        for c in rgba_combos_Color_generator():
+            h, s, v, a = c.hsva
+            self.assert_(0 <= h <= 360)
+            self.assert_(0 <= s <= 100)
+            self.assert_(0 <= v <= 100)
+            self.assert_(0 <= a <= 100)
+
+    def test_cmy__all_elements_within_limits (self):
+        for c in rgba_combos_Color_generator():
+            c, m, y = c.cmy
+            self.assert_(0 <= c <= 1)
+            self.assert_(0 <= m <= 1)
+            self.assert_(0 <= y <= 1)
+
+    def test_i1i2i3__all_elements_within_limits (self):        
+        for c in rgba_combos_Color_generator():
+            i1, i2, i3 = c.i1i2i3
+            self.assert_(  0   <= i1 <= 1)
+            self.assert_( -0.5 <= i2 <= 0.5)
+            self.assert_( -0.5 <= i3 <= 0.5)
+
+####################### COLORSPACE PROPERTY SANITY TESTS #######################
+
+    def colorspaces_converted_should_not_raise (self, prop):
+        fails = 0
+
+        x = 0
+        for c in rgba_combos_Color_generator():
+            x += 1
+            
+            other = pygame.Color(0)
+            
+            try:
+                setattr(other, prop, getattr(c, prop))
+                #eg other.hsla = c.hsla
+
+            except ValueError:
+                fails += 1
+
+        self.assert_(x > 0, "x is combination counter, 0 means no tests!")
+        self.assert_((fails, x) == (0, x))
+
+    def test_hsla__sanity_testing_converted_should_not_raise (self):
+        self.colorspaces_converted_should_not_raise('hsla')
+
+    def test_hsva__sanity_testing_converted_should_not_raise (self):
+        self.colorspaces_converted_should_not_raise('hsva')
+
+    def test_cmy__sanity_testing_converted_should_not_raise (self):
+        self.colorspaces_converted_should_not_raise('cmy')
+
+    def test_i1i2i3__sanity_testing_converted_should_not_raise (self):
+        self.colorspaces_converted_should_not_raise('i1i2i3')
+
+################################################################################
+
+    def colorspaces_converted_should_equate_bar_rounding (self, prop):
+        for c in rgba_combos_Color_generator():
+            other = pygame.Color(0)
+
+            try:
+                setattr(other, prop, getattr(c, prop))
+                #eg other.hsla = c.hsla
+                
+                self.assert_(abs(other.r - c.r) <= 1)
+                self.assert_(abs(other.b - c.b) <= 1)
+                self.assert_(abs(other.g - c.g) <= 1)
+                # CMY and I1I2I3 do not care about the alpha
+                if not prop in ("cmy", "i1i2i3"):
+                    self.assert_(abs(other.a - c.a) <= 1)
+                
+            except ValueError:
+                pass        # other tests will notify, this tests equation
+
+    def test_hsla__sanity_testing_converted_should_equate_bar_rounding(self):
+        self.colorspaces_converted_should_equate_bar_rounding('hsla')
+        
+    def test_hsva__sanity_testing_converted_should_equate_bar_rounding(self):
+        self.colorspaces_converted_should_equate_bar_rounding('hsva')
+
+    def test_cmy__sanity_testing_converted_should_equate_bar_rounding(self):
+        self.colorspaces_converted_should_equate_bar_rounding('cmy')
+                    
+    def test_i1i2i3__sanity_testing_converted_should_equate_bar_rounding(self):
+        self.colorspaces_converted_should_equate_bar_rounding('i1i2i3')
+
+################################################################################
+
+    def test_correct_gamma__verified_against_python_implementation(self):
+        "|tags:slow|"
+        # gamma_correct defined at top of page
+
+        gammas = map(lambda i: i / 10.0, range(1, 31)) # [0.1 .. 3.0]
+        gammas_len = len(gammas)
+
+        for i, c in enumerate(rgba_combos_Color_generator()):
+            gamma = gammas[i % gammas_len]
+
+            corrected = pygame.Color(*[gamma_correct(x, gamma) 
+                                                 for x in tuple(c)])
+            lib_corrected = c.correct_gamma(gamma)
+
+            self.assert_(corrected.r == lib_corrected.r)
+            self.assert_(corrected.g == lib_corrected.g)
+            self.assert_(corrected.b == lib_corrected.b)
+            self.assert_(corrected.a == lib_corrected.a)
+
+        # TODO: test against statically defined verified _correct_ values
+        # assert corrected.r == 125 etc.
+
+################################################################################
+
+if __name__ == '__main__':
+    unittest.main()

test/cursors_test.py

 #################################### IMPORTS ###################################
 
-import test_utils
-import test.unittest as unittest
-from test_utils import test_not_implemented, fixture_path
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
 
+if is_pygame_pkg:
+    from pygame.tests.test_utils \
+         import test_not_implemented, fixture_path, unittest
+else:
+    from test.test_utils \
+         import test_not_implemented, fixture_path, unittest
 import pygame
 
 ################################################################################
 if __name__ == '__main__':
     unittest.main()
     
-################################################################################
+################################################################################

test/display_test.py

-import test_utils
-import test.unittest as unittest
+if __name__ == '__main__':
+    import sys
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils import test_not_implemented, unittest
+else:
+    from test.test_utils import test_not_implemented, unittest
 import pygame, pygame.transform
 
-from test_utils import test_not_implemented
-
 class DisplayModuleTest( unittest.TestCase ):
     def test_update( self ):
         """ see if pygame.display.update takes rects with negative values.
         self.fail() 
 
 if __name__ == '__main__':