Ejemplo n.º 1
0
func Raise(err error) {

	var val *C.PyObject
	var exc = C.PyExc_Exception

	e, ok := err.(*Error)
	if ok {
		exc = e.Kind.c()
		val = e.Value.c()
	} else {
		v := NewString(errors.Detail(err))
		val = v.c()
		defer C.decref(val)
	}
	C.PyErr_SetObject(exc, val)
}
Ejemplo n.º 2
0
func TestCall(t *testing.T) {

	log.SetOutputLevel(0)

	for _, c := range g_moduleCases {
		code, err := py.Compile(c.exp, "", py.FileInput)
		if err != nil {
			t.Fatal("Compile failed:", err)
		}
		defer code.Decref()

		mod, err := py.ExecCodeModule(c.name, code.Obj())
		if err != nil {
			t.Fatal("ExecCodeModule failed:", err)
		}
		defer mod.Decref()

		plg, err := New(mod.Obj(), "Plugin")
		if err != nil {
			t.Fatal("NewPlugin failed:", errors.Detail(err))
		}

		ret, err := CallMethod(plg, "init", "_stage")
		if err != nil {
			t.Fatal("CallMethod failed:", err)
		}
		defer ret.Decref()

		if ret.String() != c.ret {
			t.Fatal("CallMethod ret:", ret.String(), c.ret)
		}

		tbl, _ := plg.GetAttrString("tbl")
		if tbl.String() != c.tbl {
			t.Fatal("mod.GetAttrString('tbl') ret:", tbl.String(), c.tbl)
		}
	}
}