File size: 1,122 Bytes
0b4516f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Copyright (c) OpenMMLab. All rights reserved.
import json
from unittest import TestCase

from mmocr.utils import LineJsonParser, LineStrParser


class TestParser(TestCase):

    def test_line_json_parser(self):
        parser = LineJsonParser()
        line = json.dumps(dict(filename='test.jpg', text='mmocr'))
        data = parser(line)
        self.assertEqual(data['filename'], 'test.jpg')
        self.assertEqual(data['text'], 'mmocr')

    def test_line_str_parser(self):
        parser = LineStrParser()
        line = 'test.jpg mmocr'
        data = parser(line)
        self.assertEqual(data['filename'], 'test.jpg')
        self.assertEqual(data['text'], 'mmocr')

        # warnings
        line = 'test test test'
        msg = 'More than two blank spaces were detected. '
        msg += 'Please use LineJsonParser to handle '
        msg += 'annotations with blanks. '
        msg += 'Check Doc '
        msg += 'https://mmocr.readthedocs.io/en/latest/'
        msg += 'tutorials/blank_recog.html '
        msg += 'for details.'
        data = parser(line)
        self.assertWarnsRegex(UserWarning, msg)