Beispiel #1
0
    def test_unicode__basic__input_unicode(self):
        """
        Test unicode(): default arguments with unicode input.

        """
        loader = Loader()
        actual = loader.str("foo")

        self.assertString(actual, "foo")
Beispiel #2
0
    def test_unicode__encoding_argument(self):
        """
        Test unicode(): encoding argument.

        """
        loader = Loader()

        non_ascii = 'abcdé'.encode('utf-8')

        self.assertRaises(UnicodeDecodeError, loader.str, non_ascii)

        actual = loader.str(non_ascii, encoding='utf-8')
        self.assertString(actual, 'abcdé')
Beispiel #3
0
    def test_unicode__basic__input_unicode_subclass(self):
        """
        Test unicode(): default arguments with unicode-subclass input.

        """
        class UnicodeSubclass(str):
            pass

        s = UnicodeSubclass("foo")

        loader = Loader()
        actual = loader.str(s)

        self.assertString(actual, "foo")
Beispiel #4
0
    def test_unicode__basic__input_unicode_subclass(self):
        """
        Test unicode(): default arguments with unicode-subclass input.

        """
        class UnicodeSubclass(str):
            pass

        s = UnicodeSubclass("foo")

        loader = Loader()
        actual = loader.str(s)

        self.assertString(actual, "foo")
Beispiel #5
0
    def test_unicode__to_unicode__attribute(self):
        """
        Test unicode(): encoding attribute.

        """
        loader = Loader()

        non_ascii = 'abcdé'.encode('utf-8')
        self.assertRaises(UnicodeDecodeError, loader.str, non_ascii)

        def to_unicode(s, encoding=None):
            if encoding is None:
                encoding = 'utf-8'
            return str(s, encoding)

        loader.to_unicode = to_unicode
        self.assertString(loader.str(non_ascii), "abcdé")
    def test_unicode__to_unicode__attribute(self):
        """
        Test unicode(): encoding attribute.

        """
        loader = Loader()

        non_ascii = 'abcdé'.encode('utf-8')
        self.assertRaises(UnicodeDecodeError, loader.str, non_ascii)

        def to_unicode(s, encoding=None):
            if encoding is None:
                encoding = 'utf-8'
            return str(s, encoding)

        loader.to_unicode = to_unicode
        self.assertString(loader.str(non_ascii), "abcdé")