def test_unweave_module(self): """Tests if module's unweaving works correctly """ weaver.weave_module(self.mod, ContractAspect) weaver.unweave_module(self.mod, ContractAspect) # Create a stack of max_size = 1 and push 2 elements # if module has been unweaved, this should be ok ! stack = self.mod.StackImpl(1) stack.push(1) stack.push(2)
def enable_dbc(*args): """ Without arguments, return True if contracts can be enabled and should be enabled (see option -d), return False otherwise. With arguments, return False if contracts can't or shouldn't be enabled, otherwise weave ContractAspect with items passed as arguments. """ if not ENABLE_DBC: return False try: from logilab.aspects.weaver import weaver from logilab.aspects.lib.contracts import ContractAspect except ImportError: sys.stderr.write( 'Warning: logilab.aspects is not available. Contracts disabled.') return False for arg in args: weaver.weave_module(arg, ContractAspect) return True
def cb_plug_module(self, option, opt_name, value, parser): """optik callback to plug the aspect on a module""" module = load_module_from_name(value) #self._weaved[value] = module weaver.weave_module(module, LoggerAspect, sys.stderr, self.config)
def test_weave_module(self): """Tests if module's weaving works correctly """ weaver.weave_module(self.mod, ContractAspect) stack = self.mod.StackImpl(3) self.assertRaises(ContractFailedError, stack.pop)