Example #1
0
 def test_it_attach_method_as_rule_to_class_with_rulename(self):
     method = mock.Mock(__name__='method')
     cls = mock.Mock(**{'set_one.return_value': method,
                        '_rules': {'rulename': 42},
                        '__name__': 'classname'})
     del cls.method
     meta.rule(cls, 'rulename')(method)
     self.assertIs(method, cls.method)
     cls.set_one.assert_call_once_with(42, 'method', method)
Example #2
0
 def test_it_attach_method_as_rule_to_class(self):
     functioname = mock.Mock(__name__='functioname')
     cls = mock.Mock(**{'set_one.return_value': functioname,
                        '_rules': {}, '__name__': 'classname'})
     del cls.functioname
     meta.rule(cls)(functioname)
     self.assertIs(functioname, cls.functioname)
     cls.set_one.assert_call_once_with(
         cls._rules, 'functioname', functioname)
Example #3
0
    def test_it_does_not_attach_a_rule_if_method_already_exist(self):
        class cls:
            _rules = {}

            def method(self):
                pass

        method = mock.Mock(__name__='method')
        with self.assertRaises(AttributeError):
            meta.rule(cls, 'rulename')(method)
Example #4
0
    def test_it_does_not_attach_a_rule_if_method_already_exist(self):
        class cls:
            _rules = {}

            def method(self):
                pass

        method = mock.Mock(__name__='method')
        with self.assertRaises(AttributeError):
            meta.rule(cls, 'rulename')(method)
Example #5
0
 def test_it_attach_method_as_rule_to_class(self):
     functioname = mock.Mock(__name__='functioname')
     cls = mock.Mock(
         **{
             'set_one.return_value': functioname,
             '_rules': {},
             '__name__': 'classname'
         })
     del cls.functioname
     meta.rule(cls)(functioname)
     self.assertIs(functioname, cls.functioname)
     cls.set_one.assert_call_once_with(cls._rules, 'functioname',
                                       functioname)
Example #6
0
 def test_it_attach_method_as_rule_to_class_with_rulename(self):
     method = mock.Mock(__name__='method')
     cls = mock.Mock(
         **{
             'set_one.return_value': method,
             '_rules': {
                 'rulename': 42
             },
             '__name__': 'classname'
         })
     del cls.method
     meta.rule(cls, 'rulename')(method)
     self.assertIs(method, cls.method)
     cls.set_one.assert_call_once_with(42, 'method', method)