<commit_before>import unittest
from random import randint
from copy import copy

from construct.lib.container import Container, FlagsContainer, ListContainer


class TestContainer(unittest.TestCase):

    def test_getattr(self):
        c = Container(a=1)
        self.assertEqual(c["a"], 1)
        self.assertEqual(c.a, 1)

    def test_getattr_missing(self):
        c = Container(a=1)
        self.assertRaises(AttributeError, lambda: c.unknownkey)

    def test_setattr(self):
        c = Container()
        c.a = 1
        self.assertEqual(c.a, 1)
        self.assertEqual(c["a"], 1)
        c["a"] = 2
        self.assertEqual(c.a, 2)
        self.assertEqual(c["a"], 2)

    def test_delattr(self):
        c = Container(a=1)
        del c.a
        self.assertFalse("a" in c)
        self.assertRaises(AttributeError, lambda: c.a)

    def test_update(self):
        c = Container(a=1)
        d = Container()
        d.update(c)
        self.assertEqual(d.a, 1)

    def test_items(self):
        c = Container(a=1,b=2,c=3,d=4)
        self.assertEqual(c.keys(), ["a","b","c","d"])
        self.assertEqual(c.values(), [1,2,3,4])
        self.assertEqual(c.items(), [("a",1),("b",2),("c",3),("d",4)])

    def test_iters(self):
        c = Container(a=1,b=2,c=3,d=4)
        self.assertEqual(list(c.iterkeys()), ["a","b","c","d"])
        self.assertEqual(list(c.itervalues()), [1,2,3,4])
        self.assertEqual(list(c.iteritems()), [("a",1),("b",2),("c",3),("d",4)])

    def test_order_randomized(self):
        print("WARNING: this test is randomized and may not be reproducible")
        c = Container()
        while True:
            words = [("".join(chr(randint(65, 97)) for _ in range(randint(3,7))), i) for i in range(20)]
            if words != list(dict(words).keys()):
                break
        c.update(words)
        self.assertEqual([k for k, _ in words], list(c.keys()))

    def test_eq_eq(self):
        c = Container(a=1)
        d = Container(a=1)
        self.assertEqual(c, d)

    def test_ne_wrong_type(self):
        c = Container(a=1)
        d = [("a", 1)]
        self.assertNotEqual(c, d)

    def test_ne_wrong_key(self):
        c = Container(a=1)
        d = Container(b=1)
        self.assertNotEqual(c, d)

    def test_ne_wrong_value(self):
        c = Container(a=1)
        d = Container(a=2)
        self.assertNotEqual(c, d)

    def test_copy(self):
        c = Container(a=1)
        d = c.copy()
        self.assertEqual(c, d)
        self.assertTrue(c is not d)
<commit_msg>Added few minor tests, not relevant.<commit_after>import unittest
from random import randint
from copy import copy

from construct.lib.container import Container, FlagsContainer, ListContainer


class TestContainer(unittest.TestCase):

    def test_getattr(self):
        c = Container(a=1)
        self.assertEqual(c["a"], 1)
        self.assertEqual(c.a, 1)

    def test_getattr_missing(self):
        c = Container(a=1)
        self.assertRaises(AttributeError, lambda: c.unknownkey)
        self.assertRaises(KeyError, lambda: c["unknownkey"])

    def test_setattr(self):
        c = Container()
        c.a = 1
        self.assertEqual(c.a, 1)
        self.assertEqual(c["a"], 1)
        c["a"] = 2
        self.assertEqual(c.a, 2)
        self.assertEqual(c["a"], 2)

    def test_delattr(self):
        c = Container(a=1)
        del c.a
        self.assertFalse("a" in c)
        self.assertRaises(AttributeError, lambda: c.a)
        self.assertRaises(KeyError, lambda: c["a"])
        self.assertEqual(c, Container())

    def test_update(self):
        c = Container(a=1)
        d = Container()
        d.update(c)
        self.assertEqual(d.a, 1)
        self.assertEqual(c, d)

    def test_items(self):
        c = Container(a=1,b=2,c=3,d=4)
        self.assertEqual(c.keys(), ["a","b","c","d"])
        self.assertEqual(c.values(), [1,2,3,4])
        self.assertEqual(c.items(), [("a",1),("b",2),("c",3),("d",4)])

    def test_iters(self):
        c = Container(a=1,b=2,c=3,d=4)
        self.assertEqual(list(c.iterkeys()), ["a","b","c","d"])
        self.assertEqual(list(c.itervalues()), [1,2,3,4])
        self.assertEqual(list(c.iteritems()), [("a",1),("b",2),("c",3),("d",4)])

    def test_order_randomized(self):
        print("WARNING: this test is randomized and may not be reproducible")
        c = Container()
        while True:
            words = [("".join(chr(randint(65, 97)) for _ in range(randint(3,7))), i) for i in range(20)]
            if words != list(dict(words).keys()):
                break
        c.update(words)
        self.assertEqual([k for k, _ in words], list(c.keys()))

    def test_eq_eq(self):
        c = Container(a=1,b=2,c=3,d=4,e=5)
        d = Container(c=3,a=1,b=2,e=5,d=4)
        self.assertEqual(c, d)

    def test_ne_wrong_type(self):
        c = Container(a=1)
        d = [("a", 1)]
        self.assertNotEqual(c, d)

    def test_ne_wrong_key(self):
        c = Container(a=1)
        d = Container(b=1)
        self.assertNotEqual(c, d)

    def test_ne_wrong_value(self):
        c = Container(a=1)
        d = Container(a=2)
        self.assertNotEqual(c, d)

    def test_copy(self):
        c = Container(a=1)
        d = c.copy()
        self.assertEqual(c, d)
        self.assertTrue(c is not d)

{'fraction_non_alphanumeric': 0.16754518072289157, 'fraction_numerical': 0.021837349397590362, 'mean_word_length': 2.4477611940298507, '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': '6316084', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1847, 'n_words': 361}