File: test_argutils.py

package info (click to toggle)
terminaltexteffects 0.14.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,324 kB
  • sloc: python: 16,857; makefile: 3
file content (157 lines) | stat: -rw-r--r-- 5,065 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from argparse import ArgumentTypeError

import pytest

from terminaltexteffects.utils import argutils, easing
from terminaltexteffects.utils.graphics import Color, Gradient

pytestmark = [pytest.mark.utils, pytest.mark.smoke]


def test_postive_int_valid_int():
    assert argutils.PositiveInt.type_parser("1") == 1


@pytest.mark.parametrize("arg", ["-1", "0", "1.1", "a"])
def test_postive_int_invalid_int(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.PositiveInt.type_parser(arg)


def test_non_negative_int_valid_int():
    assert argutils.NonNegativeInt.type_parser("0") == 0


@pytest.mark.parametrize("arg", ["-1", "1.1", "a"])
def test_non_negative_int_invalid_int(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.NonNegativeInt.type_parser(arg)


def test_positive_int_range_valid_range():
    assert argutils.PositiveIntRange.type_parser("1-10") == (1, 10)


@pytest.mark.parametrize("arg", ["-1-10", "1.1-10", "a-10", "1-10.1", "1-a", "2-1", "0-3"])
def test_positive_int_range_invalid_range(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.PositiveIntRange.type_parser(arg)


def test_positive_float_valid_float():
    assert argutils.PositiveFloat.type_parser("1.1") == 1.1


@pytest.mark.parametrize("arg", ["-1.1", "0", "a"])
def test_positive_float_invalid_float(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.PositiveFloat.type_parser(arg)


def test_non_negative_float_valid_float():
    assert argutils.NonNegativeFloat.type_parser("0") == 0
    assert argutils.NonNegativeFloat.type_parser("1.1") == 1.1


@pytest.mark.parametrize("arg", ["-1.1", "a"])
def test_non_negative_float_invalid_float(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.NonNegativeFloat.type_parser(arg)


def test_positive_float_range_valid_range():
    assert argutils.PositiveFloatRange.type_parser("1.1-10.1") == (1.1, 10.1)


@pytest.mark.parametrize("arg", ["-1.1-10.1", "a-10.1", "1.1-10.1.1", "1.1-a", "2.1-1.1", "0-3"])
def test_positive_float_range_invalid_range(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.PositiveFloatRange.type_parser(arg)


def test_NonNegativeRatio_valid_ratio():
    assert argutils.NonNegativeRatio.type_parser("0.5") == 0.5
    assert argutils.NonNegativeRatio.type_parser("1") == 1
    assert argutils.NonNegativeRatio.type_parser("0") == 0


@pytest.mark.parametrize("arg", ["-1", "1.1", "a"])
def test_NonNegativeRatio_invalid_ratio(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.NonNegativeRatio.type_parser(arg)


def test_PositiveRatio_valid_ratio():
    assert argutils.PositiveRatio.type_parser("0.5") == 0.5
    assert argutils.PositiveRatio.type_parser("1.0") == 1
    assert argutils.PositiveRatio.type_parser("0.01") == 0.01


@pytest.mark.parametrize("arg", ["-1", "1.1", "0", "a"])
def test_PositiveRatio_invalid_ratio(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.PositiveRatio.type_parser(arg)


def test_gradient_direction_valid_direction():
    assert argutils.GradientDirection.type_parser("horizontal") == Gradient.Direction.HORIZONTAL
    assert argutils.GradientDirection.type_parser("vertical") == Gradient.Direction.VERTICAL


def test_gradient_direction_invalid_direction():
    with pytest.raises(ArgumentTypeError):
        argutils.GradientDirection.type_parser("invalid")


def test_color_arg_valid_color():
    assert argutils.ColorArg.type_parser("125") == Color(125)
    assert argutils.ColorArg.type_parser("ffffff") == Color("#ffffff")


@pytest.mark.parametrize("arg", ["-1", "256", "ffffzz", "aaa"])
def test_color_arg_invalid_color(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.ColorArg.type_parser(arg)


def test_symbol_valid_symbol():
    assert argutils.Symbol.type_parser("a") == "a"


@pytest.mark.parametrize("arg", ["", "aa"])
def test_symbol_invalid_symbol(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.Symbol.type_parser(arg)


def test_canvas_dimensions_valid_dimension():
    assert argutils.CanvasDimension.type_parser("0") == 0
    assert argutils.CanvasDimension.type_parser("1") == 1
    assert argutils.CanvasDimension.type_parser("-1") == -1


@pytest.mark.parametrize("arg", ["-2", "a", "1.1"])
def test_canvas_dimensions_invalid_dimension(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.CanvasDimension.type_parser(arg)


def test_terminal_dimension_valid_dimension():
    assert argutils.TerminalDimension.type_parser("0") == 0
    assert argutils.TerminalDimension.type_parser("1") == 1


@pytest.mark.parametrize("arg", ["a", "1.1", "-1"])
def test_terminal_dimension_invalid_dimension(arg):
    with pytest.raises(ArgumentTypeError):
        argutils.TerminalDimension.type_parser(arg)


def test_ease_valid_ease():
    assert argutils.Ease.type_parser("linear") == easing.linear
    assert argutils.Ease.type_parser("in_sine") == easing.in_sine


def test_ease_invalid_ease():
    with pytest.raises(ArgumentTypeError):
        argutils.Ease.type_parser("invalid")