<commit_before># encoding: utf-8

import sys
from unittest import TestCase


from pulp.util import compat



class TestPy3K(TestCase):
    def test_exception(self):
        try:
            1/0
        
        except:
            exc = compat.exception()
            
            self.assertEquals(exc.name, 'ZeroDivisionError')
            self.assertEquals(exc.cls, ZeroDivisionError)
            self.assertEquals(exc.args, ('integer division or modulo by zero', ))
        
        try:
            raise Exception('foo', 1)

        except:
            exc = compat.exception()

            self.assertEquals(exc.name, 'Exception')
            self.assertEquals(exc.cls, Exception)
            self.assertEquals(exc.args, ('foo', 1))
        
    
    def test_bytes(self):
        data = compat.binary(b'\xc3\xbc')
        self.assertEquals(len(data), 2)
        
        self.failUnless(isinstance(data.decode('utf8'), compat.unicode))
        self.assertEquals(len(data.decode('utf8')), 1)
    
    def test_unicode(self):
        if sys.version_info > (3, 0):
            def uchar():
                return 'ü'
        
        else:
            def uchar():
                return u'ü'
            
        text = compat.unicode(uchar())
        self.assertEquals(len(text), 1)
        
        self.failUnless(isinstance(text.encode('utf8'), compat.binary))
        self.assertEquals(len(text.encode('utf8')), 2)
    
    def test_byte_errors(self):
        self.assertRaises(UnicodeEncodeError, lambda: compat.binary(u'ü'))


class TestIO(TestCase):
    def test_string_bytes_io(self):
        io = compat.IO("Hello world!")
        value = io.read()
        
        self.assertEquals(value, "Hello world!")
        self.failUnless(isinstance(value, compat.binary))
        
        self.assertRaises(TypeError, lambda: compat.IO(u"ü"))
<commit_msg>Attempt to isolate unicode constant handling differences for py3k compatibility.<commit_after># encoding: utf-8

import sys
from unittest import TestCase


from pulp.util import compat


if sys.version_info >= (3, 0):
    def uchar():
        return 'ü'

else:
    def uchar():
        return u'ü'



class TestPy3K(TestCase):
    def test_exception(self):
        try:
            1/0
        
        except:
            exc = compat.exception()
            
            self.assertEquals(exc.name, 'ZeroDivisionError')
            self.assertEquals(exc.cls, ZeroDivisionError)
            self.assertEquals(exc.args, ('integer division or modulo by zero', ))
        
        try:
            raise Exception('foo', 1)

        except:
            exc = compat.exception()

            self.assertEquals(exc.name, 'Exception')
            self.assertEquals(exc.cls, Exception)
            self.assertEquals(exc.args, ('foo', 1))
        
    
    def test_bytes(self):
        data = compat.binary(b'\xc3\xbc')
        self.assertEquals(len(data), 2)
        
        self.failUnless(isinstance(data.decode('utf8'), compat.unicode))
        self.assertEquals(len(data.decode('utf8')), 1)
    
    def test_unicode(self):
        text = compat.unicode(uchar())
        self.assertEquals(len(text), 1)
        
        self.failUnless(isinstance(text.encode('utf8'), compat.binary))
        self.assertEquals(len(text.encode('utf8')), 2)
    
    def test_byte_errors(self):
        self.assertRaises(UnicodeEncodeError, lambda: compat.binary(uchar()))


class TestIO(TestCase):
    def test_string_bytes_io(self):
        io = compat.IO("Hello world!")
        value = io.read()
        
        self.assertEquals(value, "Hello world!")
        self.failUnless(isinstance(value, compat.binary))
        
        self.assertRaises(TypeError, lambda: compat.IO(uchar()))

{'fraction_non_alphanumeric': 0.12048192771084337, 'fraction_numerical': 0.009370816599732263, 'mean_word_length': 2.0927152317880795, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5860728', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1061, 'n_words': 213}