File: test_utils.py

package info (click to toggle)
python-colorful 0.5.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,124 kB
  • sloc: python: 1,343; sh: 8; makefile: 3
file content (55 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-

"""
    colorful
    ~~~~~~~~

    Terminal string styling done right, in Python.

    :copyright: (c) 2017 by Timo Furrer <tuxtimo@gmail.com>
    :license: MIT, see LICENSE for more details.
"""

import os

import pytest

# do not overwrite module
os.environ['COLORFUL_NO_MODULE_OVERWRITE'] = '1'

import colorful.utils as utils  # noqa


@pytest.mark.parametrize('hex_value', [
    '#FFFFFF',
    '#0000FF',
    '#FF0000',
    '#00FF00',
    '#808080',
    '#FFFF00',
    '#00FFFF',
    '#EF8BA0',
    '#012345',
    '#999FFF',
    '#05fecA'
])
def test_hex_to_rgb_conversion(hex_value):
    """
    Test the conversion from a RGB hex value to a RGB channel triplet
    """
    red, green, blue = utils.hex_to_rgb(hex_value)
    assert '#{:02X}{:02X}{:02X}'.format(red, green, blue).lower() == hex_value.lower()


@pytest.mark.parametrize('hex_error_value', [
    '#FFFFF',
    '#FFFFFFF',
    '#FFFFFG',
    '#fffffG',
])
def test_hex_to_rgb_error(hex_error_value):
    """
    Test if the given hex values are invalid
    """
    with pytest.raises(ValueError):
        utils.hex_to_rgb(hex_error_value)