# Path: openid/oidutil.py
# def autoSubmitHTML(form, title='OpenID transaction in progress'):
# def log(message, level=0):
# def appendArgs(url, args):
# def toBase64(s):
# def fromBase64(s):
#     def __init__(self, name):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def string_to_text(value, deprecate_msg):
# def force_text(value):
# class Symbol(object):
# 
# Path: openid/oidutil.py
# def force_text(value):
#     """
#     Return a text object representing value in UTF-8 encoding.
#     """
#     if isinstance(value, six.text_type):
#         # It's already a text, just return it.
#         return value
#     elif isinstance(value, bytes):
#         # It's a byte string, decode it.
#         return value.decode('utf-8')
#     else:
#         # It's not a string, convert it.
#         return six.text_type(value)
# 
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value


import random
import string
import unittest
import warnings
import six
        import copy
from mock import sentinel
from testfixtures import ShouldWarn
from openid import oidutil
from openid.oidutil import force_text, string_to_text

# XXX: there are more functions that could benefit from being better
# specified and tested in oidutil.py These include, but are not
# limited to appendArgs


class TestToText(unittest.TestCase):
    """Test `string_to_text` utility function."""

    def test_text_input(self):
        result = string_to_text('ěščřž', sentinel.msg)
        self.assertIsInstance(result, six.text_type)
        self.assertEqual(result, 'ěščřž')

    def test_binary_input(self):
        warning_msg = 'Conversion warning'
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            result = string_to_text('ěščřž'.encode('utf-8'), warning_msg)

        self.assertIsInstance(result, six.text_type)
        self.assertEqual(result, 'ěščřž')


class TestForceText(unittest.TestCase):
    """Test `force_text` utility function."""

    def test_text(self):
        self.assertEqual(force_text(''), '')
        self.assertEqual(force_text('ascii'), 'ascii')

# Path: openid/oidutil.py
# def autoSubmitHTML(form, title='OpenID transaction in progress'):
# def log(message, level=0):
# def appendArgs(url, args):
# def toBase64(s):
# def fromBase64(s):
#     def __init__(self, name):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def __hash__(self):
#     def __repr__(self):
# def string_to_text(value, deprecate_msg):
# def force_text(value):
# class Symbol(object):
# 
# Path: openid/oidutil.py
# def force_text(value):
#     """
#     Return a text object representing value in UTF-8 encoding.
#     """
#     if isinstance(value, six.text_type):
#         # It's already a text, just return it.
#         return value
#     elif isinstance(value, bytes):
#         # It's a byte string, decode it.
#         return value.decode('utf-8')
#     else:
#         # It's not a string, convert it.
#         return six.text_type(value)
# 
# def string_to_text(value, deprecate_msg):
#     """
#     Return input string coverted to text string.
# 
#     If input is text, it is returned as is.
#     If input is binary, it is decoded using UTF-8 to text.
#     """
#     assert isinstance(value, (six.text_type, six.binary_type))
#     if isinstance(value, six.binary_type):
#         warnings.warn(deprecate_msg, DeprecationWarning)
#         value = value.decode('utf-8')
#     return value


# Path: openid/test/test_oidutil.py
import random
import string
import unittest
import warnings
import six
        import copy
from mock import sentinel
from testfixtures import ShouldWarn
from openid import oidutil
from openid.oidutil import force_text, string_to_text


# XXX: there are more functions that could benefit from being better
# specified and tested in oidutil.py These include, but are not
# limited to appendArgs


class TestToText(unittest.TestCase):
    """Test `string_to_text` utility function."""

    def test_text_input(self):
        result = string_to_text('ěščřž', sentinel.msg)
        self.assertIsInstance(result, six.text_type)
        self.assertEqual(result, 'ěščřž')

    def test_binary_input(self):
        warning_msg = 'Conversion warning'
        with ShouldWarn(DeprecationWarning(warning_msg)):
            warnings.simplefilter('always')
            result = string_to_text('ěščřž'.encode('utf-8'), warning_msg)

        self.assertIsInstance(result, six.text_type)
        self.assertEqual(result, 'ěščřž')


class TestForceText(unittest.TestCase):
    """Test `force_text` utility function."""

    def test_text(self):
        self.assertEqual(force_text(''), '')
        self.assertEqual(force_text('ascii'), 'ascii')

        self.assertEqual(force_text('ůňíčóďé'), 'ůňíčóďé')