File size: 1,228 Bytes
2366e36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) OpenMMLab. All rights reserved.
import pytest

from mmocr.utils import StringStrip


def test_string_strip():
    strip_list = [True, False]
    strip_pos_list = ['both', 'left', 'right']
    strip_str_list = [None, ' ']

    in_str_list = [
        ' hello ', 'hello ', ' hello', ' hello', 'hello ', 'hello ', 'hello',
        'hello', 'hello', 'hello', 'hello', 'hello'
    ]
    out_str_list = [
        'hello', 'hello', 'hello', 'hello', 'hello', 'hello', 'hello', 'hello',
        'hello', 'hello', 'hello', 'hello'
    ]

    for idx1, strip in enumerate(strip_list):
        for idx2, strip_pos in enumerate(strip_pos_list):
            for idx3, strip_str in enumerate(strip_str_list):
                tmp_args = dict(
                    strip=strip, strip_pos=strip_pos, strip_str=strip_str)
                strip_class = StringStrip(**tmp_args)
                i = idx1 * len(strip_pos_list) * len(
                    strip_str_list) + idx2 * len(strip_str_list) + idx3

                assert strip_class(in_str_list[i]) == out_str_list[i]

    with pytest.raises(AssertionError):
        StringStrip(strip='strip')
        StringStrip(strip_pos='head')
        StringStrip(strip_str=['\n', '\t'])