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
|
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""
import pytest
import typepy
from ._common import convert_wrapper
nan = float("nan")
inf = float("inf")
class Test_String:
@pytest.mark.parametrize(
["method", "strict_level", "value", "expected"],
[
["convert", 0, "abc", "abc"],
["convert", 0, "", ""],
["convert", 0, 1, "1"],
["convert", 0, "-1", "-1"],
["convert", 0, None, "None"],
["convert", 0, True, "True"],
["convert", 0, inf, "inf"],
["convert", 0, nan, "nan"],
["convert", 1, "abc", "abc"],
["convert", 1, "", ""],
["convert", 1, 1, "E"],
["convert", 1, "-1", "-1"],
["convert", 1, None, "E"],
["convert", 1, True, "E"],
["convert", 1, inf, "E"],
["convert", 1, nan, "E"],
["convert", 2, "abc", "abc"],
["convert", 2, "", "E"],
["convert", 2, 1, "E"],
["convert", 2, "-1", "-1"],
["convert", 2, None, "E"],
["convert", 2, True, "E"],
["convert", 2, inf, "E"],
["convert", 2, nan, "E"],
["try_convert", 0, "abc", "abc"],
["try_convert", 0, "", ""],
["try_convert", 0, 1, "1"],
["try_convert", 0, "-1", "-1"],
["try_convert", 0, None, "None"],
["try_convert", 0, True, "True"],
["try_convert", 0, inf, "inf"],
["try_convert", 0, nan, "nan"],
["try_convert", 1, "abc", "abc"],
["try_convert", 1, "", ""],
["try_convert", 1, 1, None],
["try_convert", 1, "-1", "-1"],
["try_convert", 1, None, None],
["try_convert", 1, True, None],
["try_convert", 1, inf, None],
["try_convert", 1, nan, None],
["try_convert", 2, "abc", "abc"],
["try_convert", 2, "", None],
["try_convert", 2, 1, None],
["try_convert", 2, "-1", "-1"],
["try_convert", 2, None, None],
["try_convert", 2, True, None],
["try_convert", 2, inf, None],
["try_convert", 2, nan, None],
["force_convert", 0, "abc", "abc"],
["force_convert", 0, "", ""],
["force_convert", 0, 1, "1"],
["force_convert", 0, "-1", "-1"],
["force_convert", 0, None, "None"],
["force_convert", 0, True, "True"],
["force_convert", 0, inf, "inf"],
["force_convert", 0, nan, "nan"],
["force_convert", 1, "abc", "abc"],
["force_convert", 1, "", ""],
["force_convert", 1, 1, "1"],
["force_convert", 1, "-1", "-1"],
["force_convert", 1, None, "None"],
["force_convert", 1, True, "True"],
["force_convert", 1, inf, "inf"],
["force_convert", 1, nan, "nan"],
["force_convert", 2, "abc", "abc"],
["force_convert", 2, "", ""],
["force_convert", 2, 1, "1"],
["force_convert", 2, "-1", "-1"],
["force_convert", 2, None, "None"],
["force_convert", 2, True, "True"],
["force_convert", 2, inf, "inf"],
["force_convert", 2, nan, "nan"],
],
)
def test_normal(self, method, strict_level, value, expected):
assert convert_wrapper(typepy.String(value, strict_level), method) == expected
class Test_NullString:
@pytest.mark.parametrize(
["method", "strict_level", "value", "expected"],
[
["convert", 0, "", ""],
["convert", 0, " ", " "],
["convert", 1, "", ""],
["convert", 1, " ", " "],
["convert", 2, "", ""],
["convert", 2, " ", " "],
["try_convert", 0, "", ""],
["try_convert", 0, " ", " "],
["try_convert", 1, "", ""],
["try_convert", 1, " ", " "],
["try_convert", 2, "", ""],
["try_convert", 2, " ", " "],
["force_convert", 0, "", ""],
["force_convert", 0, " ", " "],
["force_convert", 1, "", ""],
["force_convert", 1, " ", " "],
["force_convert", 2, "", ""],
["force_convert", 2, " ", " "],
],
)
def test_normal(self, method, strict_level, value, expected):
assert convert_wrapper(typepy.NullString(value, strict_level), method) == expected
|