mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Started adding support for 'with' construct, failing tests commented out
This commit is contained in:
@@ -16,6 +16,13 @@ def gr2(gr1):
|
|||||||
assert t.commit()
|
assert t.commit()
|
||||||
return gr1
|
return gr1
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def gr3(gr1):
|
||||||
|
with gr1.newTransaction() as t:
|
||||||
|
t.createFunction("bar", ty, 0, prob),
|
||||||
|
# t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob)
|
||||||
|
return gr1
|
||||||
|
|
||||||
# gr1
|
# gr1
|
||||||
|
|
||||||
def test_original_functions(gr1):
|
def test_original_functions(gr1):
|
||||||
@@ -48,3 +55,11 @@ def test_extended_function_type(gr2):
|
|||||||
|
|
||||||
# def test_extended_function_prob(gr2):
|
# def test_extended_function_prob(gr2):
|
||||||
# assert gr2.functionProbability("foo") == prob
|
# assert gr2.functionProbability("foo") == prob
|
||||||
|
|
||||||
|
# gr3
|
||||||
|
|
||||||
|
# def test_branched_functions(gr3):
|
||||||
|
# assert gr3.functions == ["bar", "c", "ind", "s", "z"]
|
||||||
|
#
|
||||||
|
# def test_branched_function_type(gr3):
|
||||||
|
# assert gr3.functionType("bar") == ty
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#define PY_SSIZE_T_CLEAN
|
#define PY_SSIZE_T_CLEAN
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
// #include <stdbool.h>
|
#include <structmember.h>
|
||||||
|
|
||||||
#include <pgf/pgf.h>
|
#include <pgf/pgf.h>
|
||||||
#include "./expr.h"
|
#include "./expr.h"
|
||||||
@@ -137,6 +137,40 @@ Transaction_dropCategory(TransactionObject *self, PyObject *args)
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
Transaction_enter(TransactionObject *self, PyObject *Py_UNUSED(ignored))
|
||||||
|
{
|
||||||
|
Py_RETURN_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
Transaction_exit(TransactionObject *self, PyObject *const *args, Py_ssize_t nargs)
|
||||||
|
{
|
||||||
|
// PyObject *exc_type = Py_None;
|
||||||
|
// PyObject *exc_value = Py_None;
|
||||||
|
// PyObject *exc_tb = Py_None;
|
||||||
|
|
||||||
|
// if (!_PyArg_CheckPositional("__exit__", nargs, 0, 3)) {
|
||||||
|
// Py_RETURN_FALSE;
|
||||||
|
// }
|
||||||
|
if (nargs < 1) {
|
||||||
|
goto skip_optional;
|
||||||
|
}
|
||||||
|
// exc_type = args[0];
|
||||||
|
// if (nargs < 2) {
|
||||||
|
// goto skip_optional;
|
||||||
|
// }
|
||||||
|
// exc_value = args[1];
|
||||||
|
// if (nargs < 3) {
|
||||||
|
// goto skip_optional;
|
||||||
|
// }
|
||||||
|
// exc_tb = args[2];
|
||||||
|
skip_optional:
|
||||||
|
// TODO check exception
|
||||||
|
|
||||||
|
return Transaction_commit(self, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
// static void
|
// static void
|
||||||
// Transaction_dealloc(PGFObject* self)
|
// Transaction_dealloc(PGFObject* self)
|
||||||
// {
|
// {
|
||||||
@@ -147,15 +181,23 @@ static PyGetSetDef Transaction_getseters[] = {
|
|||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
// static PyMemberDef Transaction_members[] = {
|
static PyMemberDef Transaction_members[] = {
|
||||||
// {NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
// };
|
};
|
||||||
|
|
||||||
static PyMethodDef Transaction_methods[] = {
|
static PyMethodDef Transaction_methods[] = {
|
||||||
{"commit", (PyCFunction)Transaction_commit, METH_VARARGS,
|
{"commit", (PyCFunction)Transaction_commit, METH_VARARGS,
|
||||||
"Commit transaction"
|
"Commit transaction"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{"__enter__", (PyCFunction)Transaction_enter, METH_NOARGS,
|
||||||
|
""
|
||||||
|
},
|
||||||
|
|
||||||
|
{"__exit__", (PyCFunction)(void(*)(void))Transaction_exit, METH_FASTCALL,
|
||||||
|
""
|
||||||
|
},
|
||||||
|
|
||||||
{"createFunction", (PyCFunction)Transaction_createFunction, METH_VARARGS,
|
{"createFunction", (PyCFunction)Transaction_createFunction, METH_VARARGS,
|
||||||
"Create function"
|
"Create function"
|
||||||
},
|
},
|
||||||
@@ -175,7 +217,7 @@ PyTypeObject pgf_TransactionType = {
|
|||||||
PyVarObject_HEAD_INIT(NULL, 0)
|
PyVarObject_HEAD_INIT(NULL, 0)
|
||||||
//0, /*ob_size*/
|
//0, /*ob_size*/
|
||||||
"pgf.Transaction", /*tp_name*/
|
"pgf.Transaction", /*tp_name*/
|
||||||
sizeof(PGFObject), /*tp_basicsize*/
|
sizeof(TransactionObject), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
0, //(destructor)Transaction_dealloc, /*tp_dealloc*/
|
0, //(destructor)Transaction_dealloc, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
@@ -193,7 +235,7 @@ PyTypeObject pgf_TransactionType = {
|
|||||||
0, /*tp_setattro*/
|
0, /*tp_setattro*/
|
||||||
0, /*tp_as_buffer*/
|
0, /*tp_as_buffer*/
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||||
"PGF transaction", /*tp_doc*/
|
"Transaction object", /*tp_doc*/
|
||||||
0, /*tp_traverse */
|
0, /*tp_traverse */
|
||||||
0, /*tp_clear */
|
0, /*tp_clear */
|
||||||
0, /*tp_richcompare */
|
0, /*tp_richcompare */
|
||||||
@@ -201,7 +243,7 @@ PyTypeObject pgf_TransactionType = {
|
|||||||
0, /*tp_iter */
|
0, /*tp_iter */
|
||||||
0, /*tp_iternext */
|
0, /*tp_iternext */
|
||||||
Transaction_methods, /*tp_methods */
|
Transaction_methods, /*tp_methods */
|
||||||
0, //Transaction_members, /*tp_members */
|
Transaction_members, /*tp_members */
|
||||||
Transaction_getseters, /*tp_getset */
|
Transaction_getseters, /*tp_getset */
|
||||||
0, /*tp_base */
|
0, /*tp_base */
|
||||||
0, /*tp_dict */
|
0, /*tp_dict */
|
||||||
|
|||||||
Reference in New Issue
Block a user