2 warnings
.filterwarnings("ignore", "", DeprecationWarning, __name__
)
3 warnings
.filterwarnings("ignore", "", DeprecationWarning, "unittest")
9 class StropFunctionTestCase(unittest
.TestCase
):
12 self
.assert_(strop
.atoi(" 1 ") == 1)
13 self
.assertRaises(ValueError, strop
.atoi
, " 1x")
14 self
.assertRaises(ValueError, strop
.atoi
, " x1 ")
17 self
.assert_(strop
.atol(" 1 ") == 1L)
18 self
.assertRaises(ValueError, strop
.atol
, " 1x")
19 self
.assertRaises(ValueError, strop
.atol
, " x1 ")
22 self
.assert_(strop
.atof(" 1 ") == 1.0)
23 self
.assertRaises(ValueError, strop
.atof
, " 1x")
24 self
.assertRaises(ValueError, strop
.atof
, " x1 ")
26 def test_capitalize(self
):
27 self
.assert_(strop
.capitalize(" hello ") == " hello ")
28 self
.assert_(strop
.capitalize("hello ") == "Hello ")
31 self
.assert_(strop
.find("abcdefghiabc", "abc") == 0)
32 self
.assert_(strop
.find("abcdefghiabc", "abc", 1) == 9)
33 self
.assert_(strop
.find("abcdefghiabc", "def", 4) == -1)
36 self
.assert_(strop
.rfind("abcdefghiabc", "abc") == 9)
39 self
.assert_(strop
.lower("HeLLo") == "hello")
42 self
.assert_(strop
.upper("HeLLo") == "HELLO")
44 def test_swapcase(self
):
45 self
.assert_(strop
.swapcase("HeLLo cOmpUteRs") == "hEllO CoMPuTErS")
48 self
.assert_(strop
.strip(" \t\n hello \t\n ") == "hello")
50 def test_lstrip(self
):
51 self
.assert_(strop
.lstrip(" \t\n hello \t\n ") == "hello \t\n ")
53 def test_rstrip(self
):
54 self
.assert_(strop
.rstrip(" \t\n hello \t\n ") == " \t\n hello")
56 def test_replace(self
):
57 replace
= strop
.replace
58 self
.assert_(replace("one!two!three!", '!', '@', 1)
60 self
.assert_(replace("one!two!three!", '!', '@', 2)
62 self
.assert_(replace("one!two!three!", '!', '@', 3)
64 self
.assert_(replace("one!two!three!", '!', '@', 4)
67 # CAUTION: a replace count of 0 means infinity only to strop,
68 # not to the string .replace() method or to the
69 # string.replace() function.
71 self
.assert_(replace("one!two!three!", '!', '@', 0)
73 self
.assert_(replace("one!two!three!", '!', '@')
75 self
.assert_(replace("one!two!three!", 'x', '@')
77 self
.assert_(replace("one!two!three!", 'x', '@', 2)
82 self
.assert_(split("this is the split function")
83 == ['this', 'is', 'the', 'split', 'function'])
84 self
.assert_(split("a|b|c|d", '|') == ['a', 'b', 'c', 'd'])
85 self
.assert_(split("a|b|c|d", '|', 2) == ['a', 'b', 'c|d'])
86 self
.assert_(split("a b c d", None, 1) == ['a', 'b c d'])
87 self
.assert_(split("a b c d", None, 2) == ['a', 'b', 'c d'])
88 self
.assert_(split("a b c d", None, 3) == ['a', 'b', 'c', 'd'])
89 self
.assert_(split("a b c d", None, 4) == ['a', 'b', 'c', 'd'])
90 self
.assert_(split("a b c d", None, 0) == ['a', 'b', 'c', 'd'])
91 self
.assert_(split("a b c d", None, 2) == ['a', 'b', 'c d'])
94 self
.assert_(strop
.join(['a', 'b', 'c', 'd']) == 'a b c d')
95 self
.assert_(strop
.join(('a', 'b', 'c', 'd'), '') == 'abcd')
96 self
.assert_(strop
.join(Sequence()) == 'w x y z')
99 self
.assert_(strop
.join(['x' * 100] * 100, ':')
100 == (('x' * 100) + ":") * 99 + "x" * 100)
101 self
.assert_(strop
.join(('x' * 100,) * 100, ':')
102 == (('x' * 100) + ":") * 99 + "x" * 100)
104 def test_maketrans(self
):
105 self
.assert_(strop
.maketrans("abc", "xyz") == transtable
)
106 self
.assertRaises(ValueError, strop
.maketrans
, "abc", "xyzq")
108 def test_translate(self
):
109 self
.assert_(strop
.translate("xyzabcdef", transtable
, "def")
112 def test_data_attributes(self
):
118 transtable
= '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377'
121 # join() now works with any sequence type.
123 def __init__(self
): self
.seq
= 'wxyz'
124 def __len__(self
): return len(self
.seq
)
125 def __getitem__(self
, i
): return self
.seq
[i
]
128 test_support
.run_unittest(StropFunctionTestCase
)