File: test_codegen.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (37 lines) | stat: -rw-r--r-- 1,125 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
31
32
33
34
35
36
37
import pytest
from StringIO import StringIO
from hypothesis import given, strategies, example

from rpython.rlib.unicodedata.codegen import CodeWriter, get_char_list_offset

def test_charlist():
    l = []
    d = {}
    offset = get_char_list_offset([1, 2, 3], l, d)
    assert offset == 0
    assert l == [1, 2, 3]
    assert d == {(1, ): 0, (2, ): 1, (3, ): 2, (1, 2): 0,
                 (2, 3): 1, (1, 2, 3): 0}

@example(l=[0, 1])
@given(strategies.lists(strategies.integers(min_value=0, max_value=2*32-1)))
def test_print_listlike(l):
    f = StringIO()
    c = CodeWriter(f)
    print >> c, 'from rpython.rlib.rarithmetic import r_longlong, r_int32, r_uint32, intmask'
    print >> c, '''\
from rpython.rlib.unicodedata.supportcode import (signed_ord, _all_short,
    _all_ushort, _all_int32, _all_uint32)'''
    c.print_listlike("l", l)
    d = {}
    s = f.getvalue()
    print l
    print s
    exec s in d
    func = d['l']
    for i, value in enumerate(l):
        assert func(i) == value
    for index in range(len(l), len(l) + 100):
        with pytest.raises((IndexError, KeyError)):
            func(index)