当前位置: 首页>>代码示例>>Python>>正文


Python test_support.have_unicode方法代码示例

本文整理汇总了Python中test.test_support.have_unicode方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.have_unicode方法的具体用法?Python test_support.have_unicode怎么用?Python test_support.have_unicode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在test.test_support的用法示例。


在下文中一共展示了test_support.have_unicode方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_float

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_float(self):
        self.assertEqual(float(3.14), 3.14)
        self.assertEqual(float(314), 314.0)
        self.assertEqual(float(314L), 314.0)
        self.assertEqual(float("  3.14  "), 3.14)
        self.assertRaises(ValueError, float, "  0x3.1  ")
        self.assertRaises(ValueError, float, "  -0x3.p-1  ")
        self.assertRaises(ValueError, float, "  +0x3.p-1  ")
        self.assertRaises(ValueError, float, "++3.14")
        self.assertRaises(ValueError, float, "+-3.14")
        self.assertRaises(ValueError, float, "-+3.14")
        self.assertRaises(ValueError, float, "--3.14")
        # check that we don't accept alternate exponent markers
        self.assertRaises(ValueError, float, "-1.7d29")
        self.assertRaises(ValueError, float, "3D-14")
        if test_support.have_unicode:
            self.assertEqual(float(unicode("  3.14  ")), 3.14)
            self.assertEqual(float(unicode("  \u0663.\u0661\u0664  ",'raw-unicode-escape')), 3.14)

        # extra long strings should no longer be a problem
        # (in 2.6, long unicode inputs to float raised ValueError)
        float('.' + '1'*1000)
        float(unicode('.' + '1'*1000)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_float.py

示例2: test_non_numeric_input_types

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_non_numeric_input_types(self):
        # Test possible non-numeric types for the argument x, including
        # subclasses of the explicitly documented accepted types.
        class CustomStr(str): pass
        class CustomByteArray(bytearray): pass
        factories = [str, bytearray, CustomStr, CustomByteArray, buffer]

        if test_support.have_unicode:
            class CustomUnicode(unicode): pass
            factories += [unicode, CustomUnicode]

        for f in factories:
            with test_support.check_py3k_warnings(quiet=True):
                x = f(" 3.14  ")
            msg = 'x has value %s and type %s' % (x, type(x).__name__)
            try:
                self.assertEqual(float(x), 3.14, msg=msg)
            except TypeError, err:
                raise AssertionError('For %s got TypeError: %s' %
                                     (type(x).__name__, err))
            errmsg = "could not convert"
            with self.assertRaisesRegexp(ValueError, errmsg, msg=msg), \
                 test_support.check_py3k_warnings(quiet=True):
                float(f('A' * 0x10)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_float.py

示例3: test_getint

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_getint(self):
        tcl = self.interp.tk
        for i in self.get_integers():
            result = tcl.getint(' %d ' % i)
            self.assertEqual(result, i)
            self.assertIsInstance(result, type(int(result)))
            if tcl_version >= (8, 5):
                self.assertEqual(tcl.getint(' {:#o} '.format(i)), i)
            self.assertEqual(tcl.getint(' %#o ' % i), i)
            self.assertEqual(tcl.getint(' %#x ' % i), i)
        if tcl_version < (8, 5):  # bignum was added in Tcl 8.5
            self.assertRaises(TclError, tcl.getint, str(2**1000))
        self.assertEqual(tcl.getint(42), 42)
        self.assertRaises(TypeError, tcl.getint)
        self.assertRaises(TypeError, tcl.getint, '42', '10')
        self.assertRaises(TypeError, tcl.getint, 42.0)
        self.assertRaises(TclError, tcl.getint, 'a')
        self.assertRaises((TypeError, ValueError, TclError),
                          tcl.getint, '42\0')
        if test_support.have_unicode:
            self.assertEqual(tcl.getint(unicode('42')), 42)
            self.assertRaises((UnicodeEncodeError, ValueError, TclError),
                              tcl.getint, '42' + unichr(0xd800)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_tcl.py

示例4: test_getboolean

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_getboolean(self):
        tcl = self.interp.tk
        self.assertIs(tcl.getboolean('on'), True)
        self.assertIs(tcl.getboolean('1'), True)
        self.assertIs(tcl.getboolean(u'on'), True)
        self.assertIs(tcl.getboolean(u'1'), True)
        self.assertIs(tcl.getboolean(42), True)
        self.assertIs(tcl.getboolean(0), False)
        self.assertIs(tcl.getboolean(42L), True)
        self.assertIs(tcl.getboolean(0L), False)
        self.assertRaises(TypeError, tcl.getboolean)
        self.assertRaises(TypeError, tcl.getboolean, 'on', '1')
        self.assertRaises(TypeError, tcl.getboolean, 1.0)
        self.assertRaises(TclError, tcl.getboolean, 'a')
        self.assertRaises((TypeError, ValueError, TclError),
                          tcl.getboolean, 'on\0')
        if test_support.have_unicode:
            self.assertIs(tcl.getboolean(unicode('on')), True)
            self.assertRaises((UnicodeEncodeError, ValueError, TclError),
                              tcl.getboolean, 'on' + unichr(0xd800)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_tcl.py

示例5: test_splitunc

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_splitunc(self):
        tester('ntpath.splitunc("c:\\foo\\bar")',
               ('', 'c:\\foo\\bar'))
        tester('ntpath.splitunc("c:/foo/bar")',
               ('', 'c:/foo/bar'))
        tester('ntpath.splitunc("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitunc("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar'))
        tester('ntpath.splitunc("\\\\\\conky\\mountpoint\\foo\\bar")',
               ('', '\\\\\\conky\\mountpoint\\foo\\bar'))
        tester('ntpath.splitunc("///conky/mountpoint/foo/bar")',
               ('', '///conky/mountpoint/foo/bar'))
        tester('ntpath.splitunc("\\\\conky\\\\mountpoint\\foo\\bar")',
               ('', '\\\\conky\\\\mountpoint\\foo\\bar'))
        tester('ntpath.splitunc("//conky//mountpoint/foo/bar")',
               ('', '//conky//mountpoint/foo/bar'))
        if test_support.have_unicode:
            self.assertEqual(ntpath.splitunc(u'//conky/MOUNTPO%cNT/foo/bar' % 0x0130),
                             (u'//conky/MOUNTPO%cNT' % 0x0130, u'/foo/bar')) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_ntpath.py

示例6: test_unicode

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_unicode(self):

        if not test_support.have_unicode: return

        # The StringIO module also supports concatenating Unicode
        # snippets to larger Unicode strings. This is tested by this
        # method. Note that cStringIO does not support this extension.

        f = self.MODULE.StringIO()
        f.write(self._line[:6])
        f.seek(3)
        f.write(unicode(self._line[20:26]))
        f.write(unicode(self._line[52]))
        s = f.getvalue()
        self.assertEqual(s, unicode('abcuvwxyz!'))
        self.assertEqual(type(s), types.UnicodeType) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_StringIO.py

示例7: test_subclass_tuple

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_subclass_tuple(self):
        # test with a tuple as the second argument classes
        self.assertEqual(True, issubclass(Child, (Child,)))
        self.assertEqual(True, issubclass(Child, (Super,)))
        self.assertEqual(False, issubclass(Super, (Child,)))
        self.assertEqual(True, issubclass(Super, (Child, Super)))
        self.assertEqual(False, issubclass(Child, ()))
        self.assertEqual(True, issubclass(Super, (Child, (Super,))))

        self.assertEqual(True, issubclass(NewChild, (NewChild,)))
        self.assertEqual(True, issubclass(NewChild, (NewSuper,)))
        self.assertEqual(False, issubclass(NewSuper, (NewChild,)))
        self.assertEqual(True, issubclass(NewSuper, (NewChild, NewSuper)))
        self.assertEqual(False, issubclass(NewChild, ()))
        self.assertEqual(True, issubclass(NewSuper, (NewChild, (NewSuper,))))

        self.assertEqual(True, issubclass(int, (long, (float, int))))
        if test_support.have_unicode:
            self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring)))) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:21,代码来源:test_isinstance.py

示例8: test_valid_non_numeric_input_types_for_x

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_valid_non_numeric_input_types_for_x(self):
        # Test possible valid non-numeric types for x, including subclasses
        # of the allowed built-in types.
        class CustomStr(str): pass
        values = ['100', CustomStr('100')]

        if have_unicode:
            class CustomUnicode(unicode): pass
            values += [unicode('100'), CustomUnicode(unicode('100'))]

        for x in values:
            msg = 'x has value %s and type %s' % (x, type(x).__name__)
            try:
                self.assertEqual(int(x), 100, msg=msg)
                self.assertEqual(int(x, 2), 4, msg=msg)
            except TypeError, err:
                raise AssertionError('For %s got TypeError: %s' %
                                     (type(x).__name__, err)) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:test_int.py

示例9: test_ignore_case

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_ignore_case(self):
        self.assertEqual(re.match("abc", "ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match("abc", u"ABC", re.I).group(0), "ABC")
        self.assertEqual(re.match(r"(a\s[^a])", "a b", re.I).group(1), "a b")
        self.assertEqual(re.match(r"(a\s[^a]*)", "a bb", re.I).group(1), "a bb")
        self.assertEqual(re.match(r"(a\s[abc])", "a b", re.I).group(1), "a b")
        self.assertEqual(re.match(r"(a\s[abc]*)", "a bb", re.I).group(1), "a bb")
        self.assertEqual(re.match(r"((a)\s\2)", "a a", re.I).group(1), "a a")
        self.assertEqual(re.match(r"((a)\s\2*)", "a aa", re.I).group(1), "a aa")
        self.assertEqual(re.match(r"((a)\s(abc|a))", "a a", re.I).group(1), "a a")
        self.assertEqual(re.match(r"((a)\s(abc|a)*)", "a aa", re.I).group(1), "a aa")

        if have_unicode:
            assert u(r'\u212a').lower() == u'k' # 'K'
            self.assertTrue(re.match(ur'K', u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(ur'k', u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'\u212a'), u'K', re.U | re.I))
            self.assertTrue(re.match(u(r'\u212a'), u'k', re.U | re.I))
            assert u(r'\u017f').upper() == u'S' # 'ſ'
            self.assertTrue(re.match(ur'S', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(ur's', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(u(r'\u017f'), u'S', re.U | re.I))
            self.assertTrue(re.match(u(r'\u017f'), u's', re.U | re.I)) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:25,代码来源:test_re.py

示例10: test_ignore_case_set

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import have_unicode [as 别名]
def test_ignore_case_set(self):
        self.assertTrue(re.match(r'[19A]', 'A', re.I))
        self.assertTrue(re.match(r'[19a]', 'a', re.I))
        self.assertTrue(re.match(r'[19a]', 'A', re.I))
        self.assertTrue(re.match(r'[19A]', 'a', re.I))
        if have_unicode:
            self.assertTrue(re.match(ur'[19A]', u'A', re.U | re.I))
            self.assertTrue(re.match(ur'[19a]', u'a', re.U | re.I))
            self.assertTrue(re.match(ur'[19a]', u'A', re.U | re.I))
            self.assertTrue(re.match(ur'[19A]', u'a', re.U | re.I))
            assert u(r'\u212a').lower() == u'k' # 'K'
            self.assertTrue(re.match(u(r'[19K]'), u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19k]'), u(r'\u212a'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u212a]'), u'K', re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u212a]'), u'k', re.U | re.I))
            assert u(r'\u017f').upper() == u'S' # 'ſ'
            self.assertTrue(re.match(ur'[19S]', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(ur'[19s]', u(r'\u017f'), re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u017f]'), u'S', re.U | re.I))
            self.assertTrue(re.match(u(r'[19\u017f]'), u's', re.U | re.I)) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:22,代码来源:test_re.py


注:本文中的test.test_support.have_unicode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。