def test_method(): """ Test of node method """ class Dummy: def __init__(self): self.tvalue = False def test(self, value=True): self.tvalue = value val = Dummy() res = run(('openalea.python method', 'method'), inputs={ 'obj': val, 'member_name': 'test' }, pm=pm) assert res[0] == val assert val.tvalue == True val.tvalue = False res = run(('openalea.python method', 'method'), inputs={ 'obj': val, 'member_name': 'test', 'args': (True, ) }, pm=pm) assert res[0] == val assert val.tvalue == True
def test_ifelse(): """ Test of node ifelse """ res = run(('openalea.python method', 'ifelse'),\ inputs={'c': True, 'a': 'a', 'b': 'b'}, pm=pm) assert res[0] == 'a' res = run(('openalea.python method', 'ifelse'),\ inputs={'c': False, 'a': 'a', 'b': 'b'}, pm=pm) assert res[0] == 'b'
def test_getitem(): """ Test of node getitem """ res = run(('openalea.python method', 'getitem'),\ inputs={'obj': {'a': 1, 'b': 2}, 'key': 'a'}, pm=pm) assert res[0] == 1 res = run(('openalea.python method', 'getitem'),\ inputs={'obj': range(10), 'key': 2}, pm=pm) assert res[0] == 2
def test_delitem(): """ Test of node delitem """ res = run(('openalea.python method', 'delitem'), inputs={'obj': {'a': 1, 'b': 2}, 'key': 'a'}, pm=pm) assert len(res[0]) == 1 res = run(('openalea.python method', 'delitem'), inputs={'obj': range(10), 'key': 2}, pm=pm) assert len(res[0]) == 9
def test_len(): """ Test of node len """ res = run(('openalea.python method', 'len'), inputs={'obj': {'a': 1, 'b': 2}}, pm=pm) assert res[0] == 2 res = run(('openalea.python method', 'len'), inputs={'obj': range(10)}, pm=pm) assert res[0] == 10
def test_setitem(): """ Test of node setitem """ res = run(('openalea.python method', 'setitem'), inputs={'obj': {'a': 1, 'b': 2}, 'key': 'c', 'value': 3}, pm=pm) assert len(res[0]) == 3 res = run(('openalea.python method', 'setitem'), inputs={'obj': range(10), 'key': 2, 'value': 3}, pm=pm) assert len(res[0]) == 10 assert res[0][2] == 3
def test_len(): """ Test of node len """ res = run(('openalea.python method', 'len'), inputs={'obj': { 'a': 1, 'b': 2 }}, pm=pm) assert res[0] == 2 res = run(('openalea.python method', 'len'), inputs={'obj': range(10)}, pm=pm) assert res[0] == 10
def test_caribu(): """ Test Tutorial LIE """ res = run(('alinea.caribu.demos', 'Tutorial'), inputs={}, vtx_id=11) efficiency = res[0] if efficiency: assert 0.62 < res[0] < 0.63, res
def test_eval(): """ Test of node eval """ val = 'True' res = run(('openalea.python method', 'eval'), inputs={'expression': val}, pm=pm) assert res[0] == True
def test_flatten(): """ Test of node flatten """ res = run( ('openalea.python method', 'flatten'), inputs={'obj': [(3 * i, 3 * i + 1, 3 * i + 2) for i in range(5)]}, pm=pm) assert len(res[0]) == 15 assert res[0] == range(15)
def binary_tst(opname, val1, val2, res=True, arg1name='a', arg2name='b'): """ Binary Test """ rres = run(('openalea.math', opname), \ inputs={arg1name: val1, arg2name: val2}, pm=pm) if rres[0] != res: raise ValueError("Bad result for operator '"\ +opname+"' with values "+str((val1, val2))\ +'. Expected '+str(res)+', Got '+str(rres[0])+'.')
def test_zip(): """ Test of node zip """ res = run(('openalea.python method', 'zip'), inputs={ 's1': range(10), 's2': range(10) }, pm=pm) assert res[0] == [(i, i) for i in range(10)]
def test_keys(): """ Test of node keys """ res = run(('openalea.python method', 'keys'), inputs={'obj': { 'a': 1, 'b': 2 }}, pm=pm) assert res[0] == ['a', 'b']
def test_values(): """ Test of node values """ res = run(('openalea.python method', 'values'), inputs={'obj': { 'a': 1, 'b': 2 }}, pm=pm) assert res[0] == [1, 2]
def function_tst(function_name, val1, res=True, arg1name='a'): """ Function test """ epsilon = 1e-15 rres = run(('openalea.math', function_name), inputs={arg1name: val1}, \ pm=pm) if (rres[0] - res) > epsilon: raise ValueError("Bad result for operator '"\ +function_name+"' with values "+str((val1))\ +'. Expected '+str(res)+', Got '+str(rres[0])+'.')
def test_items(): """ Test of node items """ res = run(('openalea.python method', 'items'), inputs={'obj': { 'a': 1, 'b': 2 }}, pm=pm) assert res[0] == [('a', 1), ('b', 2)]
def test4(): from openalea.core import alea from openalea.mtg.io import read_mtg_file fn = alea.run(('demo.mtg', 'agraf.mtg'), [])[0] g = read_mtg_file(fn) param = Quaking_Aspen() param.order = 2 wp = Weber_MTG(param, g) wp.run()
def test_delitem(): """ Test of node delitem """ res = run(('openalea.python method', 'delitem'), inputs={ 'obj': { 'a': 1, 'b': 2 }, 'key': 'a' }, pm=pm) assert len(res[0]) == 1 res = run(('openalea.python method', 'delitem'), inputs={ 'obj': range(10), 'key': 2 }, pm=pm) assert len(res[0]) == 9
def test_range(): """ Test of node range """ res = run(('openalea.python method', 'range'), inputs={ 'start': 0, 'stop': 10, 'step': 2 }, pm=pm) assert res[0] == range(0, 10, 2)
def test_method(): """ Test of node method """ class Dummy: def __init__(self): self.tvalue = False def test(self, value=True): self.tvalue = value val = Dummy() res = run(('openalea.python method', 'method'), inputs={'obj': val, 'member_name': 'test'}, pm=pm) assert res[0] == val assert val.tvalue == True val.tvalue = False res = run(('openalea.python method', 'method'), inputs={'obj': val, 'member_name': 'test', 'args': (True, )}, pm=pm) assert res[0] == val assert val.tvalue == True
def test_getattr(): """ Test of node getattr """ class Dummy: def __init__(self): self.tvalue = False val = Dummy() res = run(('openalea.python method', 'getattr'), inputs={'obj': val, 'member_name': 'tvalue'}, pm=pm) assert res[0] == val.tvalue
def test_setitem(): """ Test of node setitem """ res = run(('openalea.python method', 'setitem'), inputs={ 'obj': { 'a': 1, 'b': 2 }, 'key': 'c', 'value': 3 }, pm=pm) assert len(res[0]) == 3 res = run(('openalea.python method', 'setitem'), inputs={ 'obj': range(10), 'key': 2, 'value': 3 }, pm=pm) assert len(res[0]) == 10 assert res[0][2] == 3
def test_getattr(): """ Test of node getattr """ class Dummy: def __init__(self): self.tvalue = False val = Dummy() res = run(('openalea.python method', 'getattr'), inputs={ 'obj': val, 'member_name': 'tvalue' }, pm=pm) assert res[0] == val.tvalue
def binary_tst(opname, val1, val2, res=True, arg1name="a", arg2name="b"): """ Binary Test """ rres = run(("openalea.math", opname), inputs={arg1name: val1, arg2name: val2}, pm=pm) if rres[0] != res: raise ValueError( "Bad result for operator '" + opname + "' with values " + str((val1, val2)) + ". Expected " + str(res) + ", Got " + str(rres[0]) + "." )
def function_tst(function_name, val1, res=True, arg1name="a"): """ Function test """ epsilon = 1e-15 rres = run(("openalea.math", function_name), inputs={arg1name: val1}, pm=pm) if (rres[0] - res) > epsilon: raise ValueError( "Bad result for operator '" + function_name + "' with values " + str((val1)) + ". Expected " + str(res) + ", Got " + str(rres[0]) + "." )
def test_enumerate(): """ Test of node enumerate """ res = run(('openalea.python method', 'enumerate'), inputs={'obj': range(2, 10)}, pm=pm) assert res[0] == [(i - 2, i) for i in range(2, 10)]
def test_print(): """ Test of node print """ val = 'test' res = run(('openalea.python method', 'print'), inputs={'x': val}, pm=pm) assert res[0] == val
def test_add(): """ Test of node + """ res = run(('openalea.math', '+'), inputs={'a': 1, 'b': 2}, pm=pm) assert res[0] == 3
def test_read_csv_from_file(): """ Test of node read_csv""" res = run(('openalea.csv', 'read csv'),\ inputs={'text': '1 1 2 3', 'separator': ' '}, pm=pm)
def test_adelr1(): """ Test AdelR MonoRun """ res = run(('alinea.adel.tutorials', 'AdelR MonoRun'), inputs={}, pm=pm, vtx_id=13)
def test_range(): """ Test of node range """ res = run(('openalea.python method', 'range'), inputs={'start': 0, 'stop': 10, 'step': 2}, pm=pm) assert res[0] == range(0, 10, 2)
def test_values(): """ Test of node values """ res = run(('openalea.python method', 'values'), inputs={'obj': {'a': 1, 'b': 2}}, pm=pm) assert res[0] == [1, 2]
def test_arvalis(): """ Test Leaf db Explorer """ res = run(('alinea.adel.tutorials', 'Leaf db Explorer'), inputs={}, pm=pm) assert res[0] == []
def test_adelr2(): """ Test AdelR MonoRun """ res = run(('alinea.adel.tutorials', 'AdelR MonoRun'), inputs={}, pm=pm, vtx_id=39)
def test_keys(): """ Test of node keys """ res = run(('openalea.python method', 'keys'), inputs={'obj': {'a': 1, 'b': 2}}, pm=pm) assert res[0] == ['a', 'b']
def test_mean(): """ Test of node mean """ res = run(('openalea.python method', 'mean'), inputs={'sequence': [i for i in range(5)]}, pm=pm) assert res[0] == sum(range(5)) / 5.
def test_items(): """ Test of node items """ res = run(('openalea.python method', 'items'), inputs={'obj': {'a': 1, 'b': 2}}, pm=pm) assert res[0] == [('a', 1), ('b', 2)]
def test_enumerate(): """ Test of node enumerate """ res = run(('openalea.python method', 'enumerate'), inputs={'obj': range(2, 10)}, pm=pm) assert res[0] == [(i-2, i) for i in range(2, 10)]
def test_add(): """ Test of node + """ res = run(("openalea.math", "+"), inputs={"a": 1, "b": 2}, pm=pm) assert res[0] == 3
def test_flatten(): """ Test of node flatten """ res = run(('openalea.python method', 'flatten'), inputs={'obj': [(3*i, 3*i+1, 3*i+2) for i in range(5)]}, pm=pm) assert len(res[0]) == 15 assert res[0] == range(15)
def test_zip(): """ Test of node zip """ res = run(('openalea.python method', 'zip'), inputs={'s1': range(10), 's2': range(10)}, pm=pm) assert res[0] == [(i, i) for i in range(10)]
def test_mean(): """ Test of node mean """ res = run(('openalea.python method', 'mean'), inputs={'sequence': [i for i in range(5)]}, pm=pm) assert res[0] == sum(range(5))/5.