def define_foo_bar_env(): g = GlobalEnv() var_foo = g.eval_str("(define foo (env (quote ('foo 5)) (quote (3 7))))") var_foo2 = g.eval_str("(define foo2 (env (quote (foo 5)) (quote (3 7))))") var_bar = g.eval_str( "(define bar (env_anonymous (quote ('foo 5)) (quote (3 7))))") var_baz = g.eval_str( "(define bar/baz (env_anonymous (quote ('foo 5)) (quote (3 7))))") var_globalvar = g.eval_str("(define globalvar 55)") return g, (var_foo, var_foo2, var_bar, var_baz, var_globalvar)
def test_plugin(): g = GlobalEnv() assert g.eval_str("_Python") assert g.eval_str("(env? _Python)") g.eval_str("(_Python/import 'math)") assert callable(g.eval_str(" (_Python/get 'math.ceil)")) assert g.eval_str("((_Python/get 'math.ceil) 6.2)") == 7. assert g.eval_str("((_Python/get 'math.ceil) 6.7)") == 7.
def test_block_comment(): g = GlobalEnv() script = ''' (* 3 4) (quote (lkasdhj sdlh asdkh sadahjs )) (+ 2 3) ''' assert g.eval_str(script) == 5
def lisp_w_shell(): g = GlobalEnv() g.eval_str("(_Python/import 'plugin_shell)") return g
def redefine_foo_bar_env(): g = GlobalEnv() foo_env = g.eval_str("(define foo (env (quote (foo 5)) (quote (3 7))))") bar_env = g.eval_str("(define foo/bar (env))") mpt_env = g.eval_str("(define foo/stp/mpt/boo 600)") baz_var = g.eval_str("(define foo/bar/baz 55)") g.eval_str("(define foo/par (env (quote (3 21)) (quote (1 22))))") g.eval_str('(define foo/par/proc (lambda (x) (+ x 5)))') g.eval_str('(define foo/par/proc2 (lambda (x) (+ x scope_y)))') g.eval_str('(define foo/par/proc3 (lambda (x) (+ x /global_y)))') return g, (foo_env, bar_env, baz_var)
def define_foo(): g = GlobalEnv() g.eval_str("(define foo (env (quote (foo 5)) (quote (3 7))))") return g
def test_standard_missing_names(): g = GlobalEnv() assert callable(g.eval_str('_missing_handler')) assert g.eval_str('foo') is None
def test_set_none_for_missing_names(): g = GlobalEnv() g.eval_str('(define /_missing_handler (lambda (varname) 5))') assert g.eval_str('foo') == 5
import pytest from sym_lis import GlobalEnv l = GlobalEnv() # test macro l.eval_str('(define test equal?)') # not really a macro at all def test_pass(): assert l.eval_str('(test (+ 3 2) 5)') def test_notpass(): assert l.eval_str('(test (+ 3 2) 5)') # to test map l.eval_str('(define double (lambda (x) (* 2 x)))') l.eval_str('(define add (lambda (x y) (+ y x)))') def test_map(): assert all(a == b for a, b in zip(l.eval_str('(map double (list 1 2 3))'), [2 * i for i in [1, 2, 3]])) def test_map_tuples(): # this won't work #assert list(l.eval_str('(map add (quote ((1 2) (2 3))))')) == [3, 5]
def test_inline_annotate(): g = GlobalEnv() g.eval_str("(define baz (_note (quote (foo bar)) 5))") assert g.eval_str('baz') == 5 assert g.eval_str('baz').note == g.eval_str('(quote (foo bar))') assert g.eval_str("(+ (_note 'foo 2) 3)") == 5