def testAnnotateInferenceProgramErrorInDefinition():
    ripl = get_ripl(persistent_inference_trace=True)
    err.assert_error_message_contains(
        """\
(observe (normal 0 1) (add 1 foo))
                             ^^^
""", ripl.define, "badness", "(observe (normal 0 1) (+ 1 foo))")
Exemplo n.º 2
0
def testAssertSmoke2():
    err.assert_error_message_contains(
        """\
(run (assert false))
^^^^^^^^^^^^^^^^^^^^
""",
        get_ripl().infer, "(assert false)")
def testAnnotateInferenceProgramError():
    ripl = get_ripl()
    err.assert_error_message_contains(
        """\
(run (observe (normal 0 1) (add 1 foo)))
                                  ^^^
""", ripl.infer, "(observe (normal 0 1) (+ 1 foo))")
def testAnnotateErrorInEvaluate():
    ripl = get_ripl()
    err.assert_error_message_contains(
        """\
(autorun (badness))
          ^^^^^^^
""", ripl.evaluate, "(badness)")
def testAnnotateDefinedInferenceProgramError():
    ripl = get_ripl(persistent_inference_trace=True)
    ripl.define("badness", "(lambda () (observe (normal 0 1) (+ 1 foo)))")
    err.assert_error_message_contains(
        """\
(run (badness))
     ^^^^^^^^^
(lambda () (observe (normal 0 1) (add 1 foo)))
                                        ^^^
""", ripl.infer, "(badness)")
Exemplo n.º 6
0
def testFixScope():
    ripl = get_ripl()
    assert_error_message_contains("Cannot find symbol 'x'",
                                  ripl.predict,
                                  """\
(let ((x 5))
  (letrec ((x x))
    x))
""",
                                  label="pid")
def testAnnotateErrorInListLookup():
    # Doubles as a regression test for Issue #510 (silent acceptance of
    # negative list indexes).
    ripl = get_ripl()
    err.assert_error_message_contains(
        """\
Index out of bounds -1.0
(autorun (lookup (list 2 3) -1))
         ^^^^^^^^^^^^^^^^^^^^^^
""", ripl.evaluate, "(lookup (list 2 3) -1)")
def testAnnotateErrorInMemmedProcedure():
    ripl = get_ripl()
    ripl.assume("f", "(mem (lambda () (normal (+ 1 badness) 1)))")
    err.assert_error_message_contains(
        """\
(f)
^^^
(mem (lambda () (normal (add 1 badness) 1)))
                               ^^^^^^^
""", ripl.predict, "(f)")
def testAnnotateInferenceErrorInImplicitQuasiquote():
    ripl = get_ripl()
    expression = """\
(assume x (normal ,(+ 1 badness) 1))
"""
    err.assert_error_message_contains(
        """\
(run (assume x (normal (unquote (add 1 badness)) 1)))
                                       ^^^^^^^
""", ripl.infer, expression)
def testAnnotateProgrammaticAssume():
    ripl = get_ripl()
    err.assert_error_message_contains(
        """\
(run (assume x (add 1 foo)))
     ^^^^^^^^^^^^^^^^^^^^^^
""", ripl.infer, "(assume x (+ 1 foo))")
    err.assert_error_message_contains("""\
(add 1.0 foo)
         ^^^
""", ripl.infer, "(assume x (+ 1 foo))")
def checkAnnotateModelProgramError(form):
    ripl = get_ripl()
    err.assert_error_message_contains(
        """\
(autorun %s)
         %s
Caused by
*** evaluation: Cannot find symbol 'foo'
foo
^^^
""" % (form, "^" * len(form)), ripl.evaluate, form)
def testAnnotateErrorInListLookup2():
    # Doubles as a regression test for Issue #510 (silent acceptance of
    # negative list indexes).
    ripl = get_ripl()
    # TODO Include the segment
    # (autorun (lookup (list 2 3) -1))
    #          ^^^^^^^^^^^^^^^^^^^^^^
    # once Issue #491 is fixed
    err.assert_error_message_contains("""\
Index out of bounds -1.0
""", ripl.sample, "(lookup (list 2 3) -1)")
def testAnnotateErrorTriggeredByInference():
    ripl = get_ripl()
    ripl.assume("control", "(flip)")
    ripl.force("control", True)
    ripl.predict("(if control 1 badness)")
    err.assert_error_message_contains(
        """\
(if control 1 badness)
^^^^^^^^^^^^^^^^^^^^^^
(if control 1 badness)
              ^^^^^^^
""", ripl.infer, "(mh default one 50)")
def testAnnotateInferenceErrorInQuasiquote():
    ripl = get_ripl()
    expression = """\
(inference_action (lambda (t) (pair (lookup `(,(+ 1 badness) 5) 0) t)))
"""
    err.assert_error_message_contains(
        """\
(run (inference_action (lambda (t) (pair (lookup (quasiquote ((unquote (add 1 badness)) 5)) 0) t))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(run (inference_action (lambda (t) (pair (lookup (quasiquote ((unquote (add 1 badness)) 5)) 0) t))))
                                                                              ^^^^^^^
""", ripl.infer, expression)
def testAnnotateErrorTriggeredByInferenceOverProgrammaticAssume():
    # Do not use the do macro yet
    ripl = get_ripl()
    ripl.infer("(assume control (flip))")
    ripl.infer("(force control true)")
    ripl.infer("(predict (if control 1 badness))")
    # TODO Solve the double macroexpansion problem
    err.assert_error_message_contains(
        """\
((biplex control (make_csp (quote ()) (quote 1.0)) (make_csp (quote ()) (quote badness))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
((biplex control (make_csp (quote ()) (quote 1.0)) (make_csp (quote ()) (quote badness))))
                                                                               ^^^^^^^
""", ripl.infer, "(mh default one 50)")
def testAnnotateInModelError():
    # Tests Github Issue #538.
    ripl = get_ripl()
    ripl.set_mode("venture_script")
    err.assert_error_message_contains(
        """\
*** evaluation: Nested ripl operation signalled an error
(autorun (in_model (run (new_model)) (action (run (sample (add foo 1))))))
                                                  ^^^^^^^^^^^^^^^^^^^^
Caused by
*** evaluation: Cannot find symbol 'foo'
(add foo 1.0)
     ^^^
""", ripl.evaluate, "in_model(run(new_model()), action(run(sample(foo + 1))))")
def testAnnotateInferenceErrorInDo():
    # TODO I need the inference trace to be persistent to trigger the
    # inference prelude did skipping hack :(
    ripl = get_ripl(persistent_inference_trace=True)
    expression = """\
(do (assume x (normal 0 1))
    (observe x (+ 1 badness)))"""
    err.assert_error_message_contains(
        """\
(run (do (assume x (normal 0 1)) (observe x (add 1 badness))))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(run (do (assume x (normal 0 1)) (observe x (add 1 badness))))
                                                   ^^^^^^^
""", ripl.infer, expression)
def testAnnotateInferenceErrorInDefinedDo():
    ripl = get_ripl(persistent_inference_trace=True)
    ripl.define(
        "act", """\
(do (assume x (normal 0 1))
    (y <- (sample x))
    (observe x (+ 1 badness)))""")
    err.assert_error_message_contains(
        """\
(run act)
^^^^^^^^^
(do (assume x (normal 0 1)) (y <- (sample x)) (observe x (add 1 badness)))
                                                                ^^^^^^^
""", ripl.infer, "act")
def testAnnotateDefinedProgrammaticAssume():
    ripl = get_ripl(persistent_inference_trace=True)
    ripl.define("act", "(lambda () (assume x (+ 1 foo)))")
    # Hm.  Blaming makers of inference actions rather than the actions
    # themselves produces this; which does point to the culprit.
    # However, the top stack frame is somewhat misleading as to when the
    # problem was identified.  I might be able to live with that.
    err.assert_error_message_contains(
        """\
(run (act))
     ^^^^^
(lambda () (assume x (add 1 foo)))
           ^^^^^^^^^^^^^^^^^^^^^^
""", ripl.infer, "(act)")
    err.assert_error_message_contains("""\
(add 1.0 foo)
         ^^^
""", ripl.infer, "(act)")
Exemplo n.º 20
0
def testPluginsLoadFail():
    r = get_ripl(extra_search_paths=[this_dir])
    assert len(r.search_paths) == 3
    err.assert_error_message_contains(
        "Plugin frob.py not found in any of %s" % r.search_paths, r.infer,
        '(load_plugin "frob.py")')
def testBasicAnnotation2():
    ripl = get_ripl()
    err.assert_error_message_contains("""\
(add 1 foo)
       ^^^
""", ripl.assume, "x", "(+ 1 foo)")