Beispiel #1
0
def t_parse(s,ex=''):
    r = ''
    tokens = tokenize.tokenize(s)
    tree = parse.parse(s,tokens)
    r = t_lisp(tree)
    #print(s); print(ex); print(r)
    assert(r==ex)
Beispiel #2
0
def t_render(ss,ex,exact=True):
    if not is_tinypy:
        #ss = ss.encode('latin1')
        ex = ex.encode('latin1')
    if not istype(ss,'list'): ss =[ss]
    n = 1
    for s in ss:
        fname = 'tmp'+str(n)+'.tpc'
        system_rm(fname)
        tokens = tokenize.tokenize(s)
        t = parse.parse(s,tokens)
        r = encode.encode(fname,s,t)
        f = save(fname,r)
        n += 1
    system_rm('tmp.txt')
    cmd = VM + fname + " > tmp.txt"
    system(cmd)
    res = load(TMP).strip()
    
    #print(ss,ex,res)
    if exact:
        if res != ex: showerror(cmd, ss, ex, res)
        assert(res == ex)
    else: 
        if ex not in res: showerror(cmd, ss, ex, res)
        assert(ex in res)
Beispiel #3
0
def t_unparse(s):
    ok = False
    try:
        tokens = tokenize.tokenize(s)
        tree = parse.parse(s,tokens)
    except:
        ok = True
    assert(ok == True)
Beispiel #4
0
def t_unrender(s):
    ok = False
    try:
        tokens = tokenize.tokenize(s)
        t = parse.parse(s,tokens)
        r = encode.encode('tmp.tpc',s,t)
    except:
        ok = True
    assert(ok == True)
Beispiel #5
0
def compile(s, fname):
    tokens = tokenize.tokenize(s)
    t = parse.parse(s, tokens)
    r = encode.encode(fname, s, t)
    return r
Beispiel #6
0
def t_tokenize(s,exp=''):
    result = tokenize.tokenize(s)
    res = ' '.join([t_show(t) for t in result])
    #print(s); print(exp); print(res)
    assert(res == exp)