File: test_py3compat.py

package info (click to toggle)
python-pyelftools 0.29-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 64,480 kB
  • sloc: python: 14,475; ansic: 184; asm: 86; makefile: 22; cpp: 18
file content (30 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download | duplicates (3)
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
#-------------------------------------------------------------------------------
# elftools tests
#
# Eli Bendersky (eliben@gmail.com)
# This code is in the public domain
#-------------------------------------------------------------------------------
import unittest

from elftools.common.py3compat import (iterbytes, iterkeys, itervalues,
                                       iteritems)


class TestPy3Compat(unittest.TestCase):
    def test_iterbytes(self):
        bi = iterbytes(b'fo1')
        self.assertEqual(next(bi), b'f')
        self.assertEqual(next(bi), b'o')
        self.assertEqual(next(bi), b'1')
        with self.assertRaises(StopIteration):
            next(bi)

    def test_iterdict(self):
        d = {1: 'foo', 2: 'bar'}
        self.assertEqual(list(sorted(iterkeys(d))), [1, 2])
        self.assertEqual(list(sorted(itervalues(d))), ['bar', 'foo'])
        self.assertEqual(list(sorted(iteritems(d))), [(1, 'foo'), (2, 'bar')])


if __name__ == '__main__':
    unittest.main()