9c8fb13681d7eb5f9b2f02560080d7d090793b2a
[pyelftools.git] / test / test_py3compat.py
1 #-------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Eli Bendersky (eliben@gmail.com)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
7 import unittest
8
9 from elftools.common.py3compat import (iterbytes, iterkeys, itervalues,
10 iteritems)
11
12
13 class TestPy3Compat(unittest.TestCase):
14 def test_iterbytes(self):
15 bi = iterbytes(b'fo1')
16 self.assertEqual(next(bi), b'f')
17 self.assertEqual(next(bi), b'o')
18 self.assertEqual(next(bi), b'1')
19 with self.assertRaises(StopIteration):
20 next(bi)
21
22 def test_iterdict(self):
23 d = {1: 'foo', 2: 'bar'}
24 self.assertEqual(list(sorted(iterkeys(d))), [1, 2])
25 self.assertEqual(list(sorted(itervalues(d))), ['bar', 'foo'])
26 self.assertEqual(list(sorted(iteritems(d))), [(1, 'foo'), (2, 'bar')])
27
28
29 if __name__ == '__main__':
30 unittest.main()