summaryrefslogtreecommitdiff
path: root/test/genbuiltins.py
blob: c1a433f94376204c38cc99e4924967daeed5a4ba (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from os import remove
from glob import glob

code = """
import os

def function():
   retval = %s
   os.write(2, str(retval) + '\\n')

def entry_point(argv):
    function()
    return 0

def target(*args):
    return entry_point, None
"""

msg = "E:  5:function: Using unavailable builtin '%s'"

checks = [
    'set([1, 2, 3])', 'frozenset()',
    'dict()', 'unicode("f")', "complex(3, 4)",
    'file("foo.txt")', 'open("foo.txt")',

    'super(str)', 'object()', 
    
    'raw_input()', 'input()', 'buffer()', 
    
    'vars()', 'locals()', 'globals()', 'dir()',
    
    'getattr(function, "bar")', 'delattr(function, "bar")', 'setattr(function, "bar", "baz")',
    'staticmethod(function)', 'classmethod(function)', 'property(function)',
    
    "reduce(function, [])", "filter(function, [])", 'map(function, [])', 
    'sum(xrange(4))', 'enumerate(range(5))', 
    'sorted(range(5))', 'reversed(range(5))',

    'callable(function)', 'issubclass(function, str)',
    
    'reload(module)',

    'eval("a == b")', 'compile("a==b", "?", "eval")', 'execfile("foo.py")',
    
    'id(function)', 'help(function)',
    
    'intern("foo")',  'round(3.4)', 'iter([])',
    ]


for filename in glob('rpythoninput/func_nobuiltin_*'):
    remove(filename)
for filename in glob('rpythonmessages/func_nobuiltin_*'):
    remove(filename)    
for check in checks:
    builtin, _ = check.split('(', 1)
    if builtin == 'isinstance':
        builtin = 'basestring'
    basename = 'func_nobuiltin_%s' % builtin
    print basename
    file('rpythoninput/%s.py' % basename, 'w').write(code % check)
    file('rpythonmessages/%s.txt' % basename, 'w').write(msg % builtin)
print 'generated %s test' % len(checks)