-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_capture.py
59 lines (44 loc) · 2.05 KB
/
test_capture.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
52
53
54
55
56
57
58
59
import unittest
from context import *
class TestCapture(unittest.TestCase):
def assert_capture(self, pattern, expected):
input = 'Target'
outputs = ('First', 'Second',)
s = txf.Sequence(None, input, 1000)
s = txf.Limit(s, 100)
s = txf.Cast(s, input, str)
t = txf.Capture(s, input, outputs, pattern)
self.assertEqual('capture', t.name, )
self.assertEqual(s, t.source)
self.assertEqual((input,), t.inputs)
self.assertEqual(outputs, t.outputs)
self.assertEqual(input, t.input)
self.assertEqual(pattern, t.pattern)
schema = t.schema
self.assertFalse(input in schema)
for output in outputs:
self.assertEqual(s.schema[input], schema[output])
actual = 0
for row in t:
if row[outputs[1]]: actual += 1
self.assertEqual(expected, actual)
return t
def test_capture_none(self):
self.assert_capture(r'(\s+)(\w+)', 0)
def test_capture_all(self):
self.assert_capture(r'(\d)(\d+)', 100)
def test_capture_some(self):
self.assert_capture(r'(\d+)(0)$', 10)
def test_root(self):
self.assertRaises(txf.TransformException, txf.Capture, None, 'Target', ('First', 'Second',), r'\w+')
def test_missing(self):
s = txf.Add(None, 'Target', '1234')
self.assertRaises(txf.TransformException, txf.Capture, s, 'Missing', ('First', 'Second',), r'\w+')
def test_overwrite(self):
s = txf.Add(None, ('Target', 'Bystander',), ('1234', 1234,))
self.assertRaises(txf.TransformException, txf.Capture, s, 'Target', ('First', 'Bystander',), r'\w+')
self.assertRaises(txf.TransformException, txf.Capture, s, 'Target', ('Bystander', 'Second',), r'\w+')
def test_group_count(self):
s = txf.Add(None, 'Target', '1234')
self.assertRaises(txf.TransformException, txf.Capture, s, 'Target', ('First', 'Second',), r'(\w+)')
self.assertRaises(txf.TransformException, txf.Capture, s, 'Target', ('First', 'Second',), r'(\w+) (\w+) (\w+)')