# Copyright (c) 2004 DoCoMo Euro-Labs GmbH (Munich, Germany). # Copyright (c) 2001-2004 LOGILAB S.A. (Paris, FRANCE). # # http://www.docomolab-euro.com/ -- mailto:tarlano@docomolab-euro.com # http://www.logilab.fr/ -- mailto:contact@logilab.fr # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA '''This module is intended to be used with the test suite in Narval/tools/tests/cases. Do not expect anything useful from the actions defined here. ''' __revision__ = "$Id: Selftest.py,v 1.8 2003/01/30 09:26:33 syt Exp $" from narval.elements import create_error from narval.elements.test import Element MOD_XML=''' ''' def NOP_f(inputs) : """No OPeration""" return {} MOD_XML = MOD_XML + "" def produce_element_f(inputs): """output an element""" return {'output': Element()} MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ def produce_error_f(inputs): """output an error element""" return {'error': [create_error('yo')]} MOD_XML = MOD_XML + """ elmt.whatever """ MOD_XML = MOD_XML + """ isinstance(elmt, str) """ MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ def produce_multiple_elements_f(inputs): """output multiple elements""" return {'output': [Element(), Element(), Element()]} MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ def naughty_action_f(inputs): """Bad behaviour in action""" return None MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ # Bad behaviour in action : no stub exist in module############################ MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ def produce_wrong_multiple_elements_f(inputs): """Bad behaviour in action : outputs multiple elements with one wrong type""" class DummyElement: def as_xml(self, encoding='UTF-8'): return '' return {'output': [Element(), DummyElement(), # list DummyElement instead of Element instance Element()]} MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ def raise_exception_f(inputs): """Bad behaviour in action : exception raised""" raise 'Bouahahahahahaha!' MOD_XML = MOD_XML + "" # ########################### def identity_f(inputs): """identity function: copies its input to its ouput""" out = {} # if the input element has a flag attribute, things will be fine # otherwise, we'll get an error for id, elmt in inputs.items(): try: elmt = elmt.clone() out[id] = elmt elmt.identity = 1 except: # list argument ? out[id] = res = [] for elmt_ in elmt: elmt_ = elmt_.clone() elmt_.identity = 1 res.append(elmt_) return out # outdates optional MOD_XML = MOD_XML + """ outdates all elements of the optional list isinstance(elmt, Element) and elmt.el_id isinstance(elmt, str) elmt.attribute == "test" isinstance(elmt, Element) and elmt.el_id isinstance(elmt, str) elmt.attribute == "test" """ # match should be given in the recipe MOD_XML = MOD_XML + """ """ # action expects more than what is specified in the prototype # so that we can test the context from which the element is selected MOD_XML = MOD_XML + """ isinstance(elmt, Element) isinstance(elmt, Element) and elmt.identity """ MOD_XML = MOD_XML + """ isinstance(elmt, Element) elmt.identity """ # copies the input element to the output MOD_XML = MOD_XML + """ isinstance(elmt, Element) isinstance(elmt, Element) """ # eats a list of arguments MOD_XML = MOD_XML + """ isinstance(elmt, Element) """ MOD_XML = MOD_XML +''