mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-17 16:59:34 -06:00
Add Transaction type to Python bindings, get first tests working.
This commit is contained in:
@@ -2,40 +2,49 @@ import pytest
|
||||
from pgf import *
|
||||
|
||||
ty = readType("(N -> N) -> P (s z)")
|
||||
pi = 3.142
|
||||
prob = 3.142
|
||||
|
||||
# @pytest.fixture(scope="module")
|
||||
# def gr1():
|
||||
# return pgf.readPGF("../haskell/tests/basic.pgf")
|
||||
#
|
||||
# @pytest.fixture(scope="module")
|
||||
# def gr2(gr1):
|
||||
# transaction = [
|
||||
# createFunction("foo", ty, 0, pi),
|
||||
# createCategory("Q", [(BIND_TYPE_EXPLICIT, "x", ty)], pi)
|
||||
# ]
|
||||
# return gr1.modifyPGF(transaction)
|
||||
#
|
||||
# @pytest.fixture(scope="module")
|
||||
# def gr3(gr1):
|
||||
# transaction = [
|
||||
# createFunction("bar", ty, 0, pi),
|
||||
# createCategory("R", [(BIND_TYPE_EXPLICIT, "x", ty)], pi)
|
||||
# ]
|
||||
# return gr1.branchPGF("bar_branch", transaction)
|
||||
#
|
||||
# def original_functions(gr1):
|
||||
# assert gr1.functions == ["c", "ind", "s", "z"]
|
||||
#
|
||||
# def extended_functions(gr2):
|
||||
# assert gr2.functions == ["c", "foo", "ind", "s", "z"]
|
||||
#
|
||||
# def branched_functions(gr3):
|
||||
# assert gr3.functions == ["bar", "c", "ind", "s", "z"]
|
||||
@pytest.fixture(scope="module")
|
||||
def gr1():
|
||||
return readPGF("../haskell/tests/basic.pgf")
|
||||
|
||||
def test_non_transactional():
|
||||
gr1 = readPGF("../haskell/tests/basic.pgf")
|
||||
@pytest.fixture(scope="module")
|
||||
def gr2(gr1):
|
||||
t = gr1.newTransaction()
|
||||
t.createFunction("foo", ty, 0, prob),
|
||||
# t.createCategory("Q", [(BIND_TYPE_EXPLICIT, "x", ty)], prob)
|
||||
assert t.commit()
|
||||
return gr1
|
||||
|
||||
# gr1
|
||||
|
||||
def test_original_functions(gr1):
|
||||
assert gr1.functions == ["c", "ind", "s", "z"]
|
||||
|
||||
gr1.createFunction("foo", ty, 0, pi)
|
||||
assert gr1.functions == ["c", "foo", "ind", "s", "z"]
|
||||
def test_original_categories(gr1):
|
||||
assert gr1.categories == ["Float","Int","N","P","S","String"]
|
||||
|
||||
def test_original_function_type(gr1):
|
||||
with pytest.raises(KeyError):
|
||||
gr1.functionType("foo")
|
||||
|
||||
# def test_original_function_prob(gr1):
|
||||
# with pytest.raises(KeyError):
|
||||
# gr1.functionProbability("foo")
|
||||
|
||||
# gr2
|
||||
|
||||
def test_extended_functions(gr2):
|
||||
assert gr2.functions == ["c", "foo", "ind", "s", "z"]
|
||||
|
||||
# def test_extended_categories(gr2):
|
||||
# assert gr2.categories == ["Float","Int","N","P","Q","S","String"]
|
||||
#
|
||||
# def test_extended_category_context(gr2):
|
||||
# assert gr2.categoryContext("Q") == [(BIND_TYPE_EXPLICIT, "x", ty)]
|
||||
|
||||
def test_extended_function_type(gr2):
|
||||
assert gr2.functionType("foo") == ty
|
||||
|
||||
# def test_extended_function_prob(gr2):
|
||||
# assert gr2.functionProbability("foo") == prob
|
||||
|
||||
Reference in New Issue
Block a user