Merge branch 'majestic' of github.com:GrammaticalFramework/gf-core into majestic

This commit is contained in:
krangelov
2021-09-24 13:57:29 +02:00

View File

@@ -5,28 +5,54 @@ import math
ty = readType("(N -> N) -> P (s z)") ty = readType("(N -> N) -> P (s z)")
prob = math.pi prob = math.pi
@pytest.fixture(scope="module") @pytest.fixture(scope="function")
def gr1(): def gr1():
gr = readPGF("../haskell/tests/basic.pgf") gr = readPGF("../haskell/tests/basic.pgf")
yield gr yield gr
@pytest.fixture(scope="module") @pytest.fixture(scope="function")
def gr2(): def gr2(gr1):
gr = readPGF("../haskell/tests/basic.pgf") gr = gr1
t = gr.newTransaction() t = gr.newTransaction()
t.createFunction("foo", ty, 0, prob) t.createFunction("foo", ty, 0, prob)
t.createCategory("Q", [(BIND_TYPE_EXPLICIT, "x", ty)], prob) t.createCategory("Q", [(BIND_TYPE_EXPLICIT, "x", ty)], prob)
t.commit() t.commit()
yield gr yield gr
@pytest.fixture(scope="module") @pytest.fixture(scope="function")
def gr3(): def gr3(gr1):
gr = readPGF("../haskell/tests/basic.pgf") gr = gr1
with gr.newTransaction("bar_branch") as t: with gr.newTransaction("bar_branch") as t:
t.createFunction("bar", ty, 0, prob) t.createFunction("bar", ty, 0, prob)
t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob) t.createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], prob)
yield gr 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 # gr1
def test_original_functions(gr1): def test_original_functions(gr1):
@@ -71,8 +97,24 @@ def test_branched_functions(gr3):
def test_branched_categories(gr3): def test_branched_categories(gr3):
assert gr3.categories == ["Float","Int","N","P","R","S","String"] 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)] assert gr3.categoryContext("R") == [(BIND_TYPE_EXPLICIT, "x", ty)]
def test_branched_function_type(gr3): def test_branched_function_type(gr3):
assert gr3.functionType("bar") == ty 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"]