Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)