Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Add custom coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankLawrence committed Jun 17, 2024
1 parent a924e68 commit 51d176f
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions discord/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import colorsys
import random
import re
from cov import test, mark

from typing import TYPE_CHECKING, Optional, Tuple, Union

Expand Down Expand Up @@ -174,6 +175,7 @@ def from_hsv(cls, h: float, s: float, v: float) -> Self:
rgb = colorsys.hsv_to_rgb(h, s, v)
return cls.from_rgb(*(int(x * 255) for x in rgb))

@test(7)
@classmethod
def from_str(cls, value: str) -> Colour:
"""Constructs a :class:`Colour` from a string.
Expand All @@ -197,22 +199,29 @@ def from_str(cls, value: str) -> Colour:
"""

if not value:
mark(0)
raise ValueError('unknown colour format given')

if value[0] == '#':
mark(1)
return parse_hex_number(value[1:])

if value[0:2] == '0x':
mark(2)
rest = value[2:]
# Legacy backwards compatible syntax
if rest.startswith('#'):
mark(3)
return parse_hex_number(rest[1:])
mark(4)
return parse_hex_number(rest)

arg = value.lower()
if arg[0:3] == 'rgb':
mark(5)
return parse_rgb(arg)

mark(6)
raise ValueError('unknown colour format given')

@classmethod
Expand Down

0 comments on commit 51d176f

Please sign in to comment.