本文整理匯總了Python中test.string_tests.CommonTest方法的典型用法代碼示例。如果您正苦於以下問題:Python string_tests.CommonTest方法的具體用法?Python string_tests.CommonTest怎麽用?Python string_tests.CommonTest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類test.string_tests
的用法示例。
在下文中一共展示了string_tests.CommonTest方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_capitalize
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_capitalize(self):
string_tests.CommonTest.test_capitalize(self)
# check that titlecased chars are lowered correctly
# \u1ffc is the titlecased char
self.checkequal(u'\u1ffc\u1ff3\u1ff3\u1ff3',
u'\u1ff3\u1ff3\u1ffc\u1ffc', 'capitalize')
# check with cased non-letter chars
self.checkequal(u'\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
u'\u24c5\u24ce\u24c9\u24bd\u24c4\u24c3', 'capitalize')
self.checkequal(u'\u24c5\u24e8\u24e3\u24d7\u24de\u24dd',
u'\u24df\u24e8\u24e3\u24d7\u24de\u24dd', 'capitalize')
self.checkequal(u'\u2160\u2171\u2172',
u'\u2160\u2161\u2162', 'capitalize')
self.checkequal(u'\u2160\u2171\u2172',
u'\u2170\u2171\u2172', 'capitalize')
# check with Ll chars with no upper - nothing changes here
self.checkequal(u'\u019b\u1d00\u1d86\u0221\u1fb7',
u'\u019b\u1d00\u1d86\u0221\u1fb7', 'capitalize')
示例2: test_count
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_count(self):
string_tests.CommonTest.test_count(self)
# check mixed argument types
self.checkequalnofix(3, 'aaa', 'count', 'a')
self.checkequalnofix(0, 'aaa', 'count', 'b')
self.checkequalnofix(3, 'aaa', 'count', 'a')
self.checkequalnofix(0, 'aaa', 'count', 'b')
self.checkequalnofix(0, 'aaa', 'count', 'b')
self.checkequalnofix(1, 'aaa', 'count', 'a', -1)
self.checkequalnofix(3, 'aaa', 'count', 'a', -10)
self.checkequalnofix(2, 'aaa', 'count', 'a', 0, -1)
self.checkequalnofix(0, 'aaa', 'count', 'a', 0, -10)
# test mixed kinds
self.checkequal(10, '\u0102' + 'a' * 10, 'count', 'a')
self.checkequal(10, '\U00100304' + 'a' * 10, 'count', 'a')
self.checkequal(10, '\U00100304' + '\u0102' * 10, 'count', '\u0102')
self.checkequal(0, 'a' * 10, 'count', '\u0102')
self.checkequal(0, 'a' * 10, 'count', '\U00100304')
self.checkequal(0, '\u0102' * 10, 'count', '\U00100304')
self.checkequal(10, '\u0102' + 'a_' * 10, 'count', 'a_')
self.checkequal(10, '\U00100304' + 'a_' * 10, 'count', 'a_')
self.checkequal(10, '\U00100304' + '\u0102_' * 10, 'count', '\u0102_')
self.checkequal(0, 'a' * 10, 'count', 'a\u0102')
self.checkequal(0, 'a' * 10, 'count', 'a\U00100304')
self.checkequal(0, '\u0102' * 10, 'count', '\u0102\U00100304')
示例3: test_index
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_index(self):
string_tests.CommonTest.test_index(self)
self.checkequalnofix(0, 'abcdefghiabc', 'index', '')
self.checkequalnofix(3, 'abcdefghiabc', 'index', 'def')
self.checkequalnofix(0, 'abcdefghiabc', 'index', 'abc')
self.checkequalnofix(9, 'abcdefghiabc', 'index', 'abc', 1)
self.assertRaises(ValueError, 'abcdefghiabc'.index, 'hib')
self.assertRaises(ValueError, 'abcdefghiab'.index, 'abc', 1)
self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', 8)
self.assertRaises(ValueError, 'abcdefghi'.index, 'ghi', -1)
# test mixed kinds
self.checkequal(100, '\u0102' * 100 + 'a', 'index', 'a')
self.checkequal(100, '\U00100304' * 100 + 'a', 'index', 'a')
self.checkequal(100, '\U00100304' * 100 + '\u0102', 'index', '\u0102')
self.assertRaises(ValueError, ('a' * 100).index, '\u0102')
self.assertRaises(ValueError, ('a' * 100).index, '\U00100304')
self.assertRaises(ValueError, ('\u0102' * 100).index, '\U00100304')
self.checkequal(100, '\u0102' * 100 + 'a_', 'index', 'a_')
self.checkequal(100, '\U00100304' * 100 + 'a_', 'index', 'a_')
self.checkequal(100, '\U00100304' * 100 + '\u0102_', 'index', '\u0102_')
self.assertRaises(ValueError, ('a' * 100).index, 'a\u0102')
self.assertRaises(ValueError, ('a' * 100).index, 'a\U00100304')
self.assertRaises(ValueError, ('\u0102' * 100).index, '\u0102\U00100304')
示例4: test_rindex
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_rindex(self):
string_tests.CommonTest.test_rindex(self)
self.checkequalnofix(12, 'abcdefghiabc', 'rindex', '')
self.checkequalnofix(3, 'abcdefghiabc', 'rindex', 'def')
self.checkequalnofix(9, 'abcdefghiabc', 'rindex', 'abc')
self.checkequalnofix(0, 'abcdefghiabc', 'rindex', 'abc', 0, -1)
self.assertRaises(ValueError, 'abcdefghiabc'.rindex, 'hib')
self.assertRaises(ValueError, 'defghiabc'.rindex, 'def', 1)
self.assertRaises(ValueError, 'defghiabc'.rindex, 'abc', 0, -1)
self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, 8)
self.assertRaises(ValueError, 'abcdefghi'.rindex, 'ghi', 0, -1)
# test mixed kinds
self.checkequal(0, 'a' + '\u0102' * 100, 'rindex', 'a')
self.checkequal(0, 'a' + '\U00100304' * 100, 'rindex', 'a')
self.checkequal(0, '\u0102' + '\U00100304' * 100, 'rindex', '\u0102')
self.assertRaises(ValueError, ('a' * 100).rindex, '\u0102')
self.assertRaises(ValueError, ('a' * 100).rindex, '\U00100304')
self.assertRaises(ValueError, ('\u0102' * 100).rindex, '\U00100304')
self.checkequal(0, '_a' + '\u0102' * 100, 'rindex', '_a')
self.checkequal(0, '_a' + '\U00100304' * 100, 'rindex', '_a')
self.checkequal(0, '_\u0102' + '\U00100304' * 100, 'rindex', '_\u0102')
self.assertRaises(ValueError, ('a' * 100).rindex, '\u0102a')
self.assertRaises(ValueError, ('a' * 100).rindex, '\U00100304a')
self.assertRaises(ValueError, ('\u0102' * 100).rindex, '\U00100304\u0102')
示例5: test_replace
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_replace(self):
string_tests.CommonTest.test_replace(self)
# method call forwarded from str implementation because of unicode argument
self.checkequalnofix('one@two!three!', 'one!two!three!', 'replace', '!', '@', 1)
self.assertRaises(TypeError, 'replace'.replace, "r", 42)
# test mixed kinds
for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
left *= 9
right *= 9
for delim in ('c', '\u0102', '\U00010302'):
for repl in ('d', '\u0103', '\U00010303'):
self.checkequal(left + right,
left + right, 'replace', delim, repl)
self.checkequal(left + repl + right,
left + delim + right,
'replace', delim, repl)
self.checkequal(left + right,
left + right, 'replace', delim * 2, repl)
self.checkequal(left + repl + right,
left + delim * 2 + right,
'replace', delim * 2, repl)
示例6: test_lower
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_lower(self):
string_tests.CommonTest.test_lower(self)
self.assertEqual('\U00010427'.lower(), '\U0001044F')
self.assertEqual('\U00010427\U00010427'.lower(),
'\U0001044F\U0001044F')
self.assertEqual('\U00010427\U0001044F'.lower(),
'\U0001044F\U0001044F')
self.assertEqual('X\U00010427x\U0001044F'.lower(),
'x\U0001044Fx\U0001044F')
self.assertEqual('fi'.lower(), 'fi')
self.assertEqual('\u0130'.lower(), '\u0069\u0307')
# Special case for GREEK CAPITAL LETTER SIGMA U+03A3
self.assertEqual('\u03a3'.lower(), '\u03c3')
self.assertEqual('\u0345\u03a3'.lower(), '\u0345\u03c3')
self.assertEqual('A\u0345\u03a3'.lower(), 'a\u0345\u03c2')
self.assertEqual('A\u0345\u03a3a'.lower(), 'a\u0345\u03c3a')
self.assertEqual('A\u0345\u03a3'.lower(), 'a\u0345\u03c2')
self.assertEqual('A\u03a3\u0345'.lower(), 'a\u03c2\u0345')
self.assertEqual('\u03a3\u0345 '.lower(), '\u03c3\u0345 ')
self.assertEqual('\U0008fffe'.lower(), '\U0008fffe')
self.assertEqual('\u2177'.lower(), '\u2177')
示例7: test_upper
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_upper(self):
string_tests.CommonTest.test_upper(self)
self.assertEqual('\U0001044F'.upper(), '\U00010427')
self.assertEqual('\U0001044F\U0001044F'.upper(),
'\U00010427\U00010427')
self.assertEqual('\U00010427\U0001044F'.upper(),
'\U00010427\U00010427')
self.assertEqual('X\U00010427x\U0001044F'.upper(),
'X\U00010427X\U00010427')
self.assertEqual('fi'.upper(), 'FI')
self.assertEqual('\u0130'.upper(), '\u0130')
self.assertEqual('\u03a3'.upper(), '\u03a3')
self.assertEqual('ß'.upper(), 'SS')
self.assertEqual('\u1fd2'.upper(), '\u0399\u0308\u0300')
self.assertEqual('\U0008fffe'.upper(), '\U0008fffe')
self.assertEqual('\u2177'.upper(), '\u2167')
示例8: test_capitalize
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_capitalize(self):
string_tests.CommonTest.test_capitalize(self)
self.assertEqual('\U0001044F'.capitalize(), '\U00010427')
self.assertEqual('\U0001044F\U0001044F'.capitalize(),
'\U00010427\U0001044F')
self.assertEqual('\U00010427\U0001044F'.capitalize(),
'\U00010427\U0001044F')
self.assertEqual('\U0001044F\U00010427'.capitalize(),
'\U00010427\U0001044F')
self.assertEqual('X\U00010427x\U0001044F'.capitalize(),
'X\U0001044Fx\U0001044F')
self.assertEqual('h\u0130'.capitalize(), 'H\u0069\u0307')
exp = '\u0399\u0308\u0300\u0069\u0307'
self.assertEqual('\u1fd2\u0130'.capitalize(), exp)
self.assertEqual('finnish'.capitalize(), 'FInnish')
self.assertEqual('A\u0345\u03a3'.capitalize(), 'A\u0345\u03c2')
示例9: test_count
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_count(self):
string_tests.CommonTest.test_count(self)
# check mixed argument types
self.checkequalnofix(3, 'aaa', 'count', u'a')
self.checkequalnofix(0, 'aaa', 'count', u'b')
self.checkequalnofix(3, u'aaa', 'count', 'a')
self.checkequalnofix(0, u'aaa', 'count', 'b')
self.checkequalnofix(0, u'aaa', 'count', 'b')
self.checkequalnofix(1, u'aaa', 'count', 'a', -1)
self.checkequalnofix(3, u'aaa', 'count', 'a', -10)
self.checkequalnofix(2, u'aaa', 'count', 'a', 0, -1)
self.checkequalnofix(0, u'aaa', 'count', 'a', 0, -10)
示例10: test_rfind
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_rfind(self):
string_tests.CommonTest.test_rfind(self)
# check mixed argument types
self.checkequalnofix(9, 'abcdefghiabc', 'rfind', u'abc')
self.checkequalnofix(12, 'abcdefghiabc', 'rfind', u'')
self.checkequalnofix(12, u'abcdefghiabc', 'rfind', '')
示例11: test_index
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_index(self):
string_tests.CommonTest.test_index(self)
# check mixed argument types
for (t1, t2) in ((str, unicode), (unicode, str)):
self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2(''))
self.checkequalnofix(3, t1('abcdefghiabc'), 'index', t2('def'))
self.checkequalnofix(0, t1('abcdefghiabc'), 'index', t2('abc'))
self.checkequalnofix(9, t1('abcdefghiabc'), 'index', t2('abc'), 1)
self.assertRaises(ValueError, t1('abcdefghiabc').index, t2('hib'))
self.assertRaises(ValueError, t1('abcdefghiab').index, t2('abc'), 1)
self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), 8)
self.assertRaises(ValueError, t1('abcdefghi').index, t2('ghi'), -1)
示例12: test_rindex
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_rindex(self):
string_tests.CommonTest.test_rindex(self)
# check mixed argument types
for (t1, t2) in ((str, unicode), (unicode, str)):
self.checkequalnofix(12, t1('abcdefghiabc'), 'rindex', t2(''))
self.checkequalnofix(3, t1('abcdefghiabc'), 'rindex', t2('def'))
self.checkequalnofix(9, t1('abcdefghiabc'), 'rindex', t2('abc'))
self.checkequalnofix(0, t1('abcdefghiabc'), 'rindex', t2('abc'), 0, -1)
self.assertRaises(ValueError, t1('abcdefghiabc').rindex, t2('hib'))
self.assertRaises(ValueError, t1('defghiabc').rindex, t2('def'), 1)
self.assertRaises(ValueError, t1('defghiabc').rindex, t2('abc'), 0, -1)
self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('ghi'), 0, 8)
self.assertRaises(ValueError, t1('abcdefghi').rindex, t2('ghi'), 0, -1)
示例13: test_split
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_split(self):
string_tests.CommonTest.test_split(self)
# Mixed arguments
self.checkequalnofix([u'a', u'b', u'c', u'd'], u'a//b//c//d', 'split', '//')
self.checkequalnofix([u'a', u'b', u'c', u'd'], 'a//b//c//d', 'split', u'//')
self.checkequalnofix([u'endcase ', u''], u'endcase test', 'split', 'test')
示例14: test_replace
# 需要導入模塊: from test import string_tests [as 別名]
# 或者: from test.string_tests import CommonTest [as 別名]
def test_replace(self):
string_tests.CommonTest.test_replace(self)
# method call forwarded from str implementation because of unicode argument
self.checkequalnofix(u'one@two!three!', 'one!two!three!', 'replace', u'!', u'@', 1)
self.assertRaises(TypeError, 'replace'.replace, u"r", 42)