File: test_str_function.py

package info (click to toggle)
dataproperty 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 428 kB
  • sloc: python: 4,450; makefile: 51; sh: 5
file content (42 lines) | stat: -rw-r--r-- 1,162 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
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import itertools

import pytest

from dataproperty import calc_ascii_char_width


nan = float("nan")
inf = float("inf")


class Test_calc_ascii_char_width:
    @pytest.mark.parametrize(
        ["value", "expected"], [["吾輩は猫である", 14], ["いaろbはc", 9], ["abcdef", 6], ["", 0]]
    )
    def test_normal(self, value, expected):
        assert calc_ascii_char_width(value) == expected

    @pytest.mark.parametrize(
        ["value", "ambiguous_width"],
        itertools.product(["Ø", "α", "β", "γ", "θ", "κ", "λ", "π", "ǎ"], [1, 2]),
    )
    def test_normal_east_asian_ambiguous(self, value, ambiguous_width):
        assert calc_ascii_char_width(value, ambiguous_width) == ambiguous_width

    @pytest.mark.parametrize(
        ["value", "expected"],
        [
            [b"abcdef", TypeError],
            [None, TypeError],
            [True, TypeError],
            [1, TypeError],
            [nan, TypeError],
        ],
    )
    def test_exception(self, value, expected):
        with pytest.raises(expected):
            calc_ascii_char_width(value)