annotate tests/test_split.py @ 52:8d8c1ac0e8e1

add a test text and wire some things up
author Jeff Hammel <k0scist@gmail.com>
date Sun, 17 May 2015 08:48:56 -0700
parents c3b69728f291
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
3
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
4 """
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
5 unit tests for `textshaper.split`
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
6 """
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
7
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
8 # imports
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
9 import unittest
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
10 from textshaper import split
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
11
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
12
51
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
13
48
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
14 class SplitUnitTest(unittest.TestCase):
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
15
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
16 def test_findall(self):
51
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
17 """test finding all substrings"""
48
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
18
49
Jeff Hammel <k0scist@gmail.com>
parents: 48
diff changeset
19 # 012345678901
Jeff Hammel <k0scist@gmail.com>
parents: 48
diff changeset
20 string = 'a cat, a bat'
48
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
21
49
Jeff Hammel <k0scist@gmail.com>
parents: 48
diff changeset
22 retval = split.findall(string, 'a')
50
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
23 self.assertEqual(retval, [0,3,7,10])
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
24
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
25 self.assertEqual(split.findall(string, 't'),
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
26 [4, 11])
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
27
51
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
28 def test_indices(self):
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
29 """test finding ordered indices"""
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
30 string = 'a cat, a bat'
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
31 indices = split.indices(string, ('a', 't'))
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
32 self.assertEqual(indices,
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
33 [(0, 'a'),
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
34 (3, 'a'),
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
35 (4, 't'),
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
36 (7, 'a'),
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
37 (10, 'a'),
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
38 (11, 't')])
c3b69728f291 finding indices now works
Jeff Hammel <k0scist@gmail.com>
parents: 50
diff changeset
39
50
1284c99a94fa stubbing
Jeff Hammel <k0scist@gmail.com>
parents: 49
diff changeset
40
48
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
41 if __name__ == '__main__':
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
42 unittest.main()
03ce88daa98d start test
Jeff Hammel <k0scist@gmail.com>
parents:
diff changeset
43