Debian Codegraph @

rpython/rlib/unicodedata/test/test_codegen.py

raw symbols SCIP
1 import pytest
2 from StringIO import StringIO
3 from hypothesis import given, strategies, example
4
5 from rpython.rlib.unicodedata.codegen import CodeWriter, get_char_list_offset
6
7 def test_charlist():
8 l = []
9 d = {}
10 offset = get_char_list_offset([1, 2, 3], l, d)
11 assert offset == 0
12 assert l == [1, 2, 3]
13 assert d == {(1, ): 0, (2, ): 1, (3, ): 2, (1, 2): 0,
14 (2, 3): 1, (1, 2, 3): 0}
15
16 @example(l=[0, 1])
17 @given(strategies.lists(strategies.integers(min_value=0, max_value=2*32-1)))
18 def test_print_listlike(l):
19 f = StringIO()
20 c = CodeWriter(f)
21 print >> c, 'from rpython.rlib.rarithmetic import r_longlong, r_int32, r_uint32, intmask'
22 print >> c, '''\
23 from rpython.rlib.unicodedata.supportcode import (signed_ord, _all_short,
24 _all_ushort, _all_int32, _all_uint32)'''
25 c.print_listlike("l", l)
26 d = {}
27 s = f.getvalue()
28 print l
29 print s
30 exec s in d
31 func = d['l']
32 for i, value in enumerate(l):
33 assert func(i) == value
34 for index in range(len(l), len(l) + 100):
35 with pytest.raises((IndexError, KeyError)):
36 func(index)
37