def test_source(obj): _obj = source._wrap(obj) assert _obj(1.57) == obj(1.57) src = source.importable(obj, alias='_f') exec src in globals(), locals() assert _f(1.57) == obj(1.57) name = source.getname(obj) assert name == obj.__name__ or src.split("=", 1)[0].strip()
def test_source(obj): _obj = source._wrap(obj) assert _obj(1.57) == obj(1.57) src = source.importable(obj, alias='_f') exec src in globals(), locals() assert _f(1.57) == obj(1.57) name = source.getname(obj) assert name == obj.__name__ or src.split("=",1)[0].strip()
def run_source(obj): _obj = source._wrap(obj) assert _obj(1.57) == obj(1.57) src = source.importable(obj, alias='_f') # LEEK: for 3.x, locals may not be modified # (see https://docs.python.org/3.6/library/functions.html#locals) # my_locals = locals() exec(src, globals(), my_locals) assert my_locals["_f"](1.57) == obj(1.57) name = source.getname(obj) assert name == obj.__name__ or src.split("=", 1)[0].strip()
def run_source(obj): _obj = source._wrap(obj) assert _obj(1.57) == obj(1.57) src = source.importable(obj, alias='_f') # LEEK: for 3.x, locals may not be modified # (see https://docs.python.org/3.6/library/functions.html#locals) # my_locals = locals() exec(src, globals(), my_locals) assert my_locals["_f"](1.57) == obj(1.57) name = source.getname(obj) assert name == obj.__name__ or src.split("=",1)[0].strip()
def __get_source(self, func): """Fetches source of the function""" hashf = hash(func) if hashf not in self.__sourcesHM: self.__sourcesHM[hashf] = importable(func) return self.__sourcesHM[hashf]