Skip to content

Commit

Permalink
Add repr to Color
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
bsoyka committed Jan 4, 2021
1 parent 6909de6 commit cf71f89
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pigment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Color:
def __init__(self, red: int, green: int, blue: int):
self.rgb = (red, green, blue)

def __repr__(self):
return "<pigment.Color r=%r g=%r b=%r>" % self.rgb

def __eq__(self, other):
if isinstance(other, Color):
return self.rgb == other.rgb
Expand Down
14 changes: 14 additions & 0 deletions tests/test_repr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pytest import mark

from pigment import Color


@mark.parametrize(
"color,expected",
[
(Color(0, 0, 0), "<pigment.Color r=0 g=0 b=0>"),
(Color(255, 255, 255), "<pigment.Color r=255 g=255 b=255>"),
],
)
def test_repr(color, expected):
assert repr(color) == expected

0 comments on commit cf71f89

Please sign in to comment.