def test_action_not_supported_report_supported_action(self): # Test raise InteractionNotSupported contains information about what # actions are supported. class SpecificEditor: pass class SpecificEditor2: pass class UserAction: pass class UserAction2: pass class UserAction3: pass def handler(wrapper, interaction): pass registry = TargetRegistry() registry.register_interaction(SpecificEditor, UserAction, handler) registry.register_interaction(SpecificEditor2, UserAction2, handler) registry.register_interaction(SpecificEditor2, UserAction3, handler) with self.assertRaises(InteractionNotSupported) as exception_context: registry.get_handler(SpecificEditor2, None) self.assertIn(UserAction2, exception_context.exception.supported) self.assertIn(UserAction3, exception_context.exception.supported) self.assertNotIn(UserAction, exception_context.exception.supported)
def test_registry_empty(self): registry = TargetRegistry() with self.assertRaises(InteractionNotSupported) as exception_context: registry.get_handler(None, None) self.assertEqual( str(exception_context.exception), "No handler is found for target None with interaction None. " "Supported these: []", )
def test_register_editor_with_action(self): registry = TargetRegistry() class SpecificEditor: pass class UserAction: pass def handler(wrapper, interaction): pass # when registry.register_interaction( target_class=SpecificEditor, interaction_class=UserAction, handler=handler, ) # then actual = registry.get_handler(SpecificEditor, UserAction) self.assertIs(actual, handler)