本文整理汇总了Python中pycket.test.testhelper.run_mod函数的典型用法代码示例。如果您正苦于以下问题:Python run_mod函数的具体用法?Python run_mod怎么用?Python run_mod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run_mod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flvector_set_wrong_type
def test_flvector_set_wrong_type():
with pytest.raises(SchemeException):
run_mod("""
#lang pycket
(require '#%flfxnum '#%unsafe)
(let [(a (flvector 1.2 1.3))] (flvector-set! a 1 'a))
""")
示例2: test_use_before_definition
def test_use_before_definition():
with pytest.raises(SchemeException):
m = run_mod("""
#lang pycket
x
(define x 1)
""")
with pytest.raises(SchemeException):
m = run_mod("""
#lang pycket
x
(define x 1)
(set! x 2)
""")
示例3: test_with_continuation_mark3
def test_with_continuation_mark3():
m = run_mod(
"""
#lang racket/base
(define a 1)
(set! a 2)
(define result
(let* ([extract
(lambda (k) (continuation-mark-set->list
(continuation-marks k)
'x))]
[go
(lambda (in?)
(lambda ()
(let ([k (with-continuation-mark 'x 10
(begin0
(with-continuation-mark 'x 11
(call/cc
(lambda (k )
(with-continuation-mark 'x 12
(if in?
(extract k)
k)))))
(+ a 3)))])
(if in?
k
(extract k)))))])
((go #t))))
(define valid (equal? result '(11 10)))
"""
)
sym = W_Symbol.make("valid")
assert m.defs[sym] is w_true
示例4: test_set_mod_other
def test_set_mod_other():
m = run_mod("""
#lang pycket
(require pycket/set-export)
(define y (not x))
""")
assert m.defs[W_Symbol.make("y")]
示例5: test_module_star
def test_module_star():
m = run_mod(
"""
#lang pycket
(module outer pycket
(define a 1)
(module* inner #f
(provide b)
(define b (+ a 2))))
(module snd pycket
(require (submod ".." outer inner))
(provide c)
(define c (+ b 1)))
(require (submod "." snd))
(define d c)
""")
assert len(m.submodules) == 2
outer = m.find_submodule("outer")
snd = m.find_submodule("snd")
assert outer.parent is m
assert snd.parent is m
assert len(outer.submodules) == 1
assert len(snd.submodules) == 0
d = m.defs[W_Symbol.make("d")]
assert isinstance(d, W_Integer) and d.value == 4
示例6: test_set_mod2
def test_set_mod2():
m = run_mod("""
#lang pycket
(provide table)
(define table #f)
(set! table #f)
""")
ov = m.defs[W_Symbol.make("table")]
assert isinstance(ov, W_Cell)
示例7: test_kw_submodule
def test_kw_submodule():
# Just test to see if this runs.
# It caused quite a few problems
# when implementing submodules.
m = run_mod(
"""
#lang pycket
(require racket/private/kw)
procedure-arity-includes?
""")
示例8: test_string_set_bang
def test_string_set_bang():
m = run_mod(
"""
#lang pycket
(define str (substring "hello world" 0 5))
(string-set! str 0 #\\x)
""")
sym = W_Symbol.make("str")
res = m.defs[sym]
assert isinstance(res, W_String)
assert not res.immutable()
assert res.value == "xello"
示例9: test_shadowing_macro
def test_shadowing_macro():
m = run_mod("""
#lang pycket
(define-syntax bind+
(syntax-rules ()
[(bind+ v e) (let ([x v]) (+ x e))]
[(bind+ v0 v ... e) (let ([x v0]) (bind+ v ... (+ x e)))]))
(define x (bind+ 1 2 3))
""")
ov = m.defs[W_Symbol.make("x")]
assert ov.value == 6
示例10: test_hash_iteration_enables_jitting
def test_hash_iteration_enables_jitting(source):
"""
#lang pycket
(define h #hash((1 . 2) (2 . 3) (3 . 4)))
(define (fe c v) '())
(define (fm c v) '())
(hash-for-each h fe)
(hash-map h fm)
"""
mod = run_mod(source)
f = mod.defs[values.W_Symbol.make('fe')]
assert f.closure.caselam.lams[0].body[0].should_enter
f = mod.defs[values.W_Symbol.make('fm')]
assert f.closure.caselam.lams[0].body[0].should_enter
示例11: test_let_remove_num_envs_edge_case
def test_let_remove_num_envs_edge_case():
m = run_mod(
"""
#lang pycket
(define d
(let-values (((es) values))
(let-values (((adj) '0))
(let-values ((() (es)))
adj))))
""")
d = W_Symbol.make("d")
assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 0
m = run_mod(
"""
#lang pycket
(define d
(let-values (((es) '0))
(let-values (((adj) '1))
(let-values (((a b c) (begin es (values '2 '3 '4))))
(+ adj a)))))
""")
assert type(m.defs[d]) is W_Fixnum and m.defs[d].value == 3
示例12: test_with_continuation_mark
def test_with_continuation_mark():
m = run_mod(
"""
#lang pycket
(define key (make-continuation-mark-key))
(define result
(with-continuation-mark key "quiche"
(with-continuation-mark key "ham"
(continuation-mark-set-first
(current-continuation-marks)
key))))
""")
sym = W_Symbol.make("result")
assert isinstance(m.defs[sym], values_string.W_String)
assert m.defs[sym].as_str_utf8() == "ham"
示例13: test_set_modvar
def test_set_modvar():
m = run_mod("""
#lang pycket
(define sum 0)
(define (tail-rec-aux i n)
(if (< i n)
(begin (set! sum (+ sum 1)) (tail-rec-aux (+ i 1) n))
sum))
(tail-rec-aux 0 100)
""")
ov = m.defs[W_Symbol.make("sum")].get_val()
assert ov.value == 100
示例14: test_with_continuation_mark_impersonator
def test_with_continuation_mark_impersonator():
m = run_mod(
"""
#lang pycket
(define mark-key
(impersonate-continuation-mark-key
(make-continuation-mark-key)
(lambda (l) (car l))
(lambda (s) (string->list s))))
(define result
(with-continuation-mark mark-key "quiche"
(continuation-mark-set-first
(current-continuation-marks)
mark-key)))
""")
sym = W_Symbol.make("result")
assert isinstance(m.defs[sym], W_Character)
assert m.defs[sym].value == 'q'
示例15: test_impersonator_application_mark
def test_impersonator_application_mark():
m = run_mod(
"""
#lang pycket
(require racket/private/kw)
(define key (make-continuation-mark-key))
(define proc
(lambda ()
(continuation-mark-set-first
(current-continuation-marks)
key)))
(define wrapped
(impersonate-procedure proc (lambda () (values))
impersonator-prop:application-mark (cons key 42)))
(define result (wrapped))
""")
sym = W_Symbol.make("result")
assert isinstance(m.defs[sym], W_Fixnum)
assert m.defs[sym].value == 42