<commit_before>import unittest, time

import ocookie

class CookieTest(unittest.TestCase):
    def test_construction(self):
        cookie = ocookie.Cookie('foo', 'bar', httponly=True)
        self.assertEquals('foo', cookie.name)
        self.assertEquals('bar', cookie.value)
        self.assertTrue(cookie.httponly)
        self.assertFalse(cookie.secure)

class CookieDictTest(unittest.TestCase):
    def test_cookie_header_value_one(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        header_value = cookie_dict.cookie_header_value()
        self.assertEqual('a=b', header_value)
    
    def test_cookie_header_value_two(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        cookie_dict['c'] = ocookie.Cookie('c', 'd')
        header_value = cookie_dict.cookie_header_value()
        self.assertEqual('a=b; c=d', header_value)
    
    def test_cookie_header_value_empty(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'aa')
        cookie_dict['b'] = ocookie.Cookie('b', '')
        cookie_dict['c'] = ocookie.Cookie('c', None)
        header_value = cookie_dict.cookie_header_value()
        self.assertEqual('a=aa', header_value)
    
    def test_deletion(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        self.assertTrue('a' in cookie_dict)
        self.assertTrue('c' not in cookie_dict)
        cookie_dict['c'] = ocookie.Cookie('c', 'd')
        self.assertTrue('c' in cookie_dict)
        
        del cookie_dict['c']
        self.assertTrue('c' not in cookie_dict)
    
    def test_access(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        a = cookie_dict['a']
        self.assertEqual('b', a.value)
    
    def test_overwrite(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        cookie_dict['a'] = ocookie.Cookie('a', 'c')
        a = cookie_dict['a']
        self.assertEqual('c', a.value)

class CookieJarTest(unittest.TestCase):
    def test_add(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        
        self.assertTrue('foo' in cookie_jar)
        # Not currently supported
        #self.assertTrue(cookie in cookie_jar)
        
        # negative assertions
        self.assertFalse('bar' in cookie_jar)
        #bar_cookie = ocookie.Cookie('bar', 'bar')
        #self.assertFalse(bar_cookie in cookie_jar)
    
    def test_replacement(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        
        replacement_cookie = ocookie.Cookie('foo', 'quux')
        cookie_jar.add(replacement_cookie)
        
        self.assertTrue('foo' in cookie_jar)
        self.assertEqual('quux', cookie_jar['foo'].value)
    
    def test_clear(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        assert 'foo' in cookie_jar
        
        cookie_jar.clear()
        assert 'foo' not in cookie_jar
    
    def test_build_cookie_header_value(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        assert 'foo' in cookie_jar
        
        expected = 'foo=bar'
        self.assertEqual(expected, cookie_jar.build_cookie_header_value())
    
    def test_build_cookie_header_value_two_cookies(self):
        cookie_jar = ocookie.CookieJar()
        cookie_jar.add(ocookie.Cookie('foo', 'foo-value'))
        cookie_jar.add(ocookie.Cookie('bar', 'bar-value'))
        
        expected = 'foo=foo-value; bar=bar-value'
        self.assertEqual(expected, cookie_jar.build_cookie_header_value())
    
    def test_build_cookie_header_value_empty(self):
        cookie_jar = ocookie.CookieJar()
        cookie_jar.add(ocookie.Cookie('foo', 'foo-value'))
        cookie_jar.add(ocookie.Cookie('bar', ''))
        cookie_jar.add(ocookie.Cookie('quux', None))
        
        expected = 'foo=foo-value'
        self.assertEqual(expected, cookie_jar.build_cookie_header_value())

class CookieHeaderValueParsingTest(unittest.TestCase):<commit_msg>Python 3 compatibility: dictionaries are iterated in arbitrary order<commit_after>import unittest, time

import ocookie

class CookieTest(unittest.TestCase):
    def test_construction(self):
        cookie = ocookie.Cookie('foo', 'bar', httponly=True)
        self.assertEquals('foo', cookie.name)
        self.assertEquals('bar', cookie.value)
        self.assertTrue(cookie.httponly)
        self.assertFalse(cookie.secure)

class CookieDictTest(unittest.TestCase):
    def test_cookie_header_value_one(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        header_value = cookie_dict.cookie_header_value()
        self.assertEqual('a=b', header_value)
    
    def test_cookie_header_value_two(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        cookie_dict['c'] = ocookie.Cookie('c', 'd')
        header_value = cookie_dict.cookie_header_value()
        self.assertTrue(
            header_value == 'a=b; c=d' or
            header_value == 'c=d; a=b'
        )
    
    def test_cookie_header_value_empty(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'aa')
        cookie_dict['b'] = ocookie.Cookie('b', '')
        cookie_dict['c'] = ocookie.Cookie('c', None)
        header_value = cookie_dict.cookie_header_value()
        self.assertEqual('a=aa', header_value)
    
    def test_deletion(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        self.assertTrue('a' in cookie_dict)
        self.assertTrue('c' not in cookie_dict)
        cookie_dict['c'] = ocookie.Cookie('c', 'd')
        self.assertTrue('c' in cookie_dict)
        
        del cookie_dict['c']
        self.assertTrue('c' not in cookie_dict)
    
    def test_access(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        a = cookie_dict['a']
        self.assertEqual('b', a.value)
    
    def test_overwrite(self):
        cookie_dict = ocookie.CookieDict()
        cookie_dict['a'] = ocookie.Cookie('a', 'b')
        cookie_dict['a'] = ocookie.Cookie('a', 'c')
        a = cookie_dict['a']
        self.assertEqual('c', a.value)

class CookieJarTest(unittest.TestCase):
    def test_add(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        
        self.assertTrue('foo' in cookie_jar)
        # Not currently supported
        #self.assertTrue(cookie in cookie_jar)
        
        # negative assertions
        self.assertFalse('bar' in cookie_jar)
        #bar_cookie = ocookie.Cookie('bar', 'bar')
        #self.assertFalse(bar_cookie in cookie_jar)
    
    def test_replacement(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        
        replacement_cookie = ocookie.Cookie('foo', 'quux')
        cookie_jar.add(replacement_cookie)
        
        self.assertTrue('foo' in cookie_jar)
        self.assertEqual('quux', cookie_jar['foo'].value)
    
    def test_clear(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        assert 'foo' in cookie_jar
        
        cookie_jar.clear()
        assert 'foo' not in cookie_jar
    
    def test_build_cookie_header_value(self):
        cookie_jar = ocookie.CookieJar()
        cookie = ocookie.Cookie('foo', 'bar')
        cookie_jar.add(cookie)
        assert 'foo' in cookie_jar
        
        expected = 'foo=bar'
        self.assertEqual(expected, cookie_jar.build_cookie_header_value())
    
    def test_build_cookie_header_value_two_cookies(self):
        cookie_jar = ocookie.CookieJar()
        cookie_jar.add(ocookie.Cookie('foo', 'foo-value'))
        cookie_jar.add(ocookie.Cookie('bar', 'bar-value'))
        
        actual = cookie_jar.build_cookie_header_value()
        self.assertTrue(
            actual == 'foo=foo-value; bar=bar-value' or
            actual == 'bar=bar-value; foo=foo-value'
        )
    
    def test_build_cookie_header_value_empty(self):
        cookie_jar = ocookie.CookieJar()
        cookie_jar.add(ocookie.Cookie('foo', 'foo-value'))
        cookie_jar.add(ocookie.Cookie('bar', ''))
        cookie_jar.add(ocookie.Cookie('quux', None))
        
        expected = 'foo=foo-value'
        self.assertEqual(expected, cookie_jar.build_cookie_header_value())

class CookieHeaderValueParsingTest(unittest.TestCase):
{'fraction_non_alphanumeric': 0.12917174853087926, 'fraction_numerical': 0.00011087703736556159, 'mean_word_length': 2.7442922374429224, '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': '2717909', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2802, 'n_words': 463}