def apply(self, schema, trans_tbl, augdb): """Add a function to a given schema. :param schema: name of the schema in which to create the function :param trans_tbl: translation table :param augdb: augmenter dictionaries """ newdict = self.__dict__.copy() newdict.pop('name') newdict.pop('description') newfunc = Function(self.name, schema, self.description, None, [], **newdict) src = newfunc.source if '{{' in src and '}}' in src: pref = src.find('{{') prefix = src[:pref] suf = src.find('}}') suffix = src[suf + 2:] tmplkey = src[pref + 2:suf] if tmplkey not in augdb.funcsrcs: if '{{'+tmplkey+'}}' not in [pat for (pat, repl) in trans_tbl]: raise KeyError("Function template '%s' not found" % tmplkey) else: newfunc.source = prefix + augdb.funcsrcs[tmplkey].source + \ suffix for (pat, repl) in trans_tbl: if '{{' in newfunc.source: newfunc.source = newfunc.source.replace(pat, repl) if '{{' in newfunc.name: newfunc.name = newfunc.name.replace(pat, repl) if '{{' in newfunc.description: newfunc.description = newfunc.description.replace(pat, repl) return newfunc
def test_function(self): "Map a function" obj = Function("Weird/Or-what?", 'public', '', None, [], None, None, None, None) assert obj.extern_filename() == 'function.weird_or_what_.yaml'
def test_function(self): "Map a function" obj = Function(schema='public', name="Weird/Or-what?") assert obj.extern_filename() == 'function.weird_or_what_.yaml'