Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiommendes committed Sep 9, 2016
1 parent 53f09cd commit bed0c4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
17 changes: 7 additions & 10 deletions src/colortools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Color(object):
"""
Represents a color.
"""

__slots__ = ['_red', '_green', '_blue', '_alpha']
_CACHE = {}
_RANGE = (0, 1, 2, 3)
Expand Down Expand Up @@ -208,15 +209,13 @@ def hsif(self):
return tuple(x / 255 for x in self.hsi)

def copy(self, red=None, green=None, blue=None, alpha=None, **kwds):
"""Copia a cor possivelmente trocando o valor de alguma das componentes
RGBA ou componentes HSL ou HSI.
Examples
--------
"""
Returns a copy, possibly changing the value of a component.
>>> color = Color('white')
>>> color.copy(red=80, alpha=128)
Color(80, 255, 255, 128)
Example:
>>> color = Color('white')
>>> color.copy(red=80, alpha=128)
Color(80, 255, 255, 128)
"""
R, G, B, A = self

Expand Down Expand Up @@ -547,5 +546,3 @@ def rgba(color):
return color.rgba
except AttributeError:
return Color(color or 'black').rgba

import pgzero
12 changes: 12 additions & 0 deletions src/colortools/tests/test_colortools.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ def test_init_from_8_hex():
assert Color('#00FF0080') == Color(0, 255, 0, 128)


def test_init_from_color():
black = Color(0, 0, 0)
assert Color(black) == black


def test_init_from_sequence():
black = Color(0, 0, 0)
assert Color([0, 0, 0]) == black
assert Color((0, 0, 0)) == black
assert Color((0, 0, 0, 255)) == black


def test_color_compares_with_tuple():
color = Color('red')
assert color == (255, 0, 0, 255)
Expand Down

0 comments on commit bed0c4a

Please sign in to comment.