From fc1274912415b1c47d8e73d5fd660b24e32ec22c Mon Sep 17 00:00:00 2001 From: "John J. Camilleri" Date: Fri, 24 Sep 2021 13:46:46 +0200 Subject: [PATCH] Complete transaction tests --- src/runtime/python/tests/test_transactions.py | 58 ++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/runtime/python/tests/test_transactions.py b/src/runtime/python/tests/test_transactions.py index 92808420e..72861db46 100644 --- a/src/runtime/python/tests/test_transactions.py +++ b/src/runtime/python/tests/test_transactions.py @@ -5,28 +5,54 @@ import math ty = readType("(N -> N) -> P (s z)") prob = math.pi -@pytest.fixture(scope="module") +@pytest.fixture(scope="function") def gr1(): gr = readPGF("../haskell/tests/basic.pgf") yield gr -@pytest.fixture(scope="module") -def gr2(): - gr = readPGF("../haskell/tests/basic.pgf") +@pytest.fixture(scope="function") +def gr2(gr1): + gr = gr1 t = gr.newTransaction() t.createFunction("foo", ty, 0, prob) t.createCategory("Q", [(BIND_TYPE_EXPLICIT, "x", ty)], prob) t.commit() yield gr -@pytest.fixture(scope="module") -def gr3(): - gr = readPGF("../haskell/tests/basic.pgf") +@pytest.fixture(scope="function") +def gr3(gr1): + gr = gr1 with gr.newTransaction("bar_branch") as t: t.createFunction("bar", ty, 0, prob) t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob) yield gr +@pytest.fixture(scope="function") +def gr4(gr2): + gr = gr2 + gr.checkoutBranch("master") + yield gr + +@pytest.fixture(scope="function") +def gr5(gr3): + gr = gr3 + gr.checkoutBranch("bar_branch") + yield gr + +@pytest.fixture(scope="function") +def gr6(gr1): + gr = gr1 + with gr.newTransaction() as t: + t.dropFunction("ind") + t.dropCategory("S") + yield gr + +# general + +def test_checkout_non_existant(gr1): + with pytest.raises(KeyError): + gr1.checkoutBranch("abc") + # gr1 def test_original_functions(gr1): @@ -71,8 +97,24 @@ def test_branched_functions(gr3): def test_branched_categories(gr3): assert gr3.categories == ["Float","Int","N","P","R","S","String"] -def test_extended_category_context(gr3): +def test_branched_category_context(gr3): assert gr3.categoryContext("R") == [(BIND_TYPE_EXPLICIT, "x", ty)] def test_branched_function_type(gr3): assert gr3.functionType("bar") == ty + +# gr4, 5 + +def test_branched_functions(gr4): + assert gr4.functions == ["c", "foo", "ind", "s", "z"] + +def test_branched_functions(gr5): + assert gr5.functions == ["bar", "c", "ind", "s", "z"] + +# gr6 + +def test_reduced_functions(gr6): + assert gr6.functions == ["c", "s", "z"] + +def test_reduced_categories(gr6): + assert gr6.categories == ["Float","Int","N","P","String"]