Exemple #1
0
    def test_join(self):
        self.assert_(strop.join(["a", "b", "c", "d"]) == "a b c d")
        self.assert_(strop.join(("a", "b", "c", "d"), "") == "abcd")
        self.assert_(strop.join(Sequence()) == "w x y z")

        # try a few long ones
        self.assert_(strop.join(["x" * 100] * 100, ":") == (("x" * 100) + ":") * 99 + "x" * 100)
        self.assert_(strop.join(("x" * 100,) * 100, ":") == (("x" * 100) + ":") * 99 + "x" * 100)
    def test_join(self):
        self.assertTrue(strop.join(['a', 'b', 'c', 'd']) == 'a b c d')
        self.assertTrue(strop.join(('a', 'b', 'c', 'd'), '') == 'abcd')
        self.assertTrue(strop.join(Sequence()) == 'w x y z')

        # try a few long ones
        self.assertTrue(strop.join(['x' * 100] * 100, ':')
                     == (('x' * 100) + ":") * 99 + "x" * 100)
        self.assertTrue(strop.join(('x' * 100,) * 100, ':')
                     == (('x' * 100) + ":") * 99 + "x" * 100)
    def test_join(self):
        self.assertTrue(strop.join(['a', 'b', 'c', 'd']) == 'a b c d')
        self.assertTrue(strop.join(('a', 'b', 'c', 'd'), '') == 'abcd')
        self.assertTrue(strop.join(Sequence()) == 'w x y z')

        # try a few long ones
        self.assertTrue(strop.join(['x' * 100] * 100, ':')
                     == (('x' * 100) + ":") * 99 + "x" * 100)
        self.assertTrue(strop.join(('x' * 100,) * 100, ':')
                     == (('x' * 100) + ":") * 99 + "x" * 100)
 def test_stropjoin_huge_tup(self, size):
     a = "A" * size
     try:
         r = strop.join((a, a), a)
     except OverflowError:
         pass # acceptable on 32-bit
     else:
         self.assertEquals(len(r), len(a) * 3)
 def test_stropjoin_huge_list(self, size):
     a = "A" * size
     try:
         r = strop.join([a, a], a)
     except OverflowError:
         pass
     else:
         self.assertEquals(len(r), len(a) * 3)
 def test_stropjoin_huge_tup(self, size):
     a = "A" * size
     try:
         r = strop.join((a, a), a)
     except OverflowError:
         pass  # acceptable on 32-bit
     else:
         self.assertEquals(len(r), len(a) * 3)
 def test_stropjoin_huge_list(self, size):
     a = "A" * size
     try:
         r = strop.join([a, a], a)
     except OverflowError:
         pass
     else:
         self.assertEquals(len(r), len(a) * 3)
Exemple #8
0
import warnings
test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 4)
test('split', 'a b c d', ['a', 'b', 'c', 'd'], None, 0)
test('split', 'a  b  c  d', ['a', 'b', 'c  d'], None, 2)

# join now works with any sequence type
class Sequence:
    def __init__(self): self.seq = 'wxyz'
    def __len__(self): return len(self.seq)
    def __getitem__(self, i): return self.seq[i]

test('join', ['a', 'b', 'c', 'd'], 'a b c d')
test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
test('join', Sequence(), 'w x y z')

# try a few long ones
print strop.join(['x' * 100] * 100, ':')
print strop.join(('x' * 100,) * 100, ':')

test('strip', '   hello   ', 'hello')
test('lstrip', '   hello   ', 'hello   ')
test('rstrip', '   hello   ', '   hello')

test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')

test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
# CAUTION:  a replace count of 0 means infinity only to strop, not to the
# string .replace() method or to the string.replace() function.
Exemple #10
0
try:
    corehandle = win32api.RegOpenKey(pythonhandle, corekey)
except win32api.error, msg:
    corehandle = win32api.RegCreateKey(pythonhandle, corekey)
path = []
pwd = nt.getcwd()
for i in ["Bin",
	  "Lib",
	  "Lib\\win",
	  "Lib\\tkinter",
	  "Lib\\test",
	  "Lib\\dos_8x3"]:
    i = pwd + "\\" + i
    path.append(i)
sys.path[1:] = path
pathvalue = strop.join(path, ";")
#print "Setting PythonPath to", pathvalue
win32api.RegSetValue(corehandle, "PythonPath", win32con.REG_SZ, pathvalue)
win32api.RegCloseKey(corehandle)
#listtree(pythonhandle)
win32api.RegCloseKey(pythonhandle)

print "Registering uninstaller..."
pwd = nt.getcwd()
uninstaller = '"%s\\uninstall.bat" "%s"' % (pwd, pwd)
uninstallkey = \
 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Python"+sys.winver
try:
    uihandle = win32api.RegOpenKey(roothandle, uninstallkey)
except win32api.error, msg:
    uihandle = win32api.RegCreateKey(roothandle, uninstallkey)
Exemple #11
0
    def __init__(self):
        self.seq = 'wxyz'

    def __len__(self):
        return len(self.seq)

    def __getitem__(self, i):
        return self.seq[i]


test('join', ['a', 'b', 'c', 'd'], 'a b c d')
test('join', ('a', 'b', 'c', 'd'), 'abcd', '')
test('join', Sequence(), 'w x y z')

# try a few long ones
print strop.join(['x' * 100] * 100, ':')
print strop.join(('x' * 100, ) * 100, ':')

test('strip', '   hello   ', 'hello')
test('lstrip', '   hello   ', 'hello   ')
test('rstrip', '   hello   ', '   hello')

test('swapcase', 'HeLLo cOmpUteRs', 'hEllO CoMPuTErS')
test('translate', 'xyzabcdef', 'xyzxyz', transtable, 'def')

test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 0)
test('replace', 'one!two!three!', 'one@two@three@', '!', '@')
Exemple #12
0
import warnings