Exemple #1
0
 def test_variables(self):
     """
     Testing that the variables of methods is returned correctly.
     """
     method = Method(node('x'), node('y'))
     variables = method.variables()
     assert_equal(variables, {'x', 'y'})
Exemple #2
0
    def test_bind_variables(self):
        """
        Test binding of values
        """
        function = Function({'x': 4}, [
            Method(node('x'), node('y')),
            Method(node('y'), node('z'))
        ])

        bound = function.bind_variables({'y': 10, 'z': 20})
        assert_equal(bound, {'x': 4, 'y': 10, 'z': 20})

        bound = function.bind_variables(
            {'y': 10, 'z': 20}, lambda n, x: str(x))
        assert_equal(bound, {'x': '4', 'y': '10', 'z': '20'})
Exemple #3
0
    def test_bind_variables_bad_bound(self):
        """
        Test that the bind_variables throw the bad_bound exception
        """
        function = Function({'x': None}, [
            Method(node('x'), node('y')),
            Method(node('y'), node('z'))
        ])
        with assert_raises(BadBound):
            function.bind_variables({})

        with assert_raises(BadBound):
            function.bind_variables({'x': 12, 'y': 10, 'z': 4})

        with assert_raises(BadBound):
            function.bind_variables({'y': 10})
Exemple #4
0
 def test_node_creation(self):
     """ tests that nodes is created correctly """
     function = Mock(name="function")
     names = tuple("name" + str(i) for i in range(3))
     nodes = tuple("node" + str(i) for i in range(3))
     dictionary = dict(zip(names, nodes))
     assert_equal(
         Node(function, zip(names, nodes)),
         node(function, dictionary))
Exemple #5
0
 def test_variables_with_internal_nodes(self):
     """
     Testing that variables is retured correctly, with internal nodes
     """
     from fbml import buildin
     method = Method(
         node(buildin.lt,  {'a': node('number'), 'b': node('const')}),
         node(buildin.mul, {'a': node('number'), 'b': node('const')})
     )
     variables = method.variables()
     assert_equal(variables, {'number', 'const'})
Exemple #6
0
 def test_repr(self):
     method = Method(node('a'), node('b'))
     string = repr(method)
     assert_equal(eval(string), method)
Exemple #7
0
 def test_str(self):
     method = Method(node('a'), node('b'))
     string = str(method)
     assert_regexp_matches(string, 'a -> b')
Exemple #8
0
 def test_node_equality(self):
     """ Enusre that nodes created with same sources is equal """
     names = tuple("name" + str(i) for i in range(3))
     nodes = tuple("node" + str(i) for i in range(3))
     sources = list(zip(names, nodes))
     assert_equal(node(None, sources), node(None, reversed(sources)))
Exemple #9
0
 def create_function(self):
     return Function({'x': None}, [
         Method(node('x'), node('y')),
         Method(node('y'), node('z'))
     ])
Exemple #10
0
 def test_depenencies_multible(self):
     """
     Test multible dependencies
     """
     n2 = Node(None, ((0, node('x')), (1, node('y'))))
     assert_equal(n2.dependencies(), {'x', 'y'})
Exemple #11
0
 def test_depenencies(self):
     """
     Test that dependencies is returned correctly
     """
     n = node('x')
     assert_equal(n.dependencies(), {'x'})
Exemple #12
0
 def test_str_function(self):
     f = Function({}, [], 'a_function')
     n = node(f,  {'a': node('number'), 'b': node('const')})
     assert_equal(str(n), '(a_function a=number b=const)')
Exemple #13
0
 def test_str_lt(self):
     from fbml import buildin
     n = node(buildin.lt,  {'a': node('number'), 'b': node('const')})
     assert_equal(str(n), '(lt a=number b=const)')
Exemple #14
0
 def test_str(self):
     n = node('a')
     assert_equal(str(n), 'a')
Exemple #15
0
 def test_repr(self):
     n = node('a')
     string = repr(n)
     assert_equal(eval(string), n)
Exemple #16
0
"""
.. currentmodule:: fbml.test

The tests
"""

from fbml.model import Method, Function
from fbml import buildin
from fbml import node

INCR = Function(
    {'test': True, 'value': 1},
    [
        Method(
            node('test'),
            node(buildin.add, {'a': node('number'), 'b': node('value')})
        )
    ],
    'incr'
)

MUL_IF_LESS = Function(
    {'const': 10},
    [
        Method(
            node(buildin.lt,  {'a': node('number'), 'b': node('const')}),
            node(buildin.mul, {'a': node('number'), 'b': node('const')})
        ),
        Method(
            node(buildin.ge,  {'a': node('number'), 'b': node('const')}),
            node('number')