1 | #!/usr/bin/env python2
|
2 | """
|
3 | mylib_test.py: Tests for mylib.py
|
4 | """
|
5 | from __future__ import print_function
|
6 |
|
7 | import unittest
|
8 |
|
9 | from mycpp import mylib # module under test
|
10 |
|
11 |
|
12 | class MylibTest(unittest.TestCase):
|
13 |
|
14 | def testSplit(self):
|
15 | self.assertEqual(('foo', None), mylib.split_once('foo', '='))
|
16 | self.assertEqual(('foo', ''), mylib.split_once('foo=', '='))
|
17 | self.assertEqual(('foo', 'bar'), mylib.split_once('foo=bar', '='))
|
18 |
|
19 | def testFile(self):
|
20 | return
|
21 | stdout = mylib.File(1)
|
22 | stderr = mylib.File(2)
|
23 |
|
24 | stdout.write('stdout ')
|
25 | stdout.writeln('stdout')
|
26 |
|
27 | stderr.write('stderr ')
|
28 | stderr.writeln('stderr ')
|
29 |
|
30 | def testUniqueObjects(self):
|
31 | u = mylib.UniqueObjects()
|
32 |
|
33 | foo = 'foo'
|
34 | bar = 'bar'
|
35 | d = {}
|
36 |
|
37 | u.Add(foo)
|
38 | u.Add(bar)
|
39 | u.Add(d)
|
40 |
|
41 | self.assertEqual(0, u.Get(foo))
|
42 | self.assertEqual(1, u.Get(bar))
|
43 | self.assertEqual(2, u.Get(d))
|
44 | self.assertEqual(-1, u.Get('zzz'))
|
45 |
|
46 | # Can't add it twice, caller is responsible for checking
|
47 | try:
|
48 | u.Add(foo)
|
49 | except AssertionError:
|
50 | pass
|
51 | else:
|
52 | self.fail('Expected assertion')
|
53 |
|
54 |
|
55 | if __name__ == '__main__':
|
56 | unittest.main()
|