def Base(self: DSLContractSubclass) -> DSLContractSubclass: """Base operation. Called by default from ELLIPTIc before any other operation. """ expr = Expression(self.dsl_impl.base_delegate(), "Base") expr.shape = "shape=doubleoctagon" return self.append_tree(expr)
def test_render(self, mocker): child = "child" kwargs = {"arg1": 1, "arg2": 2} template = mocker.Mock() template.render.return_value = mocker.sentinel.rendered_template template_manager = mocker.Mock() template_manager.get_template.return_value = template context_delegate = mocker.Mock() context_delegate.get_template_file.return_value = mocker.sentinel.template_file context_delegate.template_kwargs.return_value = kwargs expression = Expression(context_delegate) rendered_template = expression.render(template_manager, child, context_delegate) assert rendered_template is mocker.sentinel.rendered_template context_delegate.get_template_file.assert_called_once() template_manager.get_template.assert_called_once_with( mocker.sentinel.template_file) context_delegate.template_kwargs.assert_called_once() template.render.assert_called_once_with(child=child, **kwargs)
def test_add_child(self): expression1 = Expression(None) expression2 = Expression(None) expression1.add_child(expression2) assert expression1.children[0] is expression2 assert len(expression1.children) == 1
def test_visit(self, delegate_stub): context = Context() expression = Expression(delegate_stub) with expression.visit(context) as context_delegate: assert context.get_value('a') == '10' with pytest.raises(ContextException): context.get_value('a')
def ByAdj(self, bridge_dim: int, to_dim: int) -> 'SelectorContract': return self.append_tree( Expression(self.dsl_impl.by_adj_delegate(bridge_dim, to_dim), "ByAdj", { 'bridge_dim': bridge_dim, 'to_dim': to_dim }))
def ByEnt(self, dim: int) -> 'SelectorContract': return self.append_tree( Expression(self.dsl_impl.by_ent_delegate(dim), "ByEnt", {'dim': dim}))
def Test(self, arg): return self.append_tree( Expression(self.dsl_impl.test_delegate(arg), "Test"))
def Store(self, field_name) -> 'ManagerContract': return self.append_tree( Expression( self.dsl_impl.store_delegate(field_name), "Store", {'field': field_name}))
def Solve(self) -> 'ManagerContract': return self.append_tree(Expression(self.dsl_impl.solve_delegate(), "Solve"))
def ScalarMult(self, scalar: int) -> 'VectorContract': return self.append_tree( Expression(self.dsl_impl.scalar_mult_delegate(scalar), "ScalarMult"))
def test_name_args(self): expression = Expression(None, 'test_name', {'a': '1', 'b': '2'}) assert expression.name == 'test_name\na=1\nb=2'
def Reduce(self, fun: MeshQLFunction) -> 'ComputerContract': return self.append_tree( Expression( self.dsl_impl.reduce_delegate(fun), "Reduce", {fun.fun: fun.fargs}))
def Map(self, fun: MeshQLFunction) -> 'ComputerContract': return self.append_tree( Expression( self.dsl_impl.map_delegate(fun), "Map", {fun.fun: fun.fargs}))
def Sum(self) -> 'VectorContract': return self.append_tree(Expression(self.dsl_impl.sum_delegate(), "Sum"))
def ScalarSum(self, scalar: int) -> 'VectorContract': return self.append_tree( Expression(self.dsl_impl.scalar_sum_delegate(scalar), "ScalarSum"))
def Where(self, **conditions): return self.append_tree( Expression(self.dsl_impl.where_delegate(conditions), "Where"))
def Test(self): return self.append_tree( Expression(self.dsl_impl.base_delegate(), "Test"))
def Range(self, start: int, count: int) -> 'VectorContract': return self.append_tree( Expression(self.dsl_impl.range_delegate(start, count), "Range"))