<commit_before>import unittest
import hookedup
import random


class TestList(unittest.TestCase):

    def setUp(self):
        self.count = 0
        self.post_hooks = ['post-add', 'post-replace', 'post-remove']
        self.pre_hooks = ['pre-add', 'pre-replace', 'pre-remove']
        
    def increment_count(self, *_):
        self.count += 1

    def raise_abort(self, *_):
        raise hookedup.Abort()

    def test_iadd(self):
        original = list(range(4))
        self.list = list(original)
        L = hookedup.List()
        L += self.list
        self.assertTrue(L == self.list)
        self.assertTrue(isinstance(L, hookedup.List))
        hold_only_4_items = lambda *_: (len(self.L2) >= 4 and (self.increment_count() or
                                self.raise_abort()))
        hook = {'pre-add': hold_only_4_items}
        self.L2 = hookedup.List(hook=hook)
        self.L2 += self.list
        self.assertTrue(self.L2 == L)
        self.L2 += self.list
        self.assertTrue(self.L2 == L == original)
        self.assertTrue(len(self.L2) == len(original) == self.count)

    def test_imul(self):
        original = list(range(4))
        self.list = list(original)
        L = hookedup.List(original)
        hold_only_4_items = lambda *_: (len(self.L2) >= 4 and (self.increment_count() or
                                self.raise_abort()))
        hook = {'pre-add': hold_only_4_items}
        self.L2 = hookedup.List(original, hook=hook)
        self.list *= 3
        L *= 3
        self.L2 *= 3
        self.assertTrue(L == self.list)
        self.assertTrue(len(original) * 2 == self.count)
        self.assertTrue(original == self.L2)<commit_msg>test unimplemented parts of hookedup.List to verify they return standard lists (instead of a hookedup.List instance)<commit_after>import unittest
import hookedup
import random

class TestListUnimplementedParts(unittest.TestCase):
    """ verify that these unimplemented methods do not return a hookedup.List instance; only a list
    """

    def setUp(self):
        self.original = list(range(4))
        self.L = hookedup.List(self.original)
        self.list = list(self.original)

    def test_L_is_hookedup_instance(self):
        self.assertTrue(isinstance(self.L, hookedup.List))

    def test_list_add_returns_normal_list(self):
        """ verify that addition in both arrangements produces a normal list """
        L = self.L + self.original
        L2 = self.original + self.L
        self.assertFalse(isinstance(L, hookedup.List))
        self.assertFalse(isinstance(L2, hookedup.List))
        self.assertTrue(isinstance(L, list))
        self.assertTrue(isinstance(L2, list))

    def test_list_multiply_returns_normal_list(self):
        """ verify that multiplication in multiple arrangments always produces a normal list """
        L = self.L * 2
        L2 = 2 * self.L
        self.assertFalse(isinstance(L, hookedup.List))
        self.assertFalse(isinstance(L2, hookedup.List))
        self.assertTrue(isinstance(L, list))
        self.assertTrue(isinstance(L2, list))

    def test_copy_returns_normal_list(self):
        L = self.L.copy()
        self.assertTrue(isinstance(L, list))
        self.assertFalse(isinstance(L, hookedup.List))



class TestAllListOperations(unittest.TestCase):
    """ verify that normal operation and exceptions are the same between hookedup.List and list """
    
    def setUp(self):
        self.original = list(range(4))
        self.L = hookedup.List(self.original)
        self.list = list(self.original)

    def test_lists_are_equal(self):
        self.assertTrue(self.L == self.original == self.list)


class TestHookedupList(unittest.TestCase):
    """ test implemented methods of hookedup.List """

    def setUp(self):
        self.count = 0
        self.post_hooks = ['post-add', 'post-replace', 'post-remove']
        self.pre_hooks = ['pre-add', 'pre-replace', 'pre-remove']
        
    def increment_count(self, *_):
        self.count += 1

    def raise_abort(self, *_):
        raise hookedup.Abort()

    def test_iadd(self):
        original = list(range(4))
        self.list = list(original)
        L = hookedup.List()
        L += self.list
        self.assertTrue(L == self.list)
        self.assertTrue(isinstance(L, hookedup.List))
        hold_only_4_items = lambda *_: (len(self.L2) >= 4 and (self.increment_count() or
                                self.raise_abort()))
        hook = {'pre-add': hold_only_4_items}
        self.L2 = hookedup.List(hook=hook)
        self.L2 += self.list
        self.assertTrue(self.L2 == L)
        self.L2 += self.list
        self.assertTrue(self.L2 == L == original)
        self.assertTrue(len(self.L2) == len(original) == self.count)
        self.assertTrue(isinstance(self.L2, hookedup.List))
        self.assertTrue(isinstance(L, hookedup.List))

    def test_imul(self):
        original = list(range(4))
        self.list = list(original)
        L = hookedup.List(original)
        hold_only_4_items = lambda *_: (len(self.L2) >= 4 and (self.increment_count() or
                                self.raise_abort()))
        hook = {'pre-add': hold_only_4_items}
        self.L2 = hookedup.List(original, hook=hook)
        self.list *= 3
        L *= 3
        self.L2 *= 3
        self.assertTrue(L == self.list)
        self.assertTrue(len(original) * 2 == self.count)
        self.assertTrue(original == self.L2)
        self.assertTrue(isinstance(L, hookedup.List))
        self.assertTrue(isinstance(self.L2, hookedup.List))
{'fraction_non_alphanumeric': 0.1261049972938842, 'fraction_numerical': 0.011185278729929641, 'mean_word_length': 2.4671669793621014, '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': '3236368', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1726, 'n_words': 348}