From 60c9ab4c53955ee58bbb9c32fe6fd128407c00f3 Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Tue, 21 Sep 2021 23:54:55 +0200 Subject: [PATCH] Fix handlers for 'with' syntax in Transaction object --- src/runtime/python/pypgf.c | 2 ++ src/runtime/python/tests/test_transactions.py | 14 ++++++++------ src/runtime/python/transactions.c | 5 +++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c index 10fb5653d..6f2d7d7cd 100644 --- a/src/runtime/python/pypgf.c +++ b/src/runtime/python/pypgf.c @@ -330,6 +330,8 @@ static PyGetSetDef PGF_getseters[] = { }; static PyMemberDef PGF_members[] = { + // {"revision", T_PYSSIZET, offsetof(PGFObject, revision), READONLY, + // "the revision number of this PGF"}, {NULL} /* Sentinel */ }; diff --git a/src/runtime/python/tests/test_transactions.py b/src/runtime/python/tests/test_transactions.py index c2932fc90..20cf806ad 100644 --- a/src/runtime/python/tests/test_transactions.py +++ b/src/runtime/python/tests/test_transactions.py @@ -18,7 +18,9 @@ def gr2(gr1): return gr1 @pytest.fixture(scope="module") -def gr3(gr1): +def gr3(): + # TODO how to avoid reloading from file? + gr1 = readPGF("../haskell/tests/basic.pgf") with gr1.newTransaction("bar_branch") as t: t.createFunction("bar", ty, 0, prob), t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob) @@ -62,8 +64,8 @@ def test_extended_function_prob(gr2): # 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 +def test_branched_functions(gr3): + assert gr3.functions == ["bar", "c", "ind", "s", "z"] + +def test_branched_function_type(gr3): + assert gr3.functionType("bar") == ty diff --git a/src/runtime/python/transactions.c b/src/runtime/python/transactions.c index b6c5db408..62c0d2960 100644 --- a/src/runtime/python/transactions.c +++ b/src/runtime/python/transactions.c @@ -47,6 +47,7 @@ Transaction_commit(TransactionObject *self, PyObject *args) return NULL; } + pgf_free_revision(self->pgf->db, self->pgf->revision); self->pgf->revision = self->revision; Py_RETURN_TRUE; @@ -156,10 +157,10 @@ Transaction_dropCategory(TransactionObject *self, PyObject *args) Py_RETURN_NONE; } -static PyObject * +static TransactionObject * Transaction_enter(TransactionObject *self, PyObject *Py_UNUSED(ignored)) { - Py_RETURN_TRUE; + return self; } static PyObject *