<commit_before>import unittest
from ray.hooks import Hook
from ray.model import Model


class UserHookUseless(Hook):
    pass


class UserWithUselessHook(Model):
    hooks = [UserHookUseless]


class UserHookException(Hook):
    def before_save(self, user):
        raise Exception('Any exception %s' % (user.name,))


class UserHookFalse(Hook):
    def before_save(self, user):
        return False


class UserHookTrue(Hook):
    def before_save(self, user):
        return True


class User(Model):
    hooks = [UserHookException]

    def __init__(self, name=None):
        self.name = name


class UserWithTwoHooks(Model):
    hooks = [UserHookTrue, UserHookFalse]


class TestHookBeforeSave(unittest.TestCase):

    def test_before_save_hook_case_exception(self):
        user = User(name='felipe')
        with self.assertRaises(Exception) as e:
            user.put()
        self.assertEqual(str(e.exception), 'Any exception felipe')

    def test_before_save_hook_with_two_hooks(self):
        user = UserWithTwoHooks()
        with self.assertRaises(Exception) as e:
            user.put()
        self.assertEqual(str(e.exception), 'The hook(s) UserHookFalse.before_save didnt return True')

    def test_hook_before_save_not_implemented(self):
        user = UserWithUselessHook()
        with self.assertRaises(NotImplementedError) as e:
            user.put()
<commit_msg>Fixing #22<commit_after>import unittest
from ray.hooks import Hook
from ray.model import Model


class UserHookUseless(Hook):
    pass


class UserWithUselessHook(Model):
    hooks = [UserHookUseless]


class UserHookException(Hook):
    def before_save(self, user):
        raise Exception('Any exception %s' % (user.name,))


class UserHookFalse(Hook):
    def before_save(self, user):
        return False


class UserHookFalse2(Hook):
    def before_save(self, user):
        return False


class UserHookTrue(Hook):
    def before_save(self, user):
        return True


class User(Model):
    hooks = [UserHookException]

    def __init__(self, name=None):
        self.name = name


class UserWithTwoHooks(Model):
    hooks = [UserHookFalse2, UserHookTrue, UserHookFalse]


class TestHookBeforeSave(unittest.TestCase):

    def test_before_save_hook_case_exception(self):
        user = User(name='felipe')
        with self.assertRaises(Exception) as e:
            user.put()
        self.assertEqual(str(e.exception), 'Any exception felipe')

    def test_before_save_hook_with_two_hooks(self):
        user = UserWithTwoHooks()
        with self.assertRaises(Exception) as e:
            user.put()
        self.assertEqual(str(e.exception), 'The hook(s) UserHookFalse2, UserHookFalse.before_save didnt return True')

    def test_hook_before_save_not_implemented(self):
        user = UserWithUselessHook()
        with self.assertRaises(NotImplementedError) as e:
            user.put()

{'fraction_non_alphanumeric': 0.09490820921371666, 'fraction_numerical': 0.0017319016279875303, 'mean_word_length': 3.4091603053435113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4982346', 'n_tokens_mistral': 899, 'n_tokens_neox': 880, 'n_words': 200}