File: test_support.py

package info (click to toggle)
pypy 5.6.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 97,040 kB
  • ctags: 185,069
  • sloc: python: 1,147,862; ansic: 49,642; cpp: 5,245; asm: 5,169; makefile: 529; sh: 481; xml: 232; lisp: 45
file content (39 lines) | stat: -rw-r--r-- 1,327 bytes parent folder | download | duplicates (4)
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
38
39
import random
from rpython.translator.c.support import gen_assignments


def test_gen_simple_assignments():
    yield gen_check, [('int @', 'a', 'a')]
    yield gen_check, [('int @', 'a', 'b')]
    yield gen_check, [('int @', 'a', 'b'),
                      ('int @', 'c', 'b')]
    yield gen_check, [('int @', 'a', 'b'),
                      ('int @', 'b', 'c')]
    yield gen_check, [('int @', 'b', 'c'),
                      ('int @', 'a', 'b')]
    yield gen_check, [('int @', 'a', 'b'),
                      ('int @', 'b', 'a')]
    yield gen_check, [('int @', 'a', 'b'),
                      ('int @', 'b', 'c'),
                      ('int @', 'd', 'b')]

def gen_check(input):
    for _, dst, src in input:
        print 'input:', dst, src
    result = ' '.join(gen_assignments(input))
    print result
    result = result.replace('{ int', '').replace('}', '').strip()
    d = {}
    for _, dst, src in input:
        d[src] = '<value of %s>' % (src,)
    exec result in d
    for _, dst, src in input:
        assert d[dst] == '<value of %s>' % (src,)

def test_gen_check():
    varlist = list('abcdefg')
    for i in range(100):
        random.shuffle(varlist)
        input = [('int @', varlist[n], random.choice(varlist))
                 for n in range(random.randrange(1, 7))]
        yield gen_check, input