예제 #1
0
    def test_comparison(self):
        hook1 = base.Hook(base.HOOK_BEFORE, base.noop)
        hook2 = base.Hook(base.HOOK_AFTER, base.noop)
        hook3 = base.Hook(base.HOOK_BEFORE, base.noop, priority=2)
        def alt_noop(*args, **kwargs):  # pragma: no cover
            pass
        hook4 = base.Hook(base.HOOK_BEFORE, alt_noop)

        # Hooks with same priority and function name compare equal wrt cmp
        self.assertFalse(hook1 < hook2)
        self.assertFalse(hook2 < hook1)
        # Hook 3 has higher priority, comes first
        self.assertLess(hook3, hook1)
        # Hook 4 has lower name, comes first
        self.assertLess(hook4, hook1)
예제 #2
0
 def test_some_names_and_priority(self):
     hook = base.Hook(base.HOOK_BEFORE,
                      base.noop,
                      'foo',
                      'bar',
                      priority=42)
     self.assertEqual(base.HOOK_BEFORE, hook.kind)
     self.assertEqual(42, hook.priority)
     self.assertEqual(base.noop, hook.function)
     self.assertEqual(('foo', 'bar'), hook.names)
예제 #3
0
    def test_equality(self):
        hook1 = base.Hook(base.HOOK_BEFORE, base.noop)
        hook2 = base.Hook(base.HOOK_BEFORE, base.noop)
        hook3 = base.Hook(base.HOOK_AFTER, base.noop)
        def alt_noop(*args, **kwargs):  # pragma: no cover
            pass
        hook4 = base.Hook(base.HOOK_BEFORE, alt_noop)
        hook5 = base.Hook(base.HOOK_BEFORE, base.noop, 'foo')
        hook6 = base.Hook(base.HOOK_BEFORE, base.noop, priority=42)

        self.assertEqual(hook1, hook2)
        self.assertNotEqual(hook1, hook3)
        self.assertNotEqual(hook1, hook4)
        self.assertNotEqual(hook1, hook5)
        self.assertNotEqual(hook1, hook6)
예제 #4
0
 def test_repr(self):
     hook = base.Hook(base.HOOK_BEFORE, base.noop)
     self.assertIn(repr(base.noop), repr(hook))
     self.assertIn(base.HOOK_BEFORE, repr(hook))
예제 #5
0
 def test_invalid_equality_checks(self):
     hook = base.Hook(base.HOOK_BEFORE, base.noop)
     self.assertTrue(hook != base.noop)
     self.assertFalse(hook == base.noop)
예제 #6
0
 def test_no_names_but_priority(self):
     hook = base.Hook(base.HOOK_BEFORE, base.noop, priority=42)
     self.assertEqual(base.HOOK_BEFORE, hook.kind)
     self.assertEqual(42, hook.priority)
     self.assertEqual(base.noop, hook.function)
     self.assertEqual(('*',), hook.names)
예제 #7
0
 def make_invalid_hook():
     return base.Hook('invalid_kind', base.noop)