-
Notifications
You must be signed in to change notification settings - Fork 191
/
test_fix_unicode_mapper.py
51 lines (39 loc) · 1.38 KB
/
test_fix_unicode_mapper.py
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
import unittest
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.fix_unicode_mapper import FixUnicodeMapper
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class FixUnicodeMapperTest(DataJuicerTestCaseBase):
def setUp(self):
self.op = FixUnicodeMapper()
def _run_fix_unicode(self, samples):
dataset = Dataset.from_list(samples)
dataset = dataset.map(self.op.process, batch_size=2)
for data in dataset:
self.assertEqual(data['text'], data['target'])
def test_bad_unicode_text(self):
samples = [
{
'text': '✔ No problems',
'target': '✔ No problems'
},
{
'text':
'The Mona Lisa doesn’t have eyebrows.',
'target': 'The Mona Lisa doesn\'t have eyebrows.'
},
]
self._run_fix_unicode(samples)
def test_good_unicode_text(self):
samples = [
{
'text': 'No problems',
'target': 'No problems'
},
{
'text': '阿里巴巴',
'target': '阿里巴巴'
},
]
self._run_fix_unicode(samples)
if __name__ == '__main__':
unittest.main()