<commit_before># GPLv3 or later
# Copyright (c) 2016 Genome Research Limited
import unittest
from abc import ABCMeta, abstractmethod

from cookiemonster.common.decorators import too_big_to_fail, MaxAttemptsExhausted


class ABCStub(metaclass=ABCMeta):
    @abstractmethod
    def this_will_fail_unless(self, condition:bool) -> bool:
        ''' This method will raise an exception until condition is True '''

@too_big_to_fail
class Stub(ABCStub):
    def this_will_fail_unless(self, condition:bool) -> bool:
        if not condition:
            raise Exception

        return True


class TestCatcherDecorator(unittest.TestCase):
    def test_fail_after_max_attempts(self):
        tries = 10
        obj = Stub(max_attempts=tries)

        for x in range(1, tries + 1):
            if x == tries:
                self.assertEqual(obj.this_will_fail_unless(x == tries), True)
            else:
                with self.assertRaises(MaxAttemptsExhausted):
                    obj.this_will_fail_unless(x == tries)

if __name__ == '__main__':
    unittest.main()<commit_msg>Fleshed out tests a bit<commit_after># GPLv3 or later
# Copyright (c) 2016 Genome Research Limited
import unittest
from abc import ABCMeta, abstractmethod

from cookiemonster.common.decorators import too_big_to_fail, MaxAttemptsExhausted


class ABCStub(metaclass=ABCMeta):
    @abstractmethod
    def this_will_fail_unless(self, condition:bool) -> bool:
        ''' This method will raise an exception unless condition is True '''

    @abstractmethod
    def this_will_always_fail(self):
        ''' This method will always raise an exception '''

@too_big_to_fail
class Stub(ABCStub):
    def this_will_fail_unless(self, condition:bool) -> bool:
        if not condition:
            raise Exception

        return True

    def this_will_always_fail(self):
        raise Exception


class TestCatcherDecorator(unittest.TestCase):
    def test_fail_after_max_attempts(self):
        tries = 10
        obj = Stub(max_attempts=tries)

        for x in range(1, tries + 1):
            if x == tries:
                self.assertTrue(obj.this_will_fail_unless(x == tries))
            else:
                with self.assertRaises(MaxAttemptsExhausted):
                    obj.this_will_fail_unless(x == tries)

    @unittest.skip('How do you test something that can never fail!?')
    def test_never_fails(self):
        obj = Stub()


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.08211382113821138, 'fraction_numerical': 0.007317073170731708, 'mean_word_length': 2.975767366720517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4626264', 'n_tokens_mistral': 780, 'n_tokens_neox': 732, 'n_words': 193}