mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Update the code to better reflect recommended style:
Use != instead of <> since <> is documented as "obsolescent". Use "is" and "is not" when comparing with None or type objects.
This commit is contained in:
parent
63596aeb33
commit
132dce2246
55 changed files with 520 additions and 519 deletions
|
@ -241,7 +241,7 @@ class CygwinCCompiler (UnixCCompiler):
|
||||||
objects.append(def_file)
|
objects.append(def_file)
|
||||||
|
|
||||||
#end: if ((export_symbols is not None) and
|
#end: if ((export_symbols is not None) and
|
||||||
# (target_desc <> self.EXECUTABLE or self.linker_dll == "gcc")):
|
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
|
||||||
|
|
||||||
# who wants symbols and a many times larger output file
|
# who wants symbols and a many times larger output file
|
||||||
# should explicitly switch the debug mode on
|
# should explicitly switch the debug mode on
|
||||||
|
|
|
@ -28,7 +28,7 @@ class Para:
|
||||||
# Each word should be a 7-tuple:
|
# Each word should be a 7-tuple:
|
||||||
# (font, text, width, space, stretch, ascent, descent)
|
# (font, text, width, space, stretch, ascent, descent)
|
||||||
def addword(self, d, font, text, space, stretch):
|
def addword(self, d, font, text, space, stretch):
|
||||||
if font <> None:
|
if font is not None:
|
||||||
d.setfont(font)
|
d.setfont(font)
|
||||||
width = d.textwidth(text)
|
width = d.textwidth(text)
|
||||||
ascent = d.baseline()
|
ascent = d.baseline()
|
||||||
|
@ -50,7 +50,7 @@ class Para:
|
||||||
def getlength(self):
|
def getlength(self):
|
||||||
total = 0
|
total = 0
|
||||||
for word in self.words:
|
for word in self.words:
|
||||||
if type(word) <> Int:
|
if type(word) is not Int:
|
||||||
total = total + word[2] + word[3]
|
total = total + word[2] + word[3]
|
||||||
return total
|
return total
|
||||||
#
|
#
|
||||||
|
@ -63,7 +63,7 @@ class Para:
|
||||||
as, de = 1, 0
|
as, de = 1, 0
|
||||||
for i in range(len(self.words)):
|
for i in range(len(self.words)):
|
||||||
word = self.words[i]
|
word = self.words[i]
|
||||||
if type(word) == Int: continue
|
if type(word) is Int: continue
|
||||||
(fo, te, wi, sp, st, as, de) = word
|
(fo, te, wi, sp, st, as, de) = word
|
||||||
self.words[i] = (fo, te, wi, sp, 0, as, de)
|
self.words[i] = (fo, te, wi, sp, 0, as, de)
|
||||||
total = total + wi + sp
|
total = total + wi + sp
|
||||||
|
@ -99,7 +99,7 @@ class Para:
|
||||||
j = i
|
j = i
|
||||||
while i < n:
|
while i < n:
|
||||||
word = words[i]
|
word = words[i]
|
||||||
if type(word) == Int:
|
if type(word) is Int:
|
||||||
if word > 0 and width >= avail:
|
if word > 0 and width >= avail:
|
||||||
break
|
break
|
||||||
i = i+1
|
i = i+1
|
||||||
|
@ -107,7 +107,7 @@ class Para:
|
||||||
fo, te, wi, sp, st, as, de = word
|
fo, te, wi, sp, st, as, de = word
|
||||||
if width + wi > avail and width > 0 and wi > 0:
|
if width + wi > avail and width > 0 and wi > 0:
|
||||||
break
|
break
|
||||||
if fo <> None:
|
if fo is not None:
|
||||||
lastfont = fo
|
lastfont = fo
|
||||||
if width == 0:
|
if width == 0:
|
||||||
firstfont = fo
|
firstfont = fo
|
||||||
|
@ -119,7 +119,7 @@ class Para:
|
||||||
ascent = max(ascent, as)
|
ascent = max(ascent, as)
|
||||||
descent = max(descent, de)
|
descent = max(descent, de)
|
||||||
i = i+1
|
i = i+1
|
||||||
while i > j and type(words[i-1]) == Int and \
|
while i > j and type(words[i-1]) is Int and \
|
||||||
words[i-1] > 0: i = i-1
|
words[i-1] > 0: i = i-1
|
||||||
width = width - lsp
|
width = width - lsp
|
||||||
if i < n:
|
if i < n:
|
||||||
|
@ -152,10 +152,10 @@ class Para:
|
||||||
v2 = v + ascent + descent
|
v2 = v + ascent + descent
|
||||||
for j in range(i, i+wordcount):
|
for j in range(i, i+wordcount):
|
||||||
word = self.words[j]
|
word = self.words[j]
|
||||||
if type(word) == Int:
|
if type(word) is Int:
|
||||||
ok = anchorfunc(self, tuple, word, \
|
ok = anchorfunc(self, tuple, word, \
|
||||||
h, v)
|
h, v)
|
||||||
if ok <> None: return ok
|
if ok is not None: return ok
|
||||||
continue
|
continue
|
||||||
fo, te, wi, sp, st, as, de = word
|
fo, te, wi, sp, st, as, de = word
|
||||||
if extra > 0 and stretch > 0:
|
if extra > 0 and stretch > 0:
|
||||||
|
@ -167,7 +167,7 @@ class Para:
|
||||||
h2 = h + wi + sp + ex
|
h2 = h + wi + sp + ex
|
||||||
ok = wordfunc(self, tuple, word, h, v, \
|
ok = wordfunc(self, tuple, word, h, v, \
|
||||||
h2, v2, (j==i), (j==i+wordcount-1))
|
h2, v2, (j==i), (j==i+wordcount-1))
|
||||||
if ok <> None: return ok
|
if ok is not None: return ok
|
||||||
h = h2
|
h = h2
|
||||||
v = v2
|
v = v2
|
||||||
i = i + wordcount
|
i = i + wordcount
|
||||||
|
@ -177,7 +177,7 @@ class Para:
|
||||||
# given by (left, top, right) with an unspecified bottom.
|
# given by (left, top, right) with an unspecified bottom.
|
||||||
# Return the computed bottom of the text.
|
# Return the computed bottom of the text.
|
||||||
def render(self, d, left, top, right):
|
def render(self, d, left, top, right):
|
||||||
if self.width <> right-left:
|
if self.width != right-left:
|
||||||
self.layout(right-left)
|
self.layout(right-left)
|
||||||
self.left = left
|
self.left = left
|
||||||
self.top = top
|
self.top = top
|
||||||
|
@ -193,7 +193,7 @@ class Para:
|
||||||
return self.bottom
|
return self.bottom
|
||||||
#
|
#
|
||||||
def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
|
def _renderword(self, tuple, word, h, v, h2, v2, isfirst, islast):
|
||||||
if word[0] <> None: self.d.setfont(word[0])
|
if word[0] is not None: self.d.setfont(word[0])
|
||||||
baseline = v + tuple[5]
|
baseline = v + tuple[5]
|
||||||
self.d.text((h, baseline - word[5]), word[1])
|
self.d.text((h, baseline - word[5]), word[1])
|
||||||
if self.anchorid > 0:
|
if self.anchorid > 0:
|
||||||
|
@ -229,7 +229,7 @@ class Para:
|
||||||
def extract(self):
|
def extract(self):
|
||||||
text = ''
|
text = ''
|
||||||
for w in self.words:
|
for w in self.words:
|
||||||
if type(w) <> Int:
|
if type(w) is not Int:
|
||||||
word = w[1]
|
word = w[1]
|
||||||
if w[3]: word = word + ' '
|
if w[3]: word = word + ' '
|
||||||
text = text + word
|
text = text + word
|
||||||
|
@ -254,14 +254,14 @@ class Para:
|
||||||
#
|
#
|
||||||
def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
def _whereisword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
||||||
fo, te, wi, sp, st, as, de = word
|
fo, te, wi, sp, st, as, de = word
|
||||||
if fo <> None: self.lastfont = fo
|
if fo is not None: self.lastfont = fo
|
||||||
h = h1
|
h = h1
|
||||||
if isfirst: h1 = 0
|
if isfirst: h1 = 0
|
||||||
if islast: h2 = 999999
|
if islast: h2 = 999999
|
||||||
if not (v1 <= self.mousev <= v2 and h1 <= self.mouseh <= h2):
|
if not (v1 <= self.mousev <= v2 and h1 <= self.mouseh <= h2):
|
||||||
self.charcount = self.charcount + len(te) + (sp > 0)
|
self.charcount = self.charcount + len(te) + (sp > 0)
|
||||||
return
|
return
|
||||||
if self.lastfont <> None:
|
if self.lastfont is not None:
|
||||||
self.d.setfont(self.lastfont)
|
self.d.setfont(self.lastfont)
|
||||||
cc = 0
|
cc = 0
|
||||||
for c in te:
|
for c in te:
|
||||||
|
@ -295,7 +295,7 @@ class Para:
|
||||||
self.__class__._screenposanchor)
|
self.__class__._screenposanchor)
|
||||||
finally:
|
finally:
|
||||||
self.d = None
|
self.d = None
|
||||||
if ok == None:
|
if ok is None:
|
||||||
ascent, descent = self.lines[-1][5:7]
|
ascent, descent = self.lines[-1][5:7]
|
||||||
ok = self.right, self.bottom - ascent - descent, \
|
ok = self.right, self.bottom - ascent - descent, \
|
||||||
self.bottom - descent, self.bottom
|
self.bottom - descent, self.bottom
|
||||||
|
@ -303,7 +303,7 @@ class Para:
|
||||||
#
|
#
|
||||||
def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
def _screenposword(self, tuple, word, h1, v1, h2, v2, isfirst, islast):
|
||||||
fo, te, wi, sp, st, as, de = word
|
fo, te, wi, sp, st, as, de = word
|
||||||
if fo <> None: self.lastfont = fo
|
if fo is not None: self.lastfont = fo
|
||||||
cc = len(te) + (sp > 0)
|
cc = len(te) + (sp > 0)
|
||||||
if self.pos > cc:
|
if self.pos > cc:
|
||||||
self.pos = self.pos - cc
|
self.pos = self.pos - cc
|
||||||
|
@ -324,11 +324,11 @@ class Para:
|
||||||
# if pos2 is None, the end is implied.
|
# if pos2 is None, the end is implied.
|
||||||
# Undoes its own effect when called again with the same arguments
|
# Undoes its own effect when called again with the same arguments
|
||||||
def invert(self, d, pos1, pos2):
|
def invert(self, d, pos1, pos2):
|
||||||
if pos1 == None:
|
if pos1 is None:
|
||||||
pos1 = self.left, self.top, self.top, self.top
|
pos1 = self.left, self.top, self.top, self.top
|
||||||
else:
|
else:
|
||||||
pos1 = self.screenpos(d, pos1)
|
pos1 = self.screenpos(d, pos1)
|
||||||
if pos2 == None:
|
if pos2 is None:
|
||||||
pos2 = self.right, self.bottom,self.bottom,self.bottom
|
pos2 = self.right, self.bottom,self.bottom,self.bottom
|
||||||
else:
|
else:
|
||||||
pos2 = self.screenpos(d, pos2)
|
pos2 = self.screenpos(d, pos2)
|
||||||
|
|
|
@ -16,13 +16,13 @@ def cmp(f1, f2, shallow=1):
|
||||||
Return 1 for identical files, 0 for different.
|
Return 1 for identical files, 0 for different.
|
||||||
Raise exceptions if either file could not be statted, read, etc."""
|
Raise exceptions if either file could not be statted, read, etc."""
|
||||||
s1, s2 = sig(os.stat(f1)), sig(os.stat(f2))
|
s1, s2 = sig(os.stat(f1)), sig(os.stat(f2))
|
||||||
if s1[0] <> 8 or s2[0] <> 8:
|
if s1[0] != 8 or s2[0] != 8:
|
||||||
# Either is a not a plain file -- always report as different
|
# Either is a not a plain file -- always report as different
|
||||||
return 0
|
return 0
|
||||||
if shallow and s1 == s2:
|
if shallow and s1 == s2:
|
||||||
# type, size & mtime match -- report same
|
# type, size & mtime match -- report same
|
||||||
return 1
|
return 1
|
||||||
if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother
|
if s1[:2] != s2[:2]: # Types or sizes differ, don't bother
|
||||||
# types or sizes differ -- report different
|
# types or sizes differ -- report different
|
||||||
return 0
|
return 0
|
||||||
# same type and size -- look in the cache
|
# same type and size -- look in the cache
|
||||||
|
@ -59,5 +59,5 @@ def do_cmp(f1, f2):
|
||||||
while 1:
|
while 1:
|
||||||
b1 = fp1.read(bufsize)
|
b1 = fp1.read(bufsize)
|
||||||
b2 = fp2.read(bufsize)
|
b2 = fp2.read(bufsize)
|
||||||
if b1 <> b2: return 0
|
if b1 != b2: return 0
|
||||||
if not b1: return 1
|
if not b1: return 1
|
||||||
|
|
|
@ -30,7 +30,7 @@ def cmp(f1, f2, shallow=1):
|
||||||
if shallow and s1 == s2:
|
if shallow and s1 == s2:
|
||||||
# type, size & mtime match -- report same
|
# type, size & mtime match -- report same
|
||||||
return 1
|
return 1
|
||||||
if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother
|
if s1[:2] != s2[:2]: # Types or sizes differ, don't bother
|
||||||
# types or sizes differ -- report different
|
# types or sizes differ -- report different
|
||||||
return 0
|
return 0
|
||||||
# same type and size -- look in the cache
|
# same type and size -- look in the cache
|
||||||
|
@ -60,5 +60,5 @@ def do_cmp(f1, f2):
|
||||||
while 1:
|
while 1:
|
||||||
b1 = fp1.read(bufsize)
|
b1 = fp1.read(bufsize)
|
||||||
b2 = fp2.read(bufsize)
|
b2 = fp2.read(bufsize)
|
||||||
if b1 <> b2: return 0
|
if b1 != b2: return 0
|
||||||
if not b1: return 1
|
if not b1: return 1
|
||||||
|
|
|
@ -70,7 +70,7 @@ class dircmp:
|
||||||
if ok:
|
if ok:
|
||||||
a_type = S_IFMT(a_stat[ST_MODE])
|
a_type = S_IFMT(a_stat[ST_MODE])
|
||||||
b_type = S_IFMT(b_stat[ST_MODE])
|
b_type = S_IFMT(b_stat[ST_MODE])
|
||||||
if a_type <> b_type:
|
if a_type != b_type:
|
||||||
self.common_funny.append(x)
|
self.common_funny.append(x)
|
||||||
elif S_ISDIR(a_type):
|
elif S_ISDIR(a_type):
|
||||||
self.common_dirs.append(x)
|
self.common_dirs.append(x)
|
||||||
|
@ -189,7 +189,8 @@ def demo():
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
options, args = getopt.getopt(sys.argv[1:], 'r')
|
options, args = getopt.getopt(sys.argv[1:], 'r')
|
||||||
if len(args) <> 2: raise getopt.error, 'need exactly two args'
|
if len(args) != 2:
|
||||||
|
raise getopt.error, 'need exactly two args'
|
||||||
dd = dircmp().new(args[0], args[1])
|
dd = dircmp().new(args[0], args[1])
|
||||||
dd.run()
|
dd.run()
|
||||||
if ('-r', '') in options:
|
if ('-r', '') in options:
|
||||||
|
|
|
@ -68,20 +68,20 @@ class SavingBackEnd(NullBackEnd):
|
||||||
for i in range(len(self.paralist)):
|
for i in range(len(self.paralist)):
|
||||||
p = self.paralist[i]
|
p = self.paralist[i]
|
||||||
result = p.whereis(d, h, v)
|
result = p.whereis(d, h, v)
|
||||||
if result <> None:
|
if result is not None:
|
||||||
return i, result
|
return i, result
|
||||||
return None
|
return None
|
||||||
#
|
#
|
||||||
def roundtowords(self, long1, long2):
|
def roundtowords(self, long1, long2):
|
||||||
i, offset = long1
|
i, offset = long1
|
||||||
text = self.paralist[i].extract()
|
text = self.paralist[i].extract()
|
||||||
while offset > 0 and text[offset-1] <> ' ': offset = offset-1
|
while offset > 0 and text[offset-1] != ' ': offset = offset-1
|
||||||
long1 = i, offset
|
long1 = i, offset
|
||||||
#
|
#
|
||||||
i, offset = long2
|
i, offset = long2
|
||||||
text = self.paralist[i].extract()
|
text = self.paralist[i].extract()
|
||||||
n = len(text)
|
n = len(text)
|
||||||
while offset < n-1 and text[offset] <> ' ': offset = offset+1
|
while offset < n-1 and text[offset] != ' ': offset = offset+1
|
||||||
long2 = i, offset
|
long2 = i, offset
|
||||||
#
|
#
|
||||||
return long1, long2
|
return long1, long2
|
||||||
|
@ -159,7 +159,7 @@ class BaseFormatter:
|
||||||
return Para.Para()
|
return Para.Para()
|
||||||
#
|
#
|
||||||
def setfont(self, font):
|
def setfont(self, font):
|
||||||
if font == None: return
|
if font is None: return
|
||||||
self.font = self.nextfont = font
|
self.font = self.nextfont = font
|
||||||
d = self.d
|
d = self.d
|
||||||
d.setfont(font)
|
d.setfont(font)
|
||||||
|
@ -193,7 +193,7 @@ class BaseFormatter:
|
||||||
if self.para:
|
if self.para:
|
||||||
self.b.addpara(self.para)
|
self.b.addpara(self.para)
|
||||||
self.para = None
|
self.para = None
|
||||||
if self.font <> None:
|
if self.font is not None:
|
||||||
self.d.setfont(self.font)
|
self.d.setfont(self.font)
|
||||||
self.nospace = 1
|
self.nospace = 1
|
||||||
#
|
#
|
||||||
|
@ -338,8 +338,8 @@ def finalize(para):
|
||||||
para.words.append(('r', '', 0, 0, 0, 0)) # temporary, deleted at end
|
para.words.append(('r', '', 0, 0, 0, 0)) # temporary, deleted at end
|
||||||
for i in range(len(para.words)):
|
for i in range(len(para.words)):
|
||||||
fo, te, wi = para.words[i][:3]
|
fo, te, wi = para.words[i][:3]
|
||||||
if fo <> None: curfont = fo
|
if fo is not None: curfont = fo
|
||||||
if curfont <> oldfont:
|
if curfont != oldfont:
|
||||||
if closechar.has_key(oldfont):
|
if closechar.has_key(oldfont):
|
||||||
c = closechar[oldfont]
|
c = closechar[oldfont]
|
||||||
j = i-1
|
j = i-1
|
||||||
|
@ -430,7 +430,7 @@ class StdwinBackEnd(SavingBackEnd):
|
||||||
pos1 = long1[:3]
|
pos1 = long1[:3]
|
||||||
pos2 = long2[:3]
|
pos2 = long2[:3]
|
||||||
new = pos1, pos2
|
new = pos1, pos2
|
||||||
if new <> self.selection:
|
if new != self.selection:
|
||||||
d = self.window.begindrawing()
|
d = self.window.begindrawing()
|
||||||
if self.selection:
|
if self.selection:
|
||||||
self.invert(d, self.selection)
|
self.invert(d, self.selection)
|
||||||
|
@ -462,7 +462,7 @@ class StdwinBackEnd(SavingBackEnd):
|
||||||
#
|
#
|
||||||
def search(self, prog):
|
def search(self, prog):
|
||||||
import re, string
|
import re, string
|
||||||
if type(prog) == type(''):
|
if type(prog) is type(''):
|
||||||
prog = re.compile(string.lower(prog))
|
prog = re.compile(string.lower(prog))
|
||||||
if self.selection:
|
if self.selection:
|
||||||
iold = self.selection[0][0]
|
iold = self.selection[0][0]
|
||||||
|
@ -551,7 +551,7 @@ class GLFontCache:
|
||||||
self.fontcache[fontkey] = \
|
self.fontcache[fontkey] = \
|
||||||
self.fontcache[key] = handle
|
self.fontcache[key] = handle
|
||||||
self.fontkey = fontkey
|
self.fontkey = fontkey
|
||||||
if self.fonthandle <> handle:
|
if self.fonthandle != handle:
|
||||||
self.fonthandle = handle
|
self.fonthandle = handle
|
||||||
self.fontinfo = handle.getfontinfo()
|
self.fontinfo = handle.getfontinfo()
|
||||||
handle.setfont()
|
handle.setfont()
|
||||||
|
@ -582,7 +582,7 @@ class GLWriter(GLFontCache):
|
||||||
def setfont(self, fontkey):
|
def setfont(self, fontkey):
|
||||||
oldhandle = self.fonthandle
|
oldhandle = self.fonthandle
|
||||||
GLFontCache.setfont(fontkey)
|
GLFontCache.setfont(fontkey)
|
||||||
if self.fonthandle <> oldhandle:
|
if self.fonthandle != oldhandle:
|
||||||
handle.setfont()
|
handle.setfont()
|
||||||
|
|
||||||
|
|
||||||
|
@ -612,7 +612,7 @@ class GLBackEnd(SavingBackEnd):
|
||||||
import gl
|
import gl
|
||||||
gl.winset(self.wid)
|
gl.winset(self.wid)
|
||||||
width = gl.getsize()[1]
|
width = gl.getsize()[1]
|
||||||
if width <> self.width:
|
if width != self.width:
|
||||||
setdocsize = 1
|
setdocsize = 1
|
||||||
self.width = width
|
self.width = width
|
||||||
for p in self.paralist:
|
for p in self.paralist:
|
||||||
|
|
|
@ -73,7 +73,7 @@ def showline(filename, lineno, line, prog):
|
||||||
else:
|
else:
|
||||||
prefix = ' ' * len(prefix)
|
prefix = ' ' * len(prefix)
|
||||||
for c in line:
|
for c in line:
|
||||||
if c <> '\t': c = ' '
|
if c != '\t': c = ' '
|
||||||
prefix = prefix + c
|
prefix = prefix + c
|
||||||
if start == end: prefix = prefix + '\\'
|
if start == end: prefix = prefix + '\\'
|
||||||
else: prefix = prefix + '^'*(end-start)
|
else: prefix = prefix + '^'*(end-start)
|
||||||
|
|
|
@ -25,7 +25,7 @@ def pack(outfp, file, name):
|
||||||
while 1:
|
while 1:
|
||||||
line = fp.readline()
|
line = fp.readline()
|
||||||
if not line: break
|
if not line: break
|
||||||
if line[-1:] <> '\n':
|
if line[-1:] != '\n':
|
||||||
line = line + '\n'
|
line = line + '\n'
|
||||||
outfp.write('X' + line)
|
outfp.write('X' + line)
|
||||||
outfp.write('!\n')
|
outfp.write('!\n')
|
||||||
|
|
|
@ -23,7 +23,7 @@ def browser(tb):
|
||||||
ptr = len(tblist)-1
|
ptr = len(tblist)-1
|
||||||
tb = tblist[ptr]
|
tb = tblist[ptr]
|
||||||
while 1:
|
while 1:
|
||||||
if tb <> tblist[ptr]:
|
if tb != tblist[ptr]:
|
||||||
tb = tblist[ptr]
|
tb = tblist[ptr]
|
||||||
print `ptr` + ':',
|
print `ptr` + ':',
|
||||||
printtbheader(tb)
|
printtbheader(tb)
|
||||||
|
@ -76,11 +76,11 @@ def browserexec(tb, cmd):
|
||||||
except:
|
except:
|
||||||
t, v = sys.exc_info()[:2]
|
t, v = sys.exc_info()[:2]
|
||||||
print '*** Exception:',
|
print '*** Exception:',
|
||||||
if type(t) == type(''):
|
if type(t) is type(''):
|
||||||
print t,
|
print t,
|
||||||
else:
|
else:
|
||||||
print t.__name__,
|
print t.__name__,
|
||||||
if v <> None:
|
if v is not None:
|
||||||
print ':', v,
|
print ':', v,
|
||||||
print
|
print
|
||||||
print 'Type help to get help.'
|
print 'Type help to get help.'
|
||||||
|
@ -127,24 +127,24 @@ def printsymbols(d):
|
||||||
print
|
print
|
||||||
|
|
||||||
def printobject(v, maxlevel):
|
def printobject(v, maxlevel):
|
||||||
if v == None:
|
if v is None:
|
||||||
print 'None',
|
print 'None',
|
||||||
elif type(v) in (type(0), type(0.0)):
|
elif type(v) in (type(0), type(0.0)):
|
||||||
print v,
|
print v,
|
||||||
elif type(v) == type(''):
|
elif type(v) is type(''):
|
||||||
if len(v) > 20:
|
if len(v) > 20:
|
||||||
print `v[:17] + '...'`,
|
print `v[:17] + '...'`,
|
||||||
else:
|
else:
|
||||||
print `v`,
|
print `v`,
|
||||||
elif type(v) == type(()):
|
elif type(v) is type(()):
|
||||||
print '(',
|
print '(',
|
||||||
printlist(v, maxlevel)
|
printlist(v, maxlevel)
|
||||||
print ')',
|
print ')',
|
||||||
elif type(v) == type([]):
|
elif type(v) is type([]):
|
||||||
print '[',
|
print '[',
|
||||||
printlist(v, maxlevel)
|
printlist(v, maxlevel)
|
||||||
print ']',
|
print ']',
|
||||||
elif type(v) == type({}):
|
elif type(v) is type({}):
|
||||||
print '{',
|
print '{',
|
||||||
printdict(v, maxlevel)
|
printdict(v, maxlevel)
|
||||||
print '}',
|
print '}',
|
||||||
|
|
|
@ -82,13 +82,13 @@ def checkfield(n, p):
|
||||||
print inv
|
print inv
|
||||||
|
|
||||||
def rj(s, width):
|
def rj(s, width):
|
||||||
if type(s) <> type(''): s = `s`
|
if type(s) is not type(''): s = `s`
|
||||||
n = len(s)
|
n = len(s)
|
||||||
if n >= width: return s
|
if n >= width: return s
|
||||||
return ' '*(width - n) + s
|
return ' '*(width - n) + s
|
||||||
|
|
||||||
def lj(s, width):
|
def lj(s, width):
|
||||||
if type(s) <> type(''): s = `s`
|
if type(s) is not type(''): s = `s`
|
||||||
n = len(s)
|
n = len(s)
|
||||||
if n >= width: return s
|
if n >= width: return s
|
||||||
return s + ' '*(width - n)
|
return s + ' '*(width - n)
|
||||||
|
|
|
@ -339,7 +339,7 @@ class Misc:
|
||||||
"""Wait until a WIDGET is destroyed.
|
"""Wait until a WIDGET is destroyed.
|
||||||
|
|
||||||
If no parameter is given self is used."""
|
If no parameter is given self is used."""
|
||||||
if window == None:
|
if window is None:
|
||||||
window = self
|
window = self
|
||||||
self.tk.call('tkwait', 'window', window._w)
|
self.tk.call('tkwait', 'window', window._w)
|
||||||
def wait_visibility(self, window=None):
|
def wait_visibility(self, window=None):
|
||||||
|
@ -347,7 +347,7 @@ class Misc:
|
||||||
(e.g. it appears).
|
(e.g. it appears).
|
||||||
|
|
||||||
If no parameter is given self is used."""
|
If no parameter is given self is used."""
|
||||||
if window == None:
|
if window is None:
|
||||||
window = self
|
window = self
|
||||||
self.tk.call('tkwait', 'visibility', window._w)
|
self.tk.call('tkwait', 'visibility', window._w)
|
||||||
def setvar(self, name='PY_VAR', value='1'):
|
def setvar(self, name='PY_VAR', value='1'):
|
||||||
|
|
|
@ -7,7 +7,7 @@ _v20 = 1
|
||||||
_v21 = 1
|
_v21 = 1
|
||||||
##import fl
|
##import fl
|
||||||
##try:
|
##try:
|
||||||
## _v20 = (fl.get_rgbmode <> None)
|
## _v20 = (fl.get_rgbmode is not None)
|
||||||
##except:
|
##except:
|
||||||
## _v20 = 0
|
## _v20 = 0
|
||||||
##del fl
|
##del fl
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Cdplayer:
|
||||||
line = old.readline()
|
line = old.readline()
|
||||||
if line == '':
|
if line == '':
|
||||||
break
|
break
|
||||||
if line[:l] <> s:
|
if line[:l] != s:
|
||||||
new.write(line)
|
new.write(line)
|
||||||
new.write(self.id + '.title:\t' + self.title + '\n')
|
new.write(self.id + '.title:\t' + self.title + '\n')
|
||||||
new.write(self.id + '.artist:\t' + self.artist + '\n')
|
new.write(self.id + '.artist:\t' + self.artist + '\n')
|
||||||
|
|
|
@ -36,7 +36,7 @@ def parse_form(filename, formname):
|
||||||
#
|
#
|
||||||
def parse_forms(filename):
|
def parse_forms(filename):
|
||||||
forms = checkcache(filename)
|
forms = checkcache(filename)
|
||||||
if forms != None: return forms
|
if forms is not None: return forms
|
||||||
fp = _open_formfile(filename)
|
fp = _open_formfile(filename)
|
||||||
nforms = _parse_fd_header(fp)
|
nforms = _parse_fd_header(fp)
|
||||||
forms = {}
|
forms = {}
|
||||||
|
@ -168,7 +168,7 @@ def _open_formfile(filename):
|
||||||
return _open_formfile2(filename)[0]
|
return _open_formfile2(filename)[0]
|
||||||
|
|
||||||
def _open_formfile2(filename):
|
def _open_formfile2(filename):
|
||||||
if filename[-3:] <> '.fd':
|
if filename[-3:] != '.fd':
|
||||||
filename = filename + '.fd'
|
filename = filename + '.fd'
|
||||||
if filename[0] == '/':
|
if filename[0] == '/':
|
||||||
try:
|
try:
|
||||||
|
@ -184,7 +184,7 @@ def _open_formfile2(filename):
|
||||||
break
|
break
|
||||||
except IOError:
|
except IOError:
|
||||||
fp = None
|
fp = None
|
||||||
if fp == None:
|
if fp is None:
|
||||||
raise error, 'Cannot find forms file ' + filename
|
raise error, 'Cannot find forms file ' + filename
|
||||||
return fp, filename
|
return fp, filename
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ def _open_formfile2(filename):
|
||||||
def _parse_fd_header(file):
|
def _parse_fd_header(file):
|
||||||
# First read the magic header line
|
# First read the magic header line
|
||||||
datum = _parse_1_line(file)
|
datum = _parse_1_line(file)
|
||||||
if datum <> ('Magic', 12321):
|
if datum != ('Magic', 12321):
|
||||||
raise error, 'Not a forms definition file'
|
raise error, 'Not a forms definition file'
|
||||||
# Now skip until we know number of forms
|
# Now skip until we know number of forms
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -208,10 +208,10 @@ def _parse_fd_header(file):
|
||||||
#
|
#
|
||||||
def _parse_fd_form(file, name):
|
def _parse_fd_form(file, name):
|
||||||
datum = _parse_1_line(file)
|
datum = _parse_1_line(file)
|
||||||
if datum <> FORMLINE:
|
if datum != FORMLINE:
|
||||||
raise error, 'Missing === FORM === line'
|
raise error, 'Missing === FORM === line'
|
||||||
form = _parse_object(file)
|
form = _parse_object(file)
|
||||||
if form.Name == name or name == None:
|
if form.Name == name or name is None:
|
||||||
objs = []
|
objs = []
|
||||||
for j in range(form.Numberofobjects):
|
for j in range(form.Numberofobjects):
|
||||||
obj = _parse_object(file)
|
obj = _parse_object(file)
|
||||||
|
@ -316,7 +316,7 @@ def _parse_object(file):
|
||||||
if datum == FORMLINE:
|
if datum == FORMLINE:
|
||||||
file.seek(pos)
|
file.seek(pos)
|
||||||
return obj
|
return obj
|
||||||
if type(datum) <> type(()) or len(datum) <> 2:
|
if type(datum) is not type(()) or len(datum) != 2:
|
||||||
raise error, 'Parse error, illegal line in object: '+datum
|
raise error, 'Parse error, illegal line in object: '+datum
|
||||||
obj.add(datum[0], datum[1])
|
obj.add(datum[0], datum[1])
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ def create_full_form(inst, (fdata, odatalist)):
|
||||||
#
|
#
|
||||||
def merge_full_form(inst, form, (fdata, odatalist)):
|
def merge_full_form(inst, form, (fdata, odatalist)):
|
||||||
exec 'inst.'+fdata.Name+' = form\n'
|
exec 'inst.'+fdata.Name+' = form\n'
|
||||||
if odatalist[0].Class <> FL.BOX:
|
if odatalist[0].Class != FL.BOX:
|
||||||
raise error, 'merge_full_form() expects FL.BOX as first obj'
|
raise error, 'merge_full_form() expects FL.BOX as first obj'
|
||||||
for odata in odatalist[1:]:
|
for odata in odatalist[1:]:
|
||||||
create_object_instance(inst, form, odata)
|
create_object_instance(inst, form, odata)
|
||||||
|
|
|
@ -59,7 +59,7 @@ def decompress(jpegdata):
|
||||||
return imgdata, width, height, bytesperpixel
|
return imgdata, width, height, bytesperpixel
|
||||||
|
|
||||||
def setoption(name, value):
|
def setoption(name, value):
|
||||||
if type(value) <> type(0):
|
if type(value) is not type(0):
|
||||||
raise TypeError, 'jpeg.setoption: numeric options only'
|
raise TypeError, 'jpeg.setoption: numeric options only'
|
||||||
if name == 'forcegrey':
|
if name == 'forcegrey':
|
||||||
name = 'forcegray'
|
name = 'forcegray'
|
||||||
|
|
|
@ -207,7 +207,7 @@ def build_panel(descr):
|
||||||
#
|
#
|
||||||
# Sanity check
|
# Sanity check
|
||||||
#
|
#
|
||||||
if (not descr) or descr[0] <> 'panel':
|
if (not descr) or descr[0] != 'panel':
|
||||||
raise panel_error, 'panel description must start with "panel"'
|
raise panel_error, 'panel description must start with "panel"'
|
||||||
#
|
#
|
||||||
if debug: show_panel('', descr)
|
if debug: show_panel('', descr)
|
||||||
|
|
|
@ -71,7 +71,7 @@ syntax_error = 'syntax error'
|
||||||
# May raise syntax_error.
|
# May raise syntax_error.
|
||||||
#
|
#
|
||||||
def parse_expr(tokens):
|
def parse_expr(tokens):
|
||||||
if (not tokens) or tokens[0] <> '(':
|
if (not tokens) or tokens[0] != '(':
|
||||||
raise syntax_error, 'expected "("'
|
raise syntax_error, 'expected "("'
|
||||||
tokens = tokens[1:]
|
tokens = tokens[1:]
|
||||||
expr = []
|
expr = []
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Readcd:
|
||||||
if prog < self.status[5] or prog > self.status[6]:
|
if prog < self.status[5] or prog > self.status[6]:
|
||||||
raise Error, 'range error'
|
raise Error, 'range error'
|
||||||
end = self.pmsf2msf(prog, min, sec, frame)
|
end = self.pmsf2msf(prog, min, sec, frame)
|
||||||
elif l <> 3:
|
elif l != 3:
|
||||||
raise Error, 'syntax error'
|
raise Error, 'syntax error'
|
||||||
if type(start) == type(0):
|
if type(start) == type(0):
|
||||||
if start < self.status[5] or start > self.status[6]:
|
if start < self.status[5] or start > self.status[6]:
|
||||||
|
@ -111,7 +111,7 @@ class Readcd:
|
||||||
if prog < self.status[5] or prog > self.status[6]:
|
if prog < self.status[5] or prog > self.status[6]:
|
||||||
raise Error, 'range error'
|
raise Error, 'range error'
|
||||||
start = self.pmsf2msf(prog, min, sec, frame)
|
start = self.pmsf2msf(prog, min, sec, frame)
|
||||||
elif l <> 3:
|
elif l != 3:
|
||||||
raise Error, 'syntax error'
|
raise Error, 'syntax error'
|
||||||
self.list.append((start, end))
|
self.list.append((start, end))
|
||||||
|
|
||||||
|
@ -127,10 +127,10 @@ class Readcd:
|
||||||
if self.playing:
|
if self.playing:
|
||||||
start, end = self.list[self.listindex]
|
start, end = self.list[self.listindex]
|
||||||
if type(end) == type(0):
|
if type(end) == type(0):
|
||||||
if cb_type <> CD.PNUM:
|
if cb_type != CD.PNUM:
|
||||||
self.parser.setcallback(cb_type, func, arg)
|
self.parser.setcallback(cb_type, func, arg)
|
||||||
else:
|
else:
|
||||||
if cb_type <> CD.ATIME:
|
if cb_type != CD.ATIME:
|
||||||
self.parser.setcallback(cb_type, func, arg)
|
self.parser.setcallback(cb_type, func, arg)
|
||||||
|
|
||||||
def removecallback(self, cb_type):
|
def removecallback(self, cb_type):
|
||||||
|
@ -140,10 +140,10 @@ class Readcd:
|
||||||
if self.playing:
|
if self.playing:
|
||||||
start, end = self.list[self.listindex]
|
start, end = self.list[self.listindex]
|
||||||
if type(end) == type(0):
|
if type(end) == type(0):
|
||||||
if cb_type <> CD.PNUM:
|
if cb_type != CD.PNUM:
|
||||||
self.parser.removecallback(cb_type)
|
self.parser.removecallback(cb_type)
|
||||||
else:
|
else:
|
||||||
if cb_type <> CD.ATIME:
|
if cb_type != CD.ATIME:
|
||||||
self.parser.removecallback(cb_type)
|
self.parser.removecallback(cb_type)
|
||||||
|
|
||||||
def gettrackinfo(self, *arg):
|
def gettrackinfo(self, *arg):
|
||||||
|
|
|
@ -60,7 +60,7 @@ def torgb(filename):
|
||||||
ret = _torgb(filename, temps)
|
ret = _torgb(filename, temps)
|
||||||
finally:
|
finally:
|
||||||
for temp in temps[:]:
|
for temp in temps[:]:
|
||||||
if temp <> ret:
|
if temp != ret:
|
||||||
try:
|
try:
|
||||||
os.unlink(temp)
|
os.unlink(temp)
|
||||||
except os.error:
|
except os.error:
|
||||||
|
@ -83,12 +83,12 @@ def _torgb(filename, temps):
|
||||||
if type(msg) == type(()) and len(msg) == 2 and \
|
if type(msg) == type(()) and len(msg) == 2 and \
|
||||||
type(msg[0]) == type(0) and type(msg[1]) == type(''):
|
type(msg[0]) == type(0) and type(msg[1]) == type(''):
|
||||||
msg = msg[1]
|
msg = msg[1]
|
||||||
if type(msg) <> type(''):
|
if type(msg) is not type(''):
|
||||||
msg = `msg`
|
msg = `msg`
|
||||||
raise error, filename + ': ' + msg
|
raise error, filename + ': ' + msg
|
||||||
if ftype == 'rgb':
|
if ftype == 'rgb':
|
||||||
return fname
|
return fname
|
||||||
if ftype == None or not table.has_key(ftype):
|
if ftype is None or not table.has_key(ftype):
|
||||||
raise error, \
|
raise error, \
|
||||||
filename + ': unsupported image file type ' + `ftype`
|
filename + ': unsupported image file type ' + `ftype`
|
||||||
temp = tempfile.mktemp()
|
temp = tempfile.mktemp()
|
||||||
|
|
|
@ -7,7 +7,7 @@ _v20 = 1
|
||||||
_v21 = 1
|
_v21 = 1
|
||||||
##import fl
|
##import fl
|
||||||
##try:
|
##try:
|
||||||
## _v20 = (fl.get_rgbmode <> None)
|
## _v20 = (fl.get_rgbmode is not None)
|
||||||
##except:
|
##except:
|
||||||
## _v20 = 0
|
## _v20 = 0
|
||||||
##del fl
|
##del fl
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Cdplayer:
|
||||||
line = old.readline()
|
line = old.readline()
|
||||||
if line == '':
|
if line == '':
|
||||||
break
|
break
|
||||||
if line[:l] <> s:
|
if line[:l] != s:
|
||||||
new.write(line)
|
new.write(line)
|
||||||
new.write(self.id + '.title:\t' + self.title + '\n')
|
new.write(self.id + '.title:\t' + self.title + '\n')
|
||||||
new.write(self.id + '.artist:\t' + self.artist + '\n')
|
new.write(self.id + '.artist:\t' + self.artist + '\n')
|
||||||
|
|
|
@ -36,7 +36,7 @@ def parse_form(filename, formname):
|
||||||
#
|
#
|
||||||
def parse_forms(filename):
|
def parse_forms(filename):
|
||||||
forms = checkcache(filename)
|
forms = checkcache(filename)
|
||||||
if forms != None: return forms
|
if forms is not None: return forms
|
||||||
fp = _open_formfile(filename)
|
fp = _open_formfile(filename)
|
||||||
nforms = _parse_fd_header(fp)
|
nforms = _parse_fd_header(fp)
|
||||||
forms = {}
|
forms = {}
|
||||||
|
@ -168,7 +168,7 @@ def _open_formfile(filename):
|
||||||
return _open_formfile2(filename)[0]
|
return _open_formfile2(filename)[0]
|
||||||
|
|
||||||
def _open_formfile2(filename):
|
def _open_formfile2(filename):
|
||||||
if filename[-3:] <> '.fd':
|
if filename[-3:] != '.fd':
|
||||||
filename = filename + '.fd'
|
filename = filename + '.fd'
|
||||||
if filename[0] == '/':
|
if filename[0] == '/':
|
||||||
try:
|
try:
|
||||||
|
@ -184,7 +184,7 @@ def _open_formfile2(filename):
|
||||||
break
|
break
|
||||||
except IOError:
|
except IOError:
|
||||||
fp = None
|
fp = None
|
||||||
if fp == None:
|
if fp is None:
|
||||||
raise error, 'Cannot find forms file ' + filename
|
raise error, 'Cannot find forms file ' + filename
|
||||||
return fp, filename
|
return fp, filename
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ def _open_formfile2(filename):
|
||||||
def _parse_fd_header(file):
|
def _parse_fd_header(file):
|
||||||
# First read the magic header line
|
# First read the magic header line
|
||||||
datum = _parse_1_line(file)
|
datum = _parse_1_line(file)
|
||||||
if datum <> ('Magic', 12321):
|
if datum != ('Magic', 12321):
|
||||||
raise error, 'Not a forms definition file'
|
raise error, 'Not a forms definition file'
|
||||||
# Now skip until we know number of forms
|
# Now skip until we know number of forms
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -208,10 +208,10 @@ def _parse_fd_header(file):
|
||||||
#
|
#
|
||||||
def _parse_fd_form(file, name):
|
def _parse_fd_form(file, name):
|
||||||
datum = _parse_1_line(file)
|
datum = _parse_1_line(file)
|
||||||
if datum <> FORMLINE:
|
if datum != FORMLINE:
|
||||||
raise error, 'Missing === FORM === line'
|
raise error, 'Missing === FORM === line'
|
||||||
form = _parse_object(file)
|
form = _parse_object(file)
|
||||||
if form.Name == name or name == None:
|
if form.Name == name or name is None:
|
||||||
objs = []
|
objs = []
|
||||||
for j in range(form.Numberofobjects):
|
for j in range(form.Numberofobjects):
|
||||||
obj = _parse_object(file)
|
obj = _parse_object(file)
|
||||||
|
@ -316,7 +316,7 @@ def _parse_object(file):
|
||||||
if datum == FORMLINE:
|
if datum == FORMLINE:
|
||||||
file.seek(pos)
|
file.seek(pos)
|
||||||
return obj
|
return obj
|
||||||
if type(datum) <> type(()) or len(datum) <> 2:
|
if type(datum) is not type(()) or len(datum) != 2:
|
||||||
raise error, 'Parse error, illegal line in object: '+datum
|
raise error, 'Parse error, illegal line in object: '+datum
|
||||||
obj.add(datum[0], datum[1])
|
obj.add(datum[0], datum[1])
|
||||||
|
|
||||||
|
@ -339,7 +339,7 @@ def create_full_form(inst, (fdata, odatalist)):
|
||||||
#
|
#
|
||||||
def merge_full_form(inst, form, (fdata, odatalist)):
|
def merge_full_form(inst, form, (fdata, odatalist)):
|
||||||
exec 'inst.'+fdata.Name+' = form\n'
|
exec 'inst.'+fdata.Name+' = form\n'
|
||||||
if odatalist[0].Class <> FL.BOX:
|
if odatalist[0].Class != FL.BOX:
|
||||||
raise error, 'merge_full_form() expects FL.BOX as first obj'
|
raise error, 'merge_full_form() expects FL.BOX as first obj'
|
||||||
for odata in odatalist[1:]:
|
for odata in odatalist[1:]:
|
||||||
create_object_instance(inst, form, odata)
|
create_object_instance(inst, form, odata)
|
||||||
|
|
|
@ -59,7 +59,7 @@ def decompress(jpegdata):
|
||||||
return imgdata, width, height, bytesperpixel
|
return imgdata, width, height, bytesperpixel
|
||||||
|
|
||||||
def setoption(name, value):
|
def setoption(name, value):
|
||||||
if type(value) <> type(0):
|
if type(value) is not type(0):
|
||||||
raise TypeError, 'jpeg.setoption: numeric options only'
|
raise TypeError, 'jpeg.setoption: numeric options only'
|
||||||
if name == 'forcegrey':
|
if name == 'forcegrey':
|
||||||
name = 'forcegray'
|
name = 'forcegray'
|
||||||
|
|
|
@ -207,7 +207,7 @@ def build_panel(descr):
|
||||||
#
|
#
|
||||||
# Sanity check
|
# Sanity check
|
||||||
#
|
#
|
||||||
if (not descr) or descr[0] <> 'panel':
|
if (not descr) or descr[0] != 'panel':
|
||||||
raise panel_error, 'panel description must start with "panel"'
|
raise panel_error, 'panel description must start with "panel"'
|
||||||
#
|
#
|
||||||
if debug: show_panel('', descr)
|
if debug: show_panel('', descr)
|
||||||
|
|
|
@ -71,7 +71,7 @@ syntax_error = 'syntax error'
|
||||||
# May raise syntax_error.
|
# May raise syntax_error.
|
||||||
#
|
#
|
||||||
def parse_expr(tokens):
|
def parse_expr(tokens):
|
||||||
if (not tokens) or tokens[0] <> '(':
|
if (not tokens) or tokens[0] != '(':
|
||||||
raise syntax_error, 'expected "("'
|
raise syntax_error, 'expected "("'
|
||||||
tokens = tokens[1:]
|
tokens = tokens[1:]
|
||||||
expr = []
|
expr = []
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Readcd:
|
||||||
if prog < self.status[5] or prog > self.status[6]:
|
if prog < self.status[5] or prog > self.status[6]:
|
||||||
raise Error, 'range error'
|
raise Error, 'range error'
|
||||||
end = self.pmsf2msf(prog, min, sec, frame)
|
end = self.pmsf2msf(prog, min, sec, frame)
|
||||||
elif l <> 3:
|
elif l != 3:
|
||||||
raise Error, 'syntax error'
|
raise Error, 'syntax error'
|
||||||
if type(start) == type(0):
|
if type(start) == type(0):
|
||||||
if start < self.status[5] or start > self.status[6]:
|
if start < self.status[5] or start > self.status[6]:
|
||||||
|
@ -111,7 +111,7 @@ class Readcd:
|
||||||
if prog < self.status[5] or prog > self.status[6]:
|
if prog < self.status[5] or prog > self.status[6]:
|
||||||
raise Error, 'range error'
|
raise Error, 'range error'
|
||||||
start = self.pmsf2msf(prog, min, sec, frame)
|
start = self.pmsf2msf(prog, min, sec, frame)
|
||||||
elif l <> 3:
|
elif l != 3:
|
||||||
raise Error, 'syntax error'
|
raise Error, 'syntax error'
|
||||||
self.list.append((start, end))
|
self.list.append((start, end))
|
||||||
|
|
||||||
|
@ -127,10 +127,10 @@ class Readcd:
|
||||||
if self.playing:
|
if self.playing:
|
||||||
start, end = self.list[self.listindex]
|
start, end = self.list[self.listindex]
|
||||||
if type(end) == type(0):
|
if type(end) == type(0):
|
||||||
if cb_type <> CD.PNUM:
|
if cb_type != CD.PNUM:
|
||||||
self.parser.setcallback(cb_type, func, arg)
|
self.parser.setcallback(cb_type, func, arg)
|
||||||
else:
|
else:
|
||||||
if cb_type <> CD.ATIME:
|
if cb_type != CD.ATIME:
|
||||||
self.parser.setcallback(cb_type, func, arg)
|
self.parser.setcallback(cb_type, func, arg)
|
||||||
|
|
||||||
def removecallback(self, cb_type):
|
def removecallback(self, cb_type):
|
||||||
|
@ -140,10 +140,10 @@ class Readcd:
|
||||||
if self.playing:
|
if self.playing:
|
||||||
start, end = self.list[self.listindex]
|
start, end = self.list[self.listindex]
|
||||||
if type(end) == type(0):
|
if type(end) == type(0):
|
||||||
if cb_type <> CD.PNUM:
|
if cb_type != CD.PNUM:
|
||||||
self.parser.removecallback(cb_type)
|
self.parser.removecallback(cb_type)
|
||||||
else:
|
else:
|
||||||
if cb_type <> CD.ATIME:
|
if cb_type != CD.ATIME:
|
||||||
self.parser.removecallback(cb_type)
|
self.parser.removecallback(cb_type)
|
||||||
|
|
||||||
def gettrackinfo(self, *arg):
|
def gettrackinfo(self, *arg):
|
||||||
|
|
|
@ -60,7 +60,7 @@ def torgb(filename):
|
||||||
ret = _torgb(filename, temps)
|
ret = _torgb(filename, temps)
|
||||||
finally:
|
finally:
|
||||||
for temp in temps[:]:
|
for temp in temps[:]:
|
||||||
if temp <> ret:
|
if temp != ret:
|
||||||
try:
|
try:
|
||||||
os.unlink(temp)
|
os.unlink(temp)
|
||||||
except os.error:
|
except os.error:
|
||||||
|
@ -83,12 +83,12 @@ def _torgb(filename, temps):
|
||||||
if type(msg) == type(()) and len(msg) == 2 and \
|
if type(msg) == type(()) and len(msg) == 2 and \
|
||||||
type(msg[0]) == type(0) and type(msg[1]) == type(''):
|
type(msg[0]) == type(0) and type(msg[1]) == type(''):
|
||||||
msg = msg[1]
|
msg = msg[1]
|
||||||
if type(msg) <> type(''):
|
if type(msg) is not type(''):
|
||||||
msg = `msg`
|
msg = `msg`
|
||||||
raise error, filename + ': ' + msg
|
raise error, filename + ': ' + msg
|
||||||
if ftype == 'rgb':
|
if ftype == 'rgb':
|
||||||
return fname
|
return fname
|
||||||
if ftype == None or not table.has_key(ftype):
|
if ftype is None or not table.has_key(ftype):
|
||||||
raise error, \
|
raise error, \
|
||||||
filename + ': unsupported image file type ' + `ftype`
|
filename + ': unsupported image file type ' + `ftype`
|
||||||
temp = tempfile.mktemp()
|
temp = tempfile.mktemp()
|
||||||
|
|
|
@ -283,7 +283,7 @@ class Compare:
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
expected = self.fp.read(len(data))
|
expected = self.fp.read(len(data))
|
||||||
if data <> expected:
|
if data != expected:
|
||||||
raise test_support.TestFailed, \
|
raise test_support.TestFailed, \
|
||||||
'Writing: '+`data`+', expected: '+`expected`
|
'Writing: '+`data`+', expected: '+`expected`
|
||||||
|
|
||||||
|
|
|
@ -24,61 +24,61 @@ def gendata4():
|
||||||
def testmax(data):
|
def testmax(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'max'
|
print 'max'
|
||||||
if audioop.max(data[0], 1) <> 2 or \
|
if audioop.max(data[0], 1) != 2 or \
|
||||||
audioop.max(data[1], 2) <> 2 or \
|
audioop.max(data[1], 2) != 2 or \
|
||||||
audioop.max(data[2], 4) <> 2:
|
audioop.max(data[2], 4) != 2:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testminmax(data):
|
def testminmax(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'minmax'
|
print 'minmax'
|
||||||
if audioop.minmax(data[0], 1) <> (0, 2) or \
|
if audioop.minmax(data[0], 1) != (0, 2) or \
|
||||||
audioop.minmax(data[1], 2) <> (0, 2) or \
|
audioop.minmax(data[1], 2) != (0, 2) or \
|
||||||
audioop.minmax(data[2], 4) <> (0, 2):
|
audioop.minmax(data[2], 4) != (0, 2):
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testmaxpp(data):
|
def testmaxpp(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'maxpp'
|
print 'maxpp'
|
||||||
if audioop.maxpp(data[0], 1) <> 0 or \
|
if audioop.maxpp(data[0], 1) != 0 or \
|
||||||
audioop.maxpp(data[1], 2) <> 0 or \
|
audioop.maxpp(data[1], 2) != 0 or \
|
||||||
audioop.maxpp(data[2], 4) <> 0:
|
audioop.maxpp(data[2], 4) != 0:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testavg(data):
|
def testavg(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'avg'
|
print 'avg'
|
||||||
if audioop.avg(data[0], 1) <> 1 or \
|
if audioop.avg(data[0], 1) != 1 or \
|
||||||
audioop.avg(data[1], 2) <> 1 or \
|
audioop.avg(data[1], 2) != 1 or \
|
||||||
audioop.avg(data[2], 4) <> 1:
|
audioop.avg(data[2], 4) != 1:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testavgpp(data):
|
def testavgpp(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'avgpp'
|
print 'avgpp'
|
||||||
if audioop.avgpp(data[0], 1) <> 0 or \
|
if audioop.avgpp(data[0], 1) != 0 or \
|
||||||
audioop.avgpp(data[1], 2) <> 0 or \
|
audioop.avgpp(data[1], 2) != 0 or \
|
||||||
audioop.avgpp(data[2], 4) <> 0:
|
audioop.avgpp(data[2], 4) != 0:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testrms(data):
|
def testrms(data):
|
||||||
if audioop.rms(data[0], 1) <> 1 or \
|
if audioop.rms(data[0], 1) != 1 or \
|
||||||
audioop.rms(data[1], 2) <> 1 or \
|
audioop.rms(data[1], 2) != 1 or \
|
||||||
audioop.rms(data[2], 4) <> 1:
|
audioop.rms(data[2], 4) != 1:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testcross(data):
|
def testcross(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'cross'
|
print 'cross'
|
||||||
if audioop.cross(data[0], 1) <> 0 or \
|
if audioop.cross(data[0], 1) != 0 or \
|
||||||
audioop.cross(data[1], 2) <> 0 or \
|
audioop.cross(data[1], 2) != 0 or \
|
||||||
audioop.cross(data[2], 4) <> 0:
|
audioop.cross(data[2], 4) != 0:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -91,9 +91,9 @@ def testadd(data):
|
||||||
for s in d:
|
for s in d:
|
||||||
str = str + chr(ord(s)*2)
|
str = str + chr(ord(s)*2)
|
||||||
data2.append(str)
|
data2.append(str)
|
||||||
if audioop.add(data[0], data[0], 1) <> data2[0] or \
|
if audioop.add(data[0], data[0], 1) != data2[0] or \
|
||||||
audioop.add(data[1], data[1], 2) <> data2[1] or \
|
audioop.add(data[1], data[1], 2) != data2[1] or \
|
||||||
audioop.add(data[2], data[2], 4) <> data2[2]:
|
audioop.add(data[2], data[2], 4) != data2[2]:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ def testbias(data):
|
||||||
d1 = audioop.bias(data[0], 1, 100)
|
d1 = audioop.bias(data[0], 1, 100)
|
||||||
d2 = audioop.bias(data[1], 2, 100)
|
d2 = audioop.bias(data[1], 2, 100)
|
||||||
d4 = audioop.bias(data[2], 4, 100)
|
d4 = audioop.bias(data[2], 4, 100)
|
||||||
if audioop.avg(d1, 1) <> 101 or \
|
if audioop.avg(d1, 1) != 101 or \
|
||||||
audioop.avg(d2, 2) <> 101 or \
|
audioop.avg(d2, 2) != 101 or \
|
||||||
audioop.avg(d4, 4) <> 101:
|
audioop.avg(d4, 4) != 101:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -118,13 +118,13 @@ def testlin2lin(data):
|
||||||
for d2 in data:
|
for d2 in data:
|
||||||
got = len(d1)/3
|
got = len(d1)/3
|
||||||
wtd = len(d2)/3
|
wtd = len(d2)/3
|
||||||
if len(audioop.lin2lin(d1, got, wtd)) <> len(d2):
|
if len(audioop.lin2lin(d1, got, wtd)) != len(d2):
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testadpcm2lin(data):
|
def testadpcm2lin(data):
|
||||||
# Very cursory test
|
# Very cursory test
|
||||||
if audioop.adpcm2lin('\0\0', 1, None) <> ('\0\0\0\0', (0,0)):
|
if audioop.adpcm2lin('\0\0', 1, None) != ('\0\0\0\0', (0,0)):
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -132,16 +132,16 @@ def testlin2adpcm(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'lin2adpcm'
|
print 'lin2adpcm'
|
||||||
# Very cursory test
|
# Very cursory test
|
||||||
if audioop.lin2adpcm('\0\0\0\0', 1, None) <> ('\0\0', (0,0)):
|
if audioop.lin2adpcm('\0\0\0\0', 1, None) != ('\0\0', (0,0)):
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testlin2ulaw(data):
|
def testlin2ulaw(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'lin2ulaw'
|
print 'lin2ulaw'
|
||||||
if audioop.lin2ulaw(data[0], 1) <> '\377\347\333' or \
|
if audioop.lin2ulaw(data[0], 1) != '\377\347\333' or \
|
||||||
audioop.lin2ulaw(data[1], 2) <> '\377\377\377' or \
|
audioop.lin2ulaw(data[1], 2) != '\377\377\377' or \
|
||||||
audioop.lin2ulaw(data[2], 4) <> '\377\377\377':
|
audioop.lin2ulaw(data[2], 4) != '\377\377\377':
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ def testulaw2lin(data):
|
||||||
print 'ulaw2lin'
|
print 'ulaw2lin'
|
||||||
# Cursory
|
# Cursory
|
||||||
d = audioop.lin2ulaw(data[0], 1)
|
d = audioop.lin2ulaw(data[0], 1)
|
||||||
if audioop.ulaw2lin(d, 1) <> data[0]:
|
if audioop.ulaw2lin(d, 1) != data[0]:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -163,9 +163,9 @@ def testmul(data):
|
||||||
for s in d:
|
for s in d:
|
||||||
str = str + chr(ord(s)*2)
|
str = str + chr(ord(s)*2)
|
||||||
data2.append(str)
|
data2.append(str)
|
||||||
if audioop.mul(data[0], 1, 2) <> data2[0] or \
|
if audioop.mul(data[0], 1, 2) != data2[0] or \
|
||||||
audioop.mul(data[1],2, 2) <> data2[1] or \
|
audioop.mul(data[1],2, 2) != data2[1] or \
|
||||||
audioop.mul(data[2], 4, 2) <> data2[2]:
|
audioop.mul(data[2], 4, 2) != data2[2]:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ def testratecv(data):
|
||||||
def testreverse(data):
|
def testreverse(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'reverse'
|
print 'reverse'
|
||||||
if audioop.reverse(data[0], 1) <> '\2\1\0':
|
if audioop.reverse(data[0], 1) != '\2\1\0':
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ def testtomono(data):
|
||||||
data2 = ''
|
data2 = ''
|
||||||
for d in data[0]:
|
for d in data[0]:
|
||||||
data2 = data2 + d + d
|
data2 = data2 + d + d
|
||||||
if audioop.tomono(data2, 1, 0.5, 0.5) <> data[0]:
|
if audioop.tomono(data2, 1, 0.5, 0.5) != data[0]:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -202,28 +202,28 @@ def testtostereo(data):
|
||||||
data2 = ''
|
data2 = ''
|
||||||
for d in data[0]:
|
for d in data[0]:
|
||||||
data2 = data2 + d + d
|
data2 = data2 + d + d
|
||||||
if audioop.tostereo(data[0], 1, 1, 1) <> data2:
|
if audioop.tostereo(data[0], 1, 1, 1) != data2:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testfindfactor(data):
|
def testfindfactor(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'findfactor'
|
print 'findfactor'
|
||||||
if audioop.findfactor(data[1], data[1]) <> 1.0:
|
if audioop.findfactor(data[1], data[1]) != 1.0:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testfindfit(data):
|
def testfindfit(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'findfit'
|
print 'findfit'
|
||||||
if audioop.findfit(data[1], data[1]) <> (0, 1.0):
|
if audioop.findfit(data[1], data[1]) != (0, 1.0):
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def testfindmax(data):
|
def testfindmax(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'findmax'
|
print 'findmax'
|
||||||
if audioop.findmax(data[1], 1) <> 2:
|
if audioop.findmax(data[1], 1) != 2:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@ -231,9 +231,9 @@ def testgetsample(data):
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'getsample'
|
print 'getsample'
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
if audioop.getsample(data[0], 1, i) <> i or \
|
if audioop.getsample(data[0], 1, i) != i or \
|
||||||
audioop.getsample(data[1], 2, i) <> i or \
|
audioop.getsample(data[1], 2, i) != i or \
|
||||||
audioop.getsample(data[2], 4, i) <> i:
|
audioop.getsample(data[2], 4, i) != i:
|
||||||
return 0
|
return 0
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
|
@ -11,17 +11,17 @@ except ImportError: pass
|
||||||
else: raise TestFailed, "__import__('spamspam') should fail"
|
else: raise TestFailed, "__import__('spamspam') should fail"
|
||||||
|
|
||||||
print 'abs'
|
print 'abs'
|
||||||
if abs(0) <> 0: raise TestFailed, 'abs(0)'
|
if abs(0) != 0: raise TestFailed, 'abs(0)'
|
||||||
if abs(1234) <> 1234: raise TestFailed, 'abs(1234)'
|
if abs(1234) != 1234: raise TestFailed, 'abs(1234)'
|
||||||
if abs(-1234) <> 1234: raise TestFailed, 'abs(-1234)'
|
if abs(-1234) != 1234: raise TestFailed, 'abs(-1234)'
|
||||||
#
|
#
|
||||||
if abs(0.0) <> 0.0: raise TestFailed, 'abs(0.0)'
|
if abs(0.0) != 0.0: raise TestFailed, 'abs(0.0)'
|
||||||
if abs(3.14) <> 3.14: raise TestFailed, 'abs(3.14)'
|
if abs(3.14) != 3.14: raise TestFailed, 'abs(3.14)'
|
||||||
if abs(-3.14) <> 3.14: raise TestFailed, 'abs(-3.14)'
|
if abs(-3.14) != 3.14: raise TestFailed, 'abs(-3.14)'
|
||||||
#
|
#
|
||||||
if abs(0L) <> 0L: raise TestFailed, 'abs(0L)'
|
if abs(0L) != 0L: raise TestFailed, 'abs(0L)'
|
||||||
if abs(1234L) <> 1234L: raise TestFailed, 'abs(1234L)'
|
if abs(1234L) != 1234L: raise TestFailed, 'abs(1234L)'
|
||||||
if abs(-1234L) <> 1234L: raise TestFailed, 'abs(-1234L)'
|
if abs(-1234L) != 1234L: raise TestFailed, 'abs(-1234L)'
|
||||||
|
|
||||||
print 'apply'
|
print 'apply'
|
||||||
def f0(*args):
|
def f0(*args):
|
||||||
|
@ -55,14 +55,14 @@ y = D()
|
||||||
if not callable(y): raise TestFailed, 'callable(y)'
|
if not callable(y): raise TestFailed, 'callable(y)'
|
||||||
|
|
||||||
print 'chr'
|
print 'chr'
|
||||||
if chr(32) <> ' ': raise TestFailed, 'chr(32)'
|
if chr(32) != ' ': raise TestFailed, 'chr(32)'
|
||||||
if chr(65) <> 'A': raise TestFailed, 'chr(65)'
|
if chr(65) != 'A': raise TestFailed, 'chr(65)'
|
||||||
if chr(97) <> 'a': raise TestFailed, 'chr(97)'
|
if chr(97) != 'a': raise TestFailed, 'chr(97)'
|
||||||
|
|
||||||
print 'cmp'
|
print 'cmp'
|
||||||
if cmp(-1, 1) <> -1: raise TestFailed, 'cmp(-1, 1)'
|
if cmp(-1, 1) != -1: raise TestFailed, 'cmp(-1, 1)'
|
||||||
if cmp(1, -1) <> 1: raise TestFailed, 'cmp(1, -1)'
|
if cmp(1, -1) != 1: raise TestFailed, 'cmp(1, -1)'
|
||||||
if cmp(1, 1) <> 0: raise TestFailed, 'cmp(1, 1)'
|
if cmp(1, 1) != 0: raise TestFailed, 'cmp(1, 1)'
|
||||||
# verify that circular objects are handled
|
# verify that circular objects are handled
|
||||||
a = []; a.append(a)
|
a = []; a.append(a)
|
||||||
b = []; b.append(b)
|
b = []; b.append(b)
|
||||||
|
@ -77,40 +77,40 @@ a.pop(); b.pop(); c.pop()
|
||||||
|
|
||||||
print 'coerce'
|
print 'coerce'
|
||||||
if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
|
if fcmp(coerce(1, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1, 1.1)'
|
||||||
if coerce(1, 1L) <> (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
|
if coerce(1, 1L) != (1L, 1L): raise TestFailed, 'coerce(1, 1L)'
|
||||||
if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
|
if fcmp(coerce(1L, 1.1), (1.0, 1.1)): raise TestFailed, 'coerce(1L, 1.1)'
|
||||||
|
|
||||||
print 'compile'
|
print 'compile'
|
||||||
compile('print 1\n', '', 'exec')
|
compile('print 1\n', '', 'exec')
|
||||||
|
|
||||||
print 'complex'
|
print 'complex'
|
||||||
if complex(1,10) <> 1+10j: raise TestFailed, 'complex(1,10)'
|
if complex(1,10) != 1+10j: raise TestFailed, 'complex(1,10)'
|
||||||
if complex(1,10L) <> 1+10j: raise TestFailed, 'complex(1,10L)'
|
if complex(1,10L) != 1+10j: raise TestFailed, 'complex(1,10L)'
|
||||||
if complex(1,10.0) <> 1+10j: raise TestFailed, 'complex(1,10.0)'
|
if complex(1,10.0) != 1+10j: raise TestFailed, 'complex(1,10.0)'
|
||||||
if complex(1L,10) <> 1+10j: raise TestFailed, 'complex(1L,10)'
|
if complex(1L,10) != 1+10j: raise TestFailed, 'complex(1L,10)'
|
||||||
if complex(1L,10L) <> 1+10j: raise TestFailed, 'complex(1L,10L)'
|
if complex(1L,10L) != 1+10j: raise TestFailed, 'complex(1L,10L)'
|
||||||
if complex(1L,10.0) <> 1+10j: raise TestFailed, 'complex(1L,10.0)'
|
if complex(1L,10.0) != 1+10j: raise TestFailed, 'complex(1L,10.0)'
|
||||||
if complex(1.0,10) <> 1+10j: raise TestFailed, 'complex(1.0,10)'
|
if complex(1.0,10) != 1+10j: raise TestFailed, 'complex(1.0,10)'
|
||||||
if complex(1.0,10L) <> 1+10j: raise TestFailed, 'complex(1.0,10L)'
|
if complex(1.0,10L) != 1+10j: raise TestFailed, 'complex(1.0,10L)'
|
||||||
if complex(1.0,10.0) <> 1+10j: raise TestFailed, 'complex(1.0,10.0)'
|
if complex(1.0,10.0) != 1+10j: raise TestFailed, 'complex(1.0,10.0)'
|
||||||
if complex(3.14+0j) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
|
if complex(3.14+0j) != 3.14+0j: raise TestFailed, 'complex(3.14)'
|
||||||
if complex(3.14) <> 3.14+0j: raise TestFailed, 'complex(3.14)'
|
if complex(3.14) != 3.14+0j: raise TestFailed, 'complex(3.14)'
|
||||||
if complex(314) <> 314.0+0j: raise TestFailed, 'complex(314)'
|
if complex(314) != 314.0+0j: raise TestFailed, 'complex(314)'
|
||||||
if complex(314L) <> 314.0+0j: raise TestFailed, 'complex(314L)'
|
if complex(314L) != 314.0+0j: raise TestFailed, 'complex(314L)'
|
||||||
if complex(3.14+0j, 0j) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0j)'
|
if complex(3.14+0j, 0j) != 3.14+0j: raise TestFailed, 'complex(3.14, 0j)'
|
||||||
if complex(3.14, 0.0) <> 3.14+0j: raise TestFailed, 'complex(3.14, 0.0)'
|
if complex(3.14, 0.0) != 3.14+0j: raise TestFailed, 'complex(3.14, 0.0)'
|
||||||
if complex(314, 0) <> 314.0+0j: raise TestFailed, 'complex(314, 0)'
|
if complex(314, 0) != 314.0+0j: raise TestFailed, 'complex(314, 0)'
|
||||||
if complex(314L, 0L) <> 314.0+0j: raise TestFailed, 'complex(314L, 0L)'
|
if complex(314L, 0L) != 314.0+0j: raise TestFailed, 'complex(314L, 0L)'
|
||||||
if complex(0j, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0j, 3.14j)'
|
if complex(0j, 3.14j) != -3.14+0j: raise TestFailed, 'complex(0j, 3.14j)'
|
||||||
if complex(0.0, 3.14j) <> -3.14+0j: raise TestFailed, 'complex(0.0, 3.14j)'
|
if complex(0.0, 3.14j) != -3.14+0j: raise TestFailed, 'complex(0.0, 3.14j)'
|
||||||
if complex(0j, 3.14) <> 3.14j: raise TestFailed, 'complex(0j, 3.14)'
|
if complex(0j, 3.14) != 3.14j: raise TestFailed, 'complex(0j, 3.14)'
|
||||||
if complex(0.0, 3.14) <> 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
|
if complex(0.0, 3.14) != 3.14j: raise TestFailed, 'complex(0.0, 3.14)'
|
||||||
if complex(" 3.14+J ") <> 3.14+1j: raise TestFailed, 'complex(" 3.14+J )"'
|
if complex(" 3.14+J ") != 3.14+1j: raise TestFailed, 'complex(" 3.14+J )"'
|
||||||
if complex(u" 3.14+J ") <> 3.14+1j: raise TestFailed, 'complex(u" 3.14+J )"'
|
if complex(u" 3.14+J ") != 3.14+1j: raise TestFailed, 'complex(u" 3.14+J )"'
|
||||||
class Z:
|
class Z:
|
||||||
def __complex__(self): return 3.14j
|
def __complex__(self): return 3.14j
|
||||||
z = Z()
|
z = Z()
|
||||||
if complex(z) <> 3.14j: raise TestFailed, 'complex(classinstance)'
|
if complex(z) != 3.14j: raise TestFailed, 'complex(classinstance)'
|
||||||
|
|
||||||
print 'delattr'
|
print 'delattr'
|
||||||
import sys
|
import sys
|
||||||
|
@ -124,20 +124,20 @@ import sys
|
||||||
if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)'
|
if 'modules' not in dir(sys): raise TestFailed, 'dir(sys)'
|
||||||
|
|
||||||
print 'divmod'
|
print 'divmod'
|
||||||
if divmod(12, 7) <> (1, 5): raise TestFailed, 'divmod(12, 7)'
|
if divmod(12, 7) != (1, 5): raise TestFailed, 'divmod(12, 7)'
|
||||||
if divmod(-12, 7) <> (-2, 2): raise TestFailed, 'divmod(-12, 7)'
|
if divmod(-12, 7) != (-2, 2): raise TestFailed, 'divmod(-12, 7)'
|
||||||
if divmod(12, -7) <> (-2, -2): raise TestFailed, 'divmod(12, -7)'
|
if divmod(12, -7) != (-2, -2): raise TestFailed, 'divmod(12, -7)'
|
||||||
if divmod(-12, -7) <> (1, -5): raise TestFailed, 'divmod(-12, -7)'
|
if divmod(-12, -7) != (1, -5): raise TestFailed, 'divmod(-12, -7)'
|
||||||
#
|
#
|
||||||
if divmod(12L, 7L) <> (1L, 5L): raise TestFailed, 'divmod(12L, 7L)'
|
if divmod(12L, 7L) != (1L, 5L): raise TestFailed, 'divmod(12L, 7L)'
|
||||||
if divmod(-12L, 7L) <> (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)'
|
if divmod(-12L, 7L) != (-2L, 2L): raise TestFailed, 'divmod(-12L, 7L)'
|
||||||
if divmod(12L, -7L) <> (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)'
|
if divmod(12L, -7L) != (-2L, -2L): raise TestFailed, 'divmod(12L, -7L)'
|
||||||
if divmod(-12L, -7L) <> (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)'
|
if divmod(-12L, -7L) != (1L, -5L): raise TestFailed, 'divmod(-12L, -7L)'
|
||||||
#
|
#
|
||||||
if divmod(12, 7L) <> (1, 5L): raise TestFailed, 'divmod(12, 7L)'
|
if divmod(12, 7L) != (1, 5L): raise TestFailed, 'divmod(12, 7L)'
|
||||||
if divmod(-12, 7L) <> (-2, 2L): raise TestFailed, 'divmod(-12, 7L)'
|
if divmod(-12, 7L) != (-2, 2L): raise TestFailed, 'divmod(-12, 7L)'
|
||||||
if divmod(12L, -7) <> (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
|
if divmod(12L, -7) != (-2L, -2): raise TestFailed, 'divmod(12L, -7)'
|
||||||
if divmod(-12L, -7) <> (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
|
if divmod(-12L, -7) != (1L, -5): raise TestFailed, 'divmod(-12L, -7)'
|
||||||
#
|
#
|
||||||
if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
|
if fcmp(divmod(3.25, 1.0), (3.0, 0.25)):
|
||||||
raise TestFailed, 'divmod(3.25, 1.0)'
|
raise TestFailed, 'divmod(3.25, 1.0)'
|
||||||
|
@ -149,29 +149,29 @@ if fcmp(divmod(-3.25, -1.0), (3.0, -0.25)):
|
||||||
raise TestFailed, 'divmod(-3.25, -1.0)'
|
raise TestFailed, 'divmod(-3.25, -1.0)'
|
||||||
|
|
||||||
print 'eval'
|
print 'eval'
|
||||||
if eval('1+1') <> 2: raise TestFailed, 'eval(\'1+1\')'
|
if eval('1+1') != 2: raise TestFailed, 'eval(\'1+1\')'
|
||||||
if eval(' 1+1\n') <> 2: raise TestFailed, 'eval(\' 1+1\\n\')'
|
if eval(' 1+1\n') != 2: raise TestFailed, 'eval(\' 1+1\\n\')'
|
||||||
globals = {'a': 1, 'b': 2}
|
globals = {'a': 1, 'b': 2}
|
||||||
locals = {'b': 200, 'c': 300}
|
locals = {'b': 200, 'c': 300}
|
||||||
if eval('a', globals) <> 1:
|
if eval('a', globals) != 1:
|
||||||
raise TestFailed, "eval(1) == %s" % eval('a', globals)
|
raise TestFailed, "eval(1) == %s" % eval('a', globals)
|
||||||
if eval('a', globals, locals) <> 1:
|
if eval('a', globals, locals) != 1:
|
||||||
raise TestFailed, "eval(2)"
|
raise TestFailed, "eval(2)"
|
||||||
if eval('b', globals, locals) <> 200:
|
if eval('b', globals, locals) != 200:
|
||||||
raise TestFailed, "eval(3)"
|
raise TestFailed, "eval(3)"
|
||||||
if eval('c', globals, locals) <> 300:
|
if eval('c', globals, locals) != 300:
|
||||||
raise TestFailed, "eval(4)"
|
raise TestFailed, "eval(4)"
|
||||||
if eval(u'1+1') <> 2: raise TestFailed, 'eval(u\'1+1\')'
|
if eval(u'1+1') != 2: raise TestFailed, 'eval(u\'1+1\')'
|
||||||
if eval(u' 1+1\n') <> 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
|
if eval(u' 1+1\n') != 2: raise TestFailed, 'eval(u\' 1+1\\n\')'
|
||||||
globals = {'a': 1, 'b': 2}
|
globals = {'a': 1, 'b': 2}
|
||||||
locals = {'b': 200, 'c': 300}
|
locals = {'b': 200, 'c': 300}
|
||||||
if eval(u'a', globals) <> 1:
|
if eval(u'a', globals) != 1:
|
||||||
raise TestFailed, "eval(1) == %s" % eval(u'a', globals)
|
raise TestFailed, "eval(1) == %s" % eval(u'a', globals)
|
||||||
if eval(u'a', globals, locals) <> 1:
|
if eval(u'a', globals, locals) != 1:
|
||||||
raise TestFailed, "eval(2)"
|
raise TestFailed, "eval(2)"
|
||||||
if eval(u'b', globals, locals) <> 200:
|
if eval(u'b', globals, locals) != 200:
|
||||||
raise TestFailed, "eval(3)"
|
raise TestFailed, "eval(3)"
|
||||||
if eval(u'c', globals, locals) <> 300:
|
if eval(u'c', globals, locals) != 300:
|
||||||
raise TestFailed, "eval(4)"
|
raise TestFailed, "eval(4)"
|
||||||
|
|
||||||
print 'execfile'
|
print 'execfile'
|
||||||
|
@ -181,21 +181,21 @@ f.write('z = z+1\n')
|
||||||
f.write('z = z*2\n')
|
f.write('z = z*2\n')
|
||||||
f.close()
|
f.close()
|
||||||
execfile(TESTFN)
|
execfile(TESTFN)
|
||||||
if z <> 2: raise TestFailed, "execfile(1)"
|
if z != 2: raise TestFailed, "execfile(1)"
|
||||||
globals['z'] = 0
|
globals['z'] = 0
|
||||||
execfile(TESTFN, globals)
|
execfile(TESTFN, globals)
|
||||||
if globals['z'] <> 2: raise TestFailed, "execfile(1)"
|
if globals['z'] != 2: raise TestFailed, "execfile(1)"
|
||||||
locals['z'] = 0
|
locals['z'] = 0
|
||||||
execfile(TESTFN, globals, locals)
|
execfile(TESTFN, globals, locals)
|
||||||
if locals['z'] <> 2: raise TestFailed, "execfile(1)"
|
if locals['z'] != 2: raise TestFailed, "execfile(1)"
|
||||||
unlink(TESTFN)
|
unlink(TESTFN)
|
||||||
|
|
||||||
print 'filter'
|
print 'filter'
|
||||||
if filter(lambda c: 'a' <= c <= 'z', 'Hello World') <> 'elloorld':
|
if filter(lambda c: 'a' <= c <= 'z', 'Hello World') != 'elloorld':
|
||||||
raise TestFailed, 'filter (filter a string)'
|
raise TestFailed, 'filter (filter a string)'
|
||||||
if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]:
|
if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) != [1, 'hello', [3], 9]:
|
||||||
raise TestFailed, 'filter (remove false values)'
|
raise TestFailed, 'filter (remove false values)'
|
||||||
if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) <> [1, 9, 2]:
|
if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) != [1, 9, 2]:
|
||||||
raise TestFailed, 'filter (keep positives)'
|
raise TestFailed, 'filter (keep positives)'
|
||||||
class Squares:
|
class Squares:
|
||||||
def __init__(self, max):
|
def __init__(self, max):
|
||||||
|
@ -232,12 +232,12 @@ def identity(item):
|
||||||
filter(identity, Squares(5))
|
filter(identity, Squares(5))
|
||||||
|
|
||||||
print 'float'
|
print 'float'
|
||||||
if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'
|
if float(3.14) != 3.14: raise TestFailed, 'float(3.14)'
|
||||||
if float(314) <> 314.0: raise TestFailed, 'float(314)'
|
if float(314) != 314.0: raise TestFailed, 'float(314)'
|
||||||
if float(314L) <> 314.0: raise TestFailed, 'float(314L)'
|
if float(314L) != 314.0: raise TestFailed, 'float(314L)'
|
||||||
if float(" 3.14 ") <> 3.14: raise TestFailed, 'float(" 3.14 ")'
|
if float(" 3.14 ") != 3.14: raise TestFailed, 'float(" 3.14 ")'
|
||||||
if float(u" 3.14 ") <> 3.14: raise TestFailed, 'float(u" 3.14 ")'
|
if float(u" 3.14 ") != 3.14: raise TestFailed, 'float(u" 3.14 ")'
|
||||||
if float(u" \u0663.\u0661\u0664 ") <> 3.14:
|
if float(u" \u0663.\u0661\u0664 ") != 3.14:
|
||||||
raise TestFailed, 'float(u" \u0663.\u0661\u0664 ")'
|
raise TestFailed, 'float(u" \u0663.\u0661\u0664 ")'
|
||||||
|
|
||||||
print 'getattr'
|
print 'getattr'
|
||||||
|
@ -276,18 +276,18 @@ id({'spam': 1, 'eggs': 2, 'ham': 3})
|
||||||
# Test input() later, together with raw_input
|
# Test input() later, together with raw_input
|
||||||
|
|
||||||
print 'int'
|
print 'int'
|
||||||
if int(314) <> 314: raise TestFailed, 'int(314)'
|
if int(314) != 314: raise TestFailed, 'int(314)'
|
||||||
if int(3.14) <> 3: raise TestFailed, 'int(3.14)'
|
if int(3.14) != 3: raise TestFailed, 'int(3.14)'
|
||||||
if int(314L) <> 314: raise TestFailed, 'int(314L)'
|
if int(314L) != 314: raise TestFailed, 'int(314L)'
|
||||||
# Check that conversion from float truncates towards zero
|
# Check that conversion from float truncates towards zero
|
||||||
if int(-3.14) <> -3: raise TestFailed, 'int(-3.14)'
|
if int(-3.14) != -3: raise TestFailed, 'int(-3.14)'
|
||||||
if int(3.9) <> 3: raise TestFailed, 'int(3.9)'
|
if int(3.9) != 3: raise TestFailed, 'int(3.9)'
|
||||||
if int(-3.9) <> -3: raise TestFailed, 'int(-3.9)'
|
if int(-3.9) != -3: raise TestFailed, 'int(-3.9)'
|
||||||
if int(3.5) <> 3: raise TestFailed, 'int(3.5)'
|
if int(3.5) != 3: raise TestFailed, 'int(3.5)'
|
||||||
if int(-3.5) <> -3: raise TestFailed, 'int(-3.5)'
|
if int(-3.5) != -3: raise TestFailed, 'int(-3.5)'
|
||||||
# Different base:
|
# Different base:
|
||||||
if int("10",16) <> 16L: raise TestFailed, 'int("10",16)'
|
if int("10",16) != 16L: raise TestFailed, 'int("10",16)'
|
||||||
if int(u"10",16) <> 16L: raise TestFailed, 'int(u"10",16)'
|
if int(u"10",16) != 16L: raise TestFailed, 'int(u"10",16)'
|
||||||
# Test conversion from strings and various anomalies
|
# Test conversion from strings and various anomalies
|
||||||
L = [
|
L = [
|
||||||
('0', 0),
|
('0', 0),
|
||||||
|
@ -385,28 +385,28 @@ except TypeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print 'len'
|
print 'len'
|
||||||
if len('123') <> 3: raise TestFailed, 'len(\'123\')'
|
if len('123') != 3: raise TestFailed, 'len(\'123\')'
|
||||||
if len(()) <> 0: raise TestFailed, 'len(())'
|
if len(()) != 0: raise TestFailed, 'len(())'
|
||||||
if len((1, 2, 3, 4)) <> 4: raise TestFailed, 'len((1, 2, 3, 4))'
|
if len((1, 2, 3, 4)) != 4: raise TestFailed, 'len((1, 2, 3, 4))'
|
||||||
if len([1, 2, 3, 4]) <> 4: raise TestFailed, 'len([1, 2, 3, 4])'
|
if len([1, 2, 3, 4]) != 4: raise TestFailed, 'len([1, 2, 3, 4])'
|
||||||
if len({}) <> 0: raise TestFailed, 'len({})'
|
if len({}) != 0: raise TestFailed, 'len({})'
|
||||||
if len({'a':1, 'b': 2}) <> 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
|
if len({'a':1, 'b': 2}) != 2: raise TestFailed, 'len({\'a\':1, \'b\': 2})'
|
||||||
|
|
||||||
print 'long'
|
print 'long'
|
||||||
if long(314) <> 314L: raise TestFailed, 'long(314)'
|
if long(314) != 314L: raise TestFailed, 'long(314)'
|
||||||
if long(3.14) <> 3L: raise TestFailed, 'long(3.14)'
|
if long(3.14) != 3L: raise TestFailed, 'long(3.14)'
|
||||||
if long(314L) <> 314L: raise TestFailed, 'long(314L)'
|
if long(314L) != 314L: raise TestFailed, 'long(314L)'
|
||||||
# Check that conversion from float truncates towards zero
|
# Check that conversion from float truncates towards zero
|
||||||
if long(-3.14) <> -3L: raise TestFailed, 'long(-3.14)'
|
if long(-3.14) != -3L: raise TestFailed, 'long(-3.14)'
|
||||||
if long(3.9) <> 3L: raise TestFailed, 'long(3.9)'
|
if long(3.9) != 3L: raise TestFailed, 'long(3.9)'
|
||||||
if long(-3.9) <> -3L: raise TestFailed, 'long(-3.9)'
|
if long(-3.9) != -3L: raise TestFailed, 'long(-3.9)'
|
||||||
if long(3.5) <> 3L: raise TestFailed, 'long(3.5)'
|
if long(3.5) != 3L: raise TestFailed, 'long(3.5)'
|
||||||
if long(-3.5) <> -3L: raise TestFailed, 'long(-3.5)'
|
if long(-3.5) != -3L: raise TestFailed, 'long(-3.5)'
|
||||||
if long("-3") <> -3L: raise TestFailed, 'long("-3")'
|
if long("-3") != -3L: raise TestFailed, 'long("-3")'
|
||||||
if long(u"-3") <> -3L: raise TestFailed, 'long(u"-3")'
|
if long(u"-3") != -3L: raise TestFailed, 'long(u"-3")'
|
||||||
# Different base:
|
# Different base:
|
||||||
if long("10",16) <> 16L: raise TestFailed, 'long("10",16)'
|
if long("10",16) != 16L: raise TestFailed, 'long("10",16)'
|
||||||
if long(u"10",16) <> 16L: raise TestFailed, 'long(u"10",16)'
|
if long(u"10",16) != 16L: raise TestFailed, 'long(u"10",16)'
|
||||||
# Check conversions from string (same test set as for int(), and then some)
|
# Check conversions from string (same test set as for int(), and then some)
|
||||||
LL = [
|
LL = [
|
||||||
('1' + '0'*20, 10L**20),
|
('1' + '0'*20, 10L**20),
|
||||||
|
@ -430,33 +430,33 @@ for s, v in L + LL:
|
||||||
raise TestFailed, "long(%s) raised ValueError: %s" % (`ss`, e)
|
raise TestFailed, "long(%s) raised ValueError: %s" % (`ss`, e)
|
||||||
|
|
||||||
print 'map'
|
print 'map'
|
||||||
if map(None, 'hello world') <> ['h','e','l','l','o',' ','w','o','r','l','d']:
|
if map(None, 'hello world') != ['h','e','l','l','o',' ','w','o','r','l','d']:
|
||||||
raise TestFailed, 'map(None, \'hello world\')'
|
raise TestFailed, 'map(None, \'hello world\')'
|
||||||
if map(None, 'abcd', 'efg') <> \
|
if map(None, 'abcd', 'efg') != \
|
||||||
[('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
|
[('a', 'e'), ('b', 'f'), ('c', 'g'), ('d', None)]:
|
||||||
raise TestFailed, 'map(None, \'abcd\', \'efg\')'
|
raise TestFailed, 'map(None, \'abcd\', \'efg\')'
|
||||||
if map(None, range(10)) <> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
|
if map(None, range(10)) != [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
|
||||||
raise TestFailed, 'map(None, range(10))'
|
raise TestFailed, 'map(None, range(10))'
|
||||||
if map(lambda x: x*x, range(1,4)) <> [1, 4, 9]:
|
if map(lambda x: x*x, range(1,4)) != [1, 4, 9]:
|
||||||
raise TestFailed, 'map(lambda x: x*x, range(1,4))'
|
raise TestFailed, 'map(lambda x: x*x, range(1,4))'
|
||||||
try:
|
try:
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
except ImportError:
|
except ImportError:
|
||||||
def sqrt(x):
|
def sqrt(x):
|
||||||
return pow(x, 0.5)
|
return pow(x, 0.5)
|
||||||
if map(lambda x: map(sqrt,x), [[16, 4], [81, 9]]) <> [[4.0, 2.0], [9.0, 3.0]]:
|
if map(lambda x: map(sqrt,x), [[16, 4], [81, 9]]) != [[4.0, 2.0], [9.0, 3.0]]:
|
||||||
raise TestFailed, 'map(lambda x: map(sqrt,x), [[16, 4], [81, 9]])'
|
raise TestFailed, 'map(lambda x: map(sqrt,x), [[16, 4], [81, 9]])'
|
||||||
if map(lambda x, y: x+y, [1,3,2], [9,1,4]) <> [10, 4, 6]:
|
if map(lambda x, y: x+y, [1,3,2], [9,1,4]) != [10, 4, 6]:
|
||||||
raise TestFailed, 'map(lambda x,y: x+y, [1,3,2], [9,1,4])'
|
raise TestFailed, 'map(lambda x,y: x+y, [1,3,2], [9,1,4])'
|
||||||
def plus(*v):
|
def plus(*v):
|
||||||
accu = 0
|
accu = 0
|
||||||
for i in v: accu = accu + i
|
for i in v: accu = accu + i
|
||||||
return accu
|
return accu
|
||||||
if map(plus, [1, 3, 7]) <> [1, 3, 7]:
|
if map(plus, [1, 3, 7]) != [1, 3, 7]:
|
||||||
raise TestFailed, 'map(plus, [1, 3, 7])'
|
raise TestFailed, 'map(plus, [1, 3, 7])'
|
||||||
if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]:
|
if map(plus, [1, 3, 7], [4, 9, 2]) != [1+4, 3+9, 7+2]:
|
||||||
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
|
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
|
||||||
if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]:
|
if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) != [1+4+1, 3+9+1, 7+2+0]:
|
||||||
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
|
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
|
||||||
if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
|
if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
|
||||||
raise TestFailed, 'map(None, Squares(10))'
|
raise TestFailed, 'map(None, Squares(10))'
|
||||||
|
@ -468,21 +468,21 @@ if map(max, Squares(3), Squares(2)) != [0, 1, None]:
|
||||||
raise TestFailed, 'map(max, Squares(3), Squares(2))'
|
raise TestFailed, 'map(max, Squares(3), Squares(2))'
|
||||||
|
|
||||||
print 'max'
|
print 'max'
|
||||||
if max('123123') <> '3': raise TestFailed, 'max(\'123123\')'
|
if max('123123') != '3': raise TestFailed, 'max(\'123123\')'
|
||||||
if max(1, 2, 3) <> 3: raise TestFailed, 'max(1, 2, 3)'
|
if max(1, 2, 3) != 3: raise TestFailed, 'max(1, 2, 3)'
|
||||||
if max((1, 2, 3, 1, 2, 3)) <> 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))'
|
if max((1, 2, 3, 1, 2, 3)) != 3: raise TestFailed, 'max((1, 2, 3, 1, 2, 3))'
|
||||||
if max([1, 2, 3, 1, 2, 3]) <> 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])'
|
if max([1, 2, 3, 1, 2, 3]) != 3: raise TestFailed, 'max([1, 2, 3, 1, 2, 3])'
|
||||||
#
|
#
|
||||||
if max(1, 2L, 3.0) <> 3.0: raise TestFailed, 'max(1, 2L, 3.0)'
|
if max(1, 2L, 3.0) != 3.0: raise TestFailed, 'max(1, 2L, 3.0)'
|
||||||
if max(1L, 2.0, 3) <> 3: raise TestFailed, 'max(1L, 2.0, 3)'
|
if max(1L, 2.0, 3) != 3: raise TestFailed, 'max(1L, 2.0, 3)'
|
||||||
if max(1.0, 2, 3L) <> 3L: raise TestFailed, 'max(1.0, 2, 3L)'
|
if max(1.0, 2, 3L) != 3L: raise TestFailed, 'max(1.0, 2, 3L)'
|
||||||
|
|
||||||
print 'min'
|
print 'min'
|
||||||
if min('123123') <> '1': raise TestFailed, 'min(\'123123\')'
|
if min('123123') != '1': raise TestFailed, 'min(\'123123\')'
|
||||||
if min(1, 2, 3) <> 1: raise TestFailed, 'min(1, 2, 3)'
|
if min(1, 2, 3) != 1: raise TestFailed, 'min(1, 2, 3)'
|
||||||
if min((1, 2, 3, 1, 2, 3)) <> 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))'
|
if min((1, 2, 3, 1, 2, 3)) != 1: raise TestFailed, 'min((1, 2, 3, 1, 2, 3))'
|
||||||
if min([1, 2, 3, 1, 2, 3]) <> 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])'
|
if min([1, 2, 3, 1, 2, 3]) != 1: raise TestFailed, 'min([1, 2, 3, 1, 2, 3])'
|
||||||
#
|
#
|
||||||
if min(1, 2L, 3.0) <> 1: raise TestFailed, 'min(1, 2L, 3.0)'
|
if min(1, 2L, 3.0) != 1: raise TestFailed, 'min(1, 2L, 3.0)'
|
||||||
if min(1L, 2.0, 3) <> 1L: raise TestFailed, 'min(1L, 2.0, 3)'
|
if min(1L, 2.0, 3) != 1L: raise TestFailed, 'min(1L, 2.0, 3)'
|
||||||
if min(1.0, 2, 3L) <> 1.0: raise TestFailed, 'min(1.0, 2, 3L)'
|
if min(1.0, 2, 3L) != 1.0: raise TestFailed, 'min(1.0, 2, 3L)'
|
||||||
|
|
|
@ -25,52 +25,52 @@ finally:
|
||||||
#
|
#
|
||||||
fp = open(TESTFN, 'r')
|
fp = open(TESTFN, 'r')
|
||||||
try:
|
try:
|
||||||
if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact'
|
if fp.readline(4) != '1+1\n': raise TestFailed, 'readline(4) # exact'
|
||||||
if fp.readline(4) <> '1+1\n': raise TestFailed, 'readline(4) # exact'
|
if fp.readline(4) != '1+1\n': raise TestFailed, 'readline(4) # exact'
|
||||||
if fp.readline() <> 'The quick brown fox jumps over the lazy dog.\n':
|
if fp.readline() != 'The quick brown fox jumps over the lazy dog.\n':
|
||||||
raise TestFailed, 'readline() # default'
|
raise TestFailed, 'readline() # default'
|
||||||
if fp.readline(4) <> 'Dear': raise TestFailed, 'readline(4) # short'
|
if fp.readline(4) != 'Dear': raise TestFailed, 'readline(4) # short'
|
||||||
if fp.readline(100) <> ' John\n': raise TestFailed, 'readline(100)'
|
if fp.readline(100) != ' John\n': raise TestFailed, 'readline(100)'
|
||||||
if fp.read(300) <> 'XXX'*100: raise TestFailed, 'read(300)'
|
if fp.read(300) != 'XXX'*100: raise TestFailed, 'read(300)'
|
||||||
if fp.read(1000) <> 'YYY'*100: raise TestFailed, 'read(1000) # truncate'
|
if fp.read(1000) != 'YYY'*100: raise TestFailed, 'read(1000) # truncate'
|
||||||
finally:
|
finally:
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
print 'ord'
|
print 'ord'
|
||||||
if ord(' ') <> 32: raise TestFailed, 'ord(\' \')'
|
if ord(' ') != 32: raise TestFailed, 'ord(\' \')'
|
||||||
if ord('A') <> 65: raise TestFailed, 'ord(\'A\')'
|
if ord('A') != 65: raise TestFailed, 'ord(\'A\')'
|
||||||
if ord('a') <> 97: raise TestFailed, 'ord(\'a\')'
|
if ord('a') != 97: raise TestFailed, 'ord(\'a\')'
|
||||||
|
|
||||||
print 'pow'
|
print 'pow'
|
||||||
if pow(0,0) <> 1: raise TestFailed, 'pow(0,0)'
|
if pow(0,0) != 1: raise TestFailed, 'pow(0,0)'
|
||||||
if pow(0,1) <> 0: raise TestFailed, 'pow(0,1)'
|
if pow(0,1) != 0: raise TestFailed, 'pow(0,1)'
|
||||||
if pow(1,0) <> 1: raise TestFailed, 'pow(1,0)'
|
if pow(1,0) != 1: raise TestFailed, 'pow(1,0)'
|
||||||
if pow(1,1) <> 1: raise TestFailed, 'pow(1,1)'
|
if pow(1,1) != 1: raise TestFailed, 'pow(1,1)'
|
||||||
#
|
#
|
||||||
if pow(2,0) <> 1: raise TestFailed, 'pow(2,0)'
|
if pow(2,0) != 1: raise TestFailed, 'pow(2,0)'
|
||||||
if pow(2,10) <> 1024: raise TestFailed, 'pow(2,10)'
|
if pow(2,10) != 1024: raise TestFailed, 'pow(2,10)'
|
||||||
if pow(2,20) <> 1024*1024: raise TestFailed, 'pow(2,20)'
|
if pow(2,20) != 1024*1024: raise TestFailed, 'pow(2,20)'
|
||||||
if pow(2,30) <> 1024*1024*1024: raise TestFailed, 'pow(2,30)'
|
if pow(2,30) != 1024*1024*1024: raise TestFailed, 'pow(2,30)'
|
||||||
#
|
#
|
||||||
if pow(-2,0) <> 1: raise TestFailed, 'pow(-2,0)'
|
if pow(-2,0) != 1: raise TestFailed, 'pow(-2,0)'
|
||||||
if pow(-2,1) <> -2: raise TestFailed, 'pow(-2,1)'
|
if pow(-2,1) != -2: raise TestFailed, 'pow(-2,1)'
|
||||||
if pow(-2,2) <> 4: raise TestFailed, 'pow(-2,2)'
|
if pow(-2,2) != 4: raise TestFailed, 'pow(-2,2)'
|
||||||
if pow(-2,3) <> -8: raise TestFailed, 'pow(-2,3)'
|
if pow(-2,3) != -8: raise TestFailed, 'pow(-2,3)'
|
||||||
#
|
#
|
||||||
if pow(0L,0) <> 1: raise TestFailed, 'pow(0L,0)'
|
if pow(0L,0) != 1: raise TestFailed, 'pow(0L,0)'
|
||||||
if pow(0L,1) <> 0: raise TestFailed, 'pow(0L,1)'
|
if pow(0L,1) != 0: raise TestFailed, 'pow(0L,1)'
|
||||||
if pow(1L,0) <> 1: raise TestFailed, 'pow(1L,0)'
|
if pow(1L,0) != 1: raise TestFailed, 'pow(1L,0)'
|
||||||
if pow(1L,1) <> 1: raise TestFailed, 'pow(1L,1)'
|
if pow(1L,1) != 1: raise TestFailed, 'pow(1L,1)'
|
||||||
#
|
#
|
||||||
if pow(2L,0) <> 1: raise TestFailed, 'pow(2L,0)'
|
if pow(2L,0) != 1: raise TestFailed, 'pow(2L,0)'
|
||||||
if pow(2L,10) <> 1024: raise TestFailed, 'pow(2L,10)'
|
if pow(2L,10) != 1024: raise TestFailed, 'pow(2L,10)'
|
||||||
if pow(2L,20) <> 1024*1024: raise TestFailed, 'pow(2L,20)'
|
if pow(2L,20) != 1024*1024: raise TestFailed, 'pow(2L,20)'
|
||||||
if pow(2L,30) <> 1024*1024*1024: raise TestFailed, 'pow(2L,30)'
|
if pow(2L,30) != 1024*1024*1024: raise TestFailed, 'pow(2L,30)'
|
||||||
#
|
#
|
||||||
if pow(-2L,0) <> 1: raise TestFailed, 'pow(-2L,0)'
|
if pow(-2L,0) != 1: raise TestFailed, 'pow(-2L,0)'
|
||||||
if pow(-2L,1) <> -2: raise TestFailed, 'pow(-2L,1)'
|
if pow(-2L,1) != -2: raise TestFailed, 'pow(-2L,1)'
|
||||||
if pow(-2L,2) <> 4: raise TestFailed, 'pow(-2L,2)'
|
if pow(-2L,2) != 4: raise TestFailed, 'pow(-2L,2)'
|
||||||
if pow(-2L,3) <> -8: raise TestFailed, 'pow(-2L,3)'
|
if pow(-2L,3) != -8: raise TestFailed, 'pow(-2L,3)'
|
||||||
#
|
#
|
||||||
if fcmp(pow(0.,0), 1.): raise TestFailed, 'pow(0.,0)'
|
if fcmp(pow(0.,0), 1.): raise TestFailed, 'pow(0.,0)'
|
||||||
if fcmp(pow(0.,1), 0.): raise TestFailed, 'pow(0.,1)'
|
if fcmp(pow(0.,1), 0.): raise TestFailed, 'pow(0.,1)'
|
||||||
|
@ -95,12 +95,12 @@ for x in 2, 2L, 2.0:
|
||||||
raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
|
raise TestFailed, 'pow(%s, %s, %s)' % (x, y, z)
|
||||||
|
|
||||||
print 'range'
|
print 'range'
|
||||||
if range(3) <> [0, 1, 2]: raise TestFailed, 'range(3)'
|
if range(3) != [0, 1, 2]: raise TestFailed, 'range(3)'
|
||||||
if range(1, 5) <> [1, 2, 3, 4]: raise TestFailed, 'range(1, 5)'
|
if range(1, 5) != [1, 2, 3, 4]: raise TestFailed, 'range(1, 5)'
|
||||||
if range(0) <> []: raise TestFailed, 'range(0)'
|
if range(0) != []: raise TestFailed, 'range(0)'
|
||||||
if range(-3) <> []: raise TestFailed, 'range(-3)'
|
if range(-3) != []: raise TestFailed, 'range(-3)'
|
||||||
if range(1, 10, 3) <> [1, 4, 7]: raise TestFailed, 'range(1, 10, 3)'
|
if range(1, 10, 3) != [1, 4, 7]: raise TestFailed, 'range(1, 10, 3)'
|
||||||
if range(5, -5, -3) <> [5, 2, -1, -4]: raise TestFailed, 'range(5, -5, -3)'
|
if range(5, -5, -3) != [5, 2, -1, -4]: raise TestFailed, 'range(5, -5, -3)'
|
||||||
|
|
||||||
print 'input and raw_input'
|
print 'input and raw_input'
|
||||||
import sys
|
import sys
|
||||||
|
@ -108,25 +108,25 @@ fp = open(TESTFN, 'r')
|
||||||
savestdin = sys.stdin
|
savestdin = sys.stdin
|
||||||
try:
|
try:
|
||||||
sys.stdin = fp
|
sys.stdin = fp
|
||||||
if input() <> 2: raise TestFailed, 'input()'
|
if input() != 2: raise TestFailed, 'input()'
|
||||||
if input('testing\n') <> 2: raise TestFailed, 'input()'
|
if input('testing\n') != 2: raise TestFailed, 'input()'
|
||||||
if raw_input() <> 'The quick brown fox jumps over the lazy dog.':
|
if raw_input() != 'The quick brown fox jumps over the lazy dog.':
|
||||||
raise TestFailed, 'raw_input()'
|
raise TestFailed, 'raw_input()'
|
||||||
if raw_input('testing\n') <> 'Dear John':
|
if raw_input('testing\n') != 'Dear John':
|
||||||
raise TestFailed, 'raw_input(\'testing\\n\')'
|
raise TestFailed, 'raw_input(\'testing\\n\')'
|
||||||
finally:
|
finally:
|
||||||
sys.stdin = savestdin
|
sys.stdin = savestdin
|
||||||
fp.close()
|
fp.close()
|
||||||
|
|
||||||
print 'reduce'
|
print 'reduce'
|
||||||
if reduce(lambda x, y: x+y, ['a', 'b', 'c'], '') <> 'abc':
|
if reduce(lambda x, y: x+y, ['a', 'b', 'c'], '') != 'abc':
|
||||||
raise TestFailed, 'reduce(): implode a string'
|
raise TestFailed, 'reduce(): implode a string'
|
||||||
if reduce(lambda x, y: x+y,
|
if reduce(lambda x, y: x+y,
|
||||||
[['a', 'c'], [], ['d', 'w']], []) <> ['a','c','d','w']:
|
[['a', 'c'], [], ['d', 'w']], []) != ['a','c','d','w']:
|
||||||
raise TestFailed, 'reduce(): append'
|
raise TestFailed, 'reduce(): append'
|
||||||
if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040:
|
if reduce(lambda x, y: x*y, range(2,8), 1) != 5040:
|
||||||
raise TestFailed, 'reduce(): compute 7!'
|
raise TestFailed, 'reduce(): compute 7!'
|
||||||
if reduce(lambda x, y: x*y, range(2,21), 1L) <> 2432902008176640000L:
|
if reduce(lambda x, y: x*y, range(2,21), 1L) != 2432902008176640000L:
|
||||||
raise TestFailed, 'reduce(): compute 20!, use long'
|
raise TestFailed, 'reduce(): compute 20!, use long'
|
||||||
class Squares:
|
class Squares:
|
||||||
def __init__(self, max):
|
def __init__(self, max):
|
||||||
|
@ -159,46 +159,46 @@ reload(string)
|
||||||
## else: raise TestFailed, 'reload(sys) should fail'
|
## else: raise TestFailed, 'reload(sys) should fail'
|
||||||
|
|
||||||
print 'repr'
|
print 'repr'
|
||||||
if repr('') <> '\'\'': raise TestFailed, 'repr(\'\')'
|
if repr('') != '\'\'': raise TestFailed, 'repr(\'\')'
|
||||||
if repr(0) <> '0': raise TestFailed, 'repr(0)'
|
if repr(0) != '0': raise TestFailed, 'repr(0)'
|
||||||
if repr(0L) <> '0L': raise TestFailed, 'repr(0L)'
|
if repr(0L) != '0L': raise TestFailed, 'repr(0L)'
|
||||||
if repr(()) <> '()': raise TestFailed, 'repr(())'
|
if repr(()) != '()': raise TestFailed, 'repr(())'
|
||||||
if repr([]) <> '[]': raise TestFailed, 'repr([])'
|
if repr([]) != '[]': raise TestFailed, 'repr([])'
|
||||||
if repr({}) <> '{}': raise TestFailed, 'repr({})'
|
if repr({}) != '{}': raise TestFailed, 'repr({})'
|
||||||
|
|
||||||
print 'round'
|
print 'round'
|
||||||
if round(0.0) <> 0.0: raise TestFailed, 'round(0.0)'
|
if round(0.0) != 0.0: raise TestFailed, 'round(0.0)'
|
||||||
if round(1.0) <> 1.0: raise TestFailed, 'round(1.0)'
|
if round(1.0) != 1.0: raise TestFailed, 'round(1.0)'
|
||||||
if round(10.0) <> 10.0: raise TestFailed, 'round(10.0)'
|
if round(10.0) != 10.0: raise TestFailed, 'round(10.0)'
|
||||||
if round(1000000000.0) <> 1000000000.0:
|
if round(1000000000.0) != 1000000000.0:
|
||||||
raise TestFailed, 'round(1000000000.0)'
|
raise TestFailed, 'round(1000000000.0)'
|
||||||
if round(1e20) <> 1e20: raise TestFailed, 'round(1e20)'
|
if round(1e20) != 1e20: raise TestFailed, 'round(1e20)'
|
||||||
|
|
||||||
if round(-1.0) <> -1.0: raise TestFailed, 'round(-1.0)'
|
if round(-1.0) != -1.0: raise TestFailed, 'round(-1.0)'
|
||||||
if round(-10.0) <> -10.0: raise TestFailed, 'round(-10.0)'
|
if round(-10.0) != -10.0: raise TestFailed, 'round(-10.0)'
|
||||||
if round(-1000000000.0) <> -1000000000.0:
|
if round(-1000000000.0) != -1000000000.0:
|
||||||
raise TestFailed, 'round(-1000000000.0)'
|
raise TestFailed, 'round(-1000000000.0)'
|
||||||
if round(-1e20) <> -1e20: raise TestFailed, 'round(-1e20)'
|
if round(-1e20) != -1e20: raise TestFailed, 'round(-1e20)'
|
||||||
|
|
||||||
if round(0.1) <> 0.0: raise TestFailed, 'round(0.0)'
|
if round(0.1) != 0.0: raise TestFailed, 'round(0.0)'
|
||||||
if round(1.1) <> 1.0: raise TestFailed, 'round(1.0)'
|
if round(1.1) != 1.0: raise TestFailed, 'round(1.0)'
|
||||||
if round(10.1) <> 10.0: raise TestFailed, 'round(10.0)'
|
if round(10.1) != 10.0: raise TestFailed, 'round(10.0)'
|
||||||
if round(1000000000.1) <> 1000000000.0:
|
if round(1000000000.1) != 1000000000.0:
|
||||||
raise TestFailed, 'round(1000000000.0)'
|
raise TestFailed, 'round(1000000000.0)'
|
||||||
|
|
||||||
if round(-1.1) <> -1.0: raise TestFailed, 'round(-1.0)'
|
if round(-1.1) != -1.0: raise TestFailed, 'round(-1.0)'
|
||||||
if round(-10.1) <> -10.0: raise TestFailed, 'round(-10.0)'
|
if round(-10.1) != -10.0: raise TestFailed, 'round(-10.0)'
|
||||||
if round(-1000000000.1) <> -1000000000.0:
|
if round(-1000000000.1) != -1000000000.0:
|
||||||
raise TestFailed, 'round(-1000000000.0)'
|
raise TestFailed, 'round(-1000000000.0)'
|
||||||
|
|
||||||
if round(0.9) <> 1.0: raise TestFailed, 'round(0.9)'
|
if round(0.9) != 1.0: raise TestFailed, 'round(0.9)'
|
||||||
if round(9.9) <> 10.0: raise TestFailed, 'round(9.9)'
|
if round(9.9) != 10.0: raise TestFailed, 'round(9.9)'
|
||||||
if round(999999999.9) <> 1000000000.0:
|
if round(999999999.9) != 1000000000.0:
|
||||||
raise TestFailed, 'round(999999999.9)'
|
raise TestFailed, 'round(999999999.9)'
|
||||||
|
|
||||||
if round(-0.9) <> -1.0: raise TestFailed, 'round(-0.9)'
|
if round(-0.9) != -1.0: raise TestFailed, 'round(-0.9)'
|
||||||
if round(-9.9) <> -10.0: raise TestFailed, 'round(-9.9)'
|
if round(-9.9) != -10.0: raise TestFailed, 'round(-9.9)'
|
||||||
if round(-999999999.9) <> -1000000000.0:
|
if round(-999999999.9) != -1000000000.0:
|
||||||
raise TestFailed, 'round(-999999999.9)'
|
raise TestFailed, 'round(-999999999.9)'
|
||||||
|
|
||||||
print 'setattr'
|
print 'setattr'
|
||||||
|
@ -207,23 +207,23 @@ setattr(sys, 'spam', 1)
|
||||||
if sys.spam != 1: raise TestFailed, 'setattr(sys, \'spam\', 1)'
|
if sys.spam != 1: raise TestFailed, 'setattr(sys, \'spam\', 1)'
|
||||||
|
|
||||||
print 'str'
|
print 'str'
|
||||||
if str('') <> '': raise TestFailed, 'str(\'\')'
|
if str('') != '': raise TestFailed, 'str(\'\')'
|
||||||
if str(0) <> '0': raise TestFailed, 'str(0)'
|
if str(0) != '0': raise TestFailed, 'str(0)'
|
||||||
if str(0L) <> '0': raise TestFailed, 'str(0L)'
|
if str(0L) != '0': raise TestFailed, 'str(0L)'
|
||||||
if str(()) <> '()': raise TestFailed, 'str(())'
|
if str(()) != '()': raise TestFailed, 'str(())'
|
||||||
if str([]) <> '[]': raise TestFailed, 'str([])'
|
if str([]) != '[]': raise TestFailed, 'str([])'
|
||||||
if str({}) <> '{}': raise TestFailed, 'str({})'
|
if str({}) != '{}': raise TestFailed, 'str({})'
|
||||||
|
|
||||||
print 'tuple'
|
print 'tuple'
|
||||||
if tuple(()) <> (): raise TestFailed, 'tuple(())'
|
if tuple(()) != (): raise TestFailed, 'tuple(())'
|
||||||
if tuple((0, 1, 2, 3)) <> (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))'
|
if tuple((0, 1, 2, 3)) != (0, 1, 2, 3): raise TestFailed, 'tuple((0, 1, 2, 3))'
|
||||||
if tuple([]) <> (): raise TestFailed, 'tuple([])'
|
if tuple([]) != (): raise TestFailed, 'tuple([])'
|
||||||
if tuple([0, 1, 2, 3]) <> (0, 1, 2, 3): raise TestFailed, 'tuple([0, 1, 2, 3])'
|
if tuple([0, 1, 2, 3]) != (0, 1, 2, 3): raise TestFailed, 'tuple([0, 1, 2, 3])'
|
||||||
if tuple('') <> (): raise TestFailed, 'tuple('')'
|
if tuple('') != (): raise TestFailed, 'tuple('')'
|
||||||
if tuple('spam') <> ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')"
|
if tuple('spam') != ('s', 'p', 'a', 'm'): raise TestFailed, "tuple('spam')"
|
||||||
|
|
||||||
print 'type'
|
print 'type'
|
||||||
if type('') <> type('123') or type('') == type(()):
|
if type('') != type('123') or type('') == type(()):
|
||||||
raise TestFailed, 'type()'
|
raise TestFailed, 'type()'
|
||||||
|
|
||||||
print 'vars'
|
print 'vars'
|
||||||
|
@ -232,13 +232,13 @@ a = vars().keys()
|
||||||
b = dir()
|
b = dir()
|
||||||
a.sort()
|
a.sort()
|
||||||
b.sort()
|
b.sort()
|
||||||
if a <> b: raise TestFailed, 'vars()'
|
if a != b: raise TestFailed, 'vars()'
|
||||||
import sys
|
import sys
|
||||||
a = vars(sys).keys()
|
a = vars(sys).keys()
|
||||||
b = dir(sys)
|
b = dir(sys)
|
||||||
a.sort()
|
a.sort()
|
||||||
b.sort()
|
b.sort()
|
||||||
if a <> b: raise TestFailed, 'vars(sys)'
|
if a != b: raise TestFailed, 'vars(sys)'
|
||||||
def f0():
|
def f0():
|
||||||
if vars() != {}: raise TestFailed, 'vars() in f0()'
|
if vars() != {}: raise TestFailed, 'vars() in f0()'
|
||||||
f0()
|
f0()
|
||||||
|
@ -250,9 +250,9 @@ def f2():
|
||||||
f2()
|
f2()
|
||||||
|
|
||||||
print 'xrange'
|
print 'xrange'
|
||||||
if tuple(xrange(10)) <> tuple(range(10)): raise TestFailed, 'xrange(10)'
|
if tuple(xrange(10)) != tuple(range(10)): raise TestFailed, 'xrange(10)'
|
||||||
if tuple(xrange(5,10)) <> tuple(range(5,10)): raise TestFailed, 'xrange(5,10)'
|
if tuple(xrange(5,10)) != tuple(range(5,10)): raise TestFailed, 'xrange(5,10)'
|
||||||
if tuple(xrange(0,10,2)) <> tuple(range(0,10,2)):
|
if tuple(xrange(0,10,2)) != tuple(range(0,10,2)):
|
||||||
raise TestFailed, 'xrange(0,10,2)'
|
raise TestFailed, 'xrange(0,10,2)'
|
||||||
# regression tests for SourceForge bug #121695
|
# regression tests for SourceForge bug #121695
|
||||||
def _range_test(r):
|
def _range_test(r):
|
||||||
|
@ -273,16 +273,16 @@ print 'zip'
|
||||||
a = (1, 2, 3)
|
a = (1, 2, 3)
|
||||||
b = (4, 5, 6)
|
b = (4, 5, 6)
|
||||||
t = [(1, 4), (2, 5), (3, 6)]
|
t = [(1, 4), (2, 5), (3, 6)]
|
||||||
if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, both tuples'
|
if zip(a, b) != t: raise TestFailed, 'zip(a, b) - same size, both tuples'
|
||||||
b = [4, 5, 6]
|
b = [4, 5, 6]
|
||||||
if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - same size, tuple/list'
|
if zip(a, b) != t: raise TestFailed, 'zip(a, b) - same size, tuple/list'
|
||||||
b = (4, 5, 6, 7)
|
b = (4, 5, 6, 7)
|
||||||
if zip(a, b) <> t: raise TestFailed, 'zip(a, b) - b is longer'
|
if zip(a, b) != t: raise TestFailed, 'zip(a, b) - b is longer'
|
||||||
class I:
|
class I:
|
||||||
def __getitem__(self, i):
|
def __getitem__(self, i):
|
||||||
if i < 0 or i > 2: raise IndexError
|
if i < 0 or i > 2: raise IndexError
|
||||||
return i + 4
|
return i + 4
|
||||||
if zip(a, I()) <> t: raise TestFailed, 'zip(a, b) - b is instance'
|
if zip(a, I()) != t: raise TestFailed, 'zip(a, b) - b is instance'
|
||||||
exc = 0
|
exc = 0
|
||||||
try:
|
try:
|
||||||
zip()
|
zip()
|
||||||
|
|
|
@ -96,7 +96,7 @@ if crc != 1571220330:
|
||||||
s = '{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'
|
s = '{s\005\000\000\000worldi\002\000\000\000s\005\000\000\000helloi\001\000\000\0000'
|
||||||
t = binascii.b2a_hex(s)
|
t = binascii.b2a_hex(s)
|
||||||
u = binascii.a2b_hex(t)
|
u = binascii.a2b_hex(t)
|
||||||
if s <> u:
|
if s != u:
|
||||||
print 'binascii hexlification failed'
|
print 'binascii hexlification failed'
|
||||||
try:
|
try:
|
||||||
binascii.a2b_hex(t[:-1])
|
binascii.a2b_hex(t[:-1])
|
||||||
|
|
|
@ -32,8 +32,8 @@ def test():
|
||||||
f = open(fname1, 'r')
|
f = open(fname1, 'r')
|
||||||
finish = f.readline()
|
finish = f.readline()
|
||||||
|
|
||||||
if start <> finish:
|
if start != finish:
|
||||||
print 'Error: binhex <> hexbin'
|
print 'Error: binhex != hexbin'
|
||||||
elif verbose:
|
elif verbose:
|
||||||
print 'binhex == hexbin'
|
print 'binhex == hexbin'
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ def test(openmethod, what):
|
||||||
try:
|
try:
|
||||||
rec = f.next()
|
rec = f.next()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
if rec <> f.last():
|
if rec != f.last():
|
||||||
print 'Error, last <> last!'
|
print 'Error, last != last!'
|
||||||
f.previous()
|
f.previous()
|
||||||
break
|
break
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -12,17 +12,17 @@ print '1.1.1 Backslashes'
|
||||||
# Backslash means line continuation:
|
# Backslash means line continuation:
|
||||||
x = 1 \
|
x = 1 \
|
||||||
+ 1
|
+ 1
|
||||||
if x <> 2: raise TestFailed, 'backslash for line continuation'
|
if x != 2: raise TestFailed, 'backslash for line continuation'
|
||||||
|
|
||||||
# Backslash does not means continuation in comments :\
|
# Backslash does not means continuation in comments :\
|
||||||
x = 0
|
x = 0
|
||||||
if x <> 0: raise TestFailed, 'backslash ending comment'
|
if x != 0: raise TestFailed, 'backslash ending comment'
|
||||||
|
|
||||||
print '1.1.2 Numeric literals'
|
print '1.1.2 Numeric literals'
|
||||||
|
|
||||||
print '1.1.2.1 Plain integers'
|
print '1.1.2.1 Plain integers'
|
||||||
if 0xff <> 255: raise TestFailed, 'hex int'
|
if 0xff != 255: raise TestFailed, 'hex int'
|
||||||
if 0377 <> 255: raise TestFailed, 'octal int'
|
if 0377 != 255: raise TestFailed, 'octal int'
|
||||||
if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
|
if 2147483647 != 017777777777: raise TestFailed, 'large positive int'
|
||||||
try:
|
try:
|
||||||
from sys import maxint
|
from sys import maxint
|
||||||
|
@ -359,28 +359,28 @@ def f():
|
||||||
z = None
|
z = None
|
||||||
del z
|
del z
|
||||||
exec 'z=1+1\n'
|
exec 'z=1+1\n'
|
||||||
if z <> 2: raise TestFailed, 'exec \'z=1+1\'\\n'
|
if z != 2: raise TestFailed, 'exec \'z=1+1\'\\n'
|
||||||
del z
|
del z
|
||||||
exec 'z=1+1'
|
exec 'z=1+1'
|
||||||
if z <> 2: raise TestFailed, 'exec \'z=1+1\''
|
if z != 2: raise TestFailed, 'exec \'z=1+1\''
|
||||||
z = None
|
z = None
|
||||||
del z
|
del z
|
||||||
exec u'z=1+1\n'
|
exec u'z=1+1\n'
|
||||||
if z <> 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
if z != 2: raise TestFailed, 'exec u\'z=1+1\'\\n'
|
||||||
del z
|
del z
|
||||||
exec u'z=1+1'
|
exec u'z=1+1'
|
||||||
if z <> 2: raise TestFailed, 'exec u\'z=1+1\''
|
if z != 2: raise TestFailed, 'exec u\'z=1+1\''
|
||||||
f()
|
f()
|
||||||
g = {}
|
g = {}
|
||||||
exec 'z = 1' in g
|
exec 'z = 1' in g
|
||||||
if g.has_key('__builtins__'): del g['__builtins__']
|
if g.has_key('__builtins__'): del g['__builtins__']
|
||||||
if g <> {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
|
if g != {'z': 1}: raise TestFailed, 'exec \'z = 1\' in g'
|
||||||
g = {}
|
g = {}
|
||||||
l = {}
|
l = {}
|
||||||
exec 'global a; a = 1; b = 2' in g, l
|
exec 'global a; a = 1; b = 2' in g, l
|
||||||
if g.has_key('__builtins__'): del g['__builtins__']
|
if g.has_key('__builtins__'): del g['__builtins__']
|
||||||
if l.has_key('__builtins__'): del l['__builtins__']
|
if l.has_key('__builtins__'): del l['__builtins__']
|
||||||
if (g, l) <> ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l'
|
if (g, l) != ({'a':1}, {'b':2}): raise TestFailed, 'exec ... in g, l'
|
||||||
|
|
||||||
|
|
||||||
### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
|
### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
|
||||||
|
|
|
@ -85,7 +85,7 @@ testit('fmod(-10,1.5)', math.fmod(-10,1.5), -1)
|
||||||
|
|
||||||
print 'frexp'
|
print 'frexp'
|
||||||
def testfrexp(name, (mant, exp), (emant, eexp)):
|
def testfrexp(name, (mant, exp), (emant, eexp)):
|
||||||
if abs(mant-emant) > eps or exp <> eexp:
|
if abs(mant-emant) > eps or exp != eexp:
|
||||||
raise TestFailed, '%s returned %s, expected %s'%\
|
raise TestFailed, '%s returned %s, expected %s'%\
|
||||||
(name, `mant, exp`, `emant,eexp`)
|
(name, `mant, exp`, `emant,eexp`)
|
||||||
|
|
||||||
|
|
|
@ -26,5 +26,5 @@ print md5test('12345678901234567890123456789012345678901234567890123456789012345
|
||||||
# hexdigest is new with Python 2.0
|
# hexdigest is new with Python 2.0
|
||||||
m = md5('testing the hexdigest method')
|
m = md5('testing the hexdigest method')
|
||||||
h = m.hexdigest()
|
h = m.hexdigest()
|
||||||
if hexstr(m.digest()) <> h:
|
if hexstr(m.digest()) != h:
|
||||||
print 'hexdigest() failed'
|
print 'hexdigest() failed'
|
||||||
|
|
|
@ -46,7 +46,7 @@ def test_both():
|
||||||
|
|
||||||
# Test doing a regular expression match in an mmap'ed file
|
# Test doing a regular expression match in an mmap'ed file
|
||||||
match=re.search('[A-Za-z]+', m)
|
match=re.search('[A-Za-z]+', m)
|
||||||
if match == None:
|
if match is None:
|
||||||
print ' ERROR: regex match on mmap failed!'
|
print ' ERROR: regex match on mmap failed!'
|
||||||
else:
|
else:
|
||||||
start, end = match.span(0)
|
start, end = match.span(0)
|
||||||
|
|
|
@ -33,10 +33,10 @@ im = new.instancemethod(break_yolks, c, C)
|
||||||
if verbose:
|
if verbose:
|
||||||
print im
|
print im
|
||||||
|
|
||||||
if c.get_yolks() <> 3 and c.get_more_yolks() <> 6:
|
if c.get_yolks() != 3 and c.get_more_yolks() != 6:
|
||||||
print 'Broken call of hand-crafted class instance'
|
print 'Broken call of hand-crafted class instance'
|
||||||
im()
|
im()
|
||||||
if c.get_yolks() <> 1 and c.get_more_yolks() <> 4:
|
if c.get_yolks() != 1 and c.get_more_yolks() != 4:
|
||||||
print 'Broken call of hand-crafted instance method'
|
print 'Broken call of hand-crafted instance method'
|
||||||
|
|
||||||
codestr = '''
|
codestr = '''
|
||||||
|
@ -53,7 +53,7 @@ func = new.function(ccode, g)
|
||||||
if verbose:
|
if verbose:
|
||||||
print func
|
print func
|
||||||
func()
|
func()
|
||||||
if g['c'] <> 3:
|
if g['c'] != 3:
|
||||||
print 'Could not create a proper function object'
|
print 'Could not create a proper function object'
|
||||||
|
|
||||||
# bogus test of new.code()
|
# bogus test of new.code()
|
||||||
|
|
|
@ -21,7 +21,7 @@ for nismap in maps:
|
||||||
print ' ', k, v
|
print ' ', k, v
|
||||||
if not k:
|
if not k:
|
||||||
continue
|
continue
|
||||||
if nis.match(k, nismap) <> v:
|
if nis.match(k, nismap) != v:
|
||||||
print "NIS match failed for key `%s' in map `%s'" % (k, nismap)
|
print "NIS match failed for key `%s' in map `%s'" % (k, nismap)
|
||||||
else:
|
else:
|
||||||
# just test the one key, otherwise this test could take a
|
# just test the one key, otherwise this test could take a
|
||||||
|
|
|
@ -19,7 +19,7 @@ for i in range(10):
|
||||||
try: pass
|
try: pass
|
||||||
finally: pass
|
finally: pass
|
||||||
n = n+i
|
n = n+i
|
||||||
if n <> 90:
|
if n != 90:
|
||||||
raise TestFailed, 'try inside for'
|
raise TestFailed, 'try inside for'
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ def test(name, input, output, *args):
|
||||||
val = apply(f, params)
|
val = apply(f, params)
|
||||||
except:
|
except:
|
||||||
val = sys.exc_type
|
val = sys.exc_type
|
||||||
if val <> output:
|
if val != output:
|
||||||
print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
|
print '%s%s = %s: %s expected' % (f.__name__, params, `val`, `output`)
|
||||||
|
|
||||||
test('abs', -1, 1)
|
test('abs', -1, 1)
|
||||||
|
@ -21,12 +21,12 @@ test('countOf', [1, 2, 1, 3, 1, 4], 1, 3)
|
||||||
|
|
||||||
a = [4, 3, 2, 1]
|
a = [4, 3, 2, 1]
|
||||||
test('delitem', a, None, 1)
|
test('delitem', a, None, 1)
|
||||||
if a <> [4, 2, 1]:
|
if a != [4, 2, 1]:
|
||||||
print 'delitem() failed'
|
print 'delitem() failed'
|
||||||
|
|
||||||
a = range(10)
|
a = range(10)
|
||||||
test('delslice', a, None, 2, 8)
|
test('delslice', a, None, 2, 8)
|
||||||
if a <> [0, 1, 8, 9]:
|
if a != [0, 1, 8, 9]:
|
||||||
print 'delslice() failed'
|
print 'delslice() failed'
|
||||||
|
|
||||||
a = range(10)
|
a = range(10)
|
||||||
|
@ -59,12 +59,12 @@ test('sequenceIncludes', range(4), 1, 2)
|
||||||
test('sequenceIncludes', range(4), 0, 5)
|
test('sequenceIncludes', range(4), 0, 5)
|
||||||
|
|
||||||
test('setitem', a, None, 0, 2)
|
test('setitem', a, None, 0, 2)
|
||||||
if a <> [2, 1, 2]:
|
if a != [2, 1, 2]:
|
||||||
print 'setitem() failed'
|
print 'setitem() failed'
|
||||||
|
|
||||||
a = range(4)
|
a = range(4)
|
||||||
test('setslice', a, None, 1, 3, [2, 1])
|
test('setslice', a, None, 1, 3, [2, 1])
|
||||||
if a <> [0, 2, 1, 3]:
|
if a != [0, 2, 1, 3]:
|
||||||
print 'setslice() failed:', a
|
print 'setslice() failed:', a
|
||||||
|
|
||||||
test('sub', 5, 2, 3)
|
test('sub', 5, 2, 3)
|
||||||
|
|
|
@ -110,11 +110,11 @@ for i in range(-10, 11):
|
||||||
o = pow(i,j) % k
|
o = pow(i,j) % k
|
||||||
n = pow(i,j,k)
|
n = pow(i,j,k)
|
||||||
if o != n: print 'Integer mismatch:', i,j,k
|
if o != n: print 'Integer mismatch:', i,j,k
|
||||||
if j >= 0 and k <> 0:
|
if j >= 0 and k != 0:
|
||||||
o = pow(long(i),j) % k
|
o = pow(long(i),j) % k
|
||||||
n = pow(long(i),j,k)
|
n = pow(long(i),j,k)
|
||||||
if o != n: print 'Long mismatch:', i,j,k
|
if o != n: print 'Long mismatch:', i,j,k
|
||||||
if i >= 0 and k <> 0:
|
if i >= 0 and k != 0:
|
||||||
o = pow(float(i),j) % k
|
o = pow(float(i),j) % k
|
||||||
n = pow(float(i),j,k)
|
n = pow(float(i),j,k)
|
||||||
if o != n: print 'Float mismatch:', i,j,k
|
if o != n: print 'Float mismatch:', i,j,k
|
||||||
|
|
|
@ -81,7 +81,7 @@ else:
|
||||||
raise TestFailed, "pty.fork() failed to make child a session leader."
|
raise TestFailed, "pty.fork() failed to make child a session leader."
|
||||||
elif status / 256 == 3:
|
elif status / 256 == 3:
|
||||||
raise TestFailed, "Child spawned by pty.fork() did not have a tty as stdout"
|
raise TestFailed, "Child spawned by pty.fork() did not have a tty as stdout"
|
||||||
elif status / 256 <> 4:
|
elif status / 256 != 4:
|
||||||
raise TestFailed, "pty.fork() failed for unknown reasons:"
|
raise TestFailed, "pty.fork() failed for unknown reasons:"
|
||||||
print os.read(master_fd, 65536)
|
print os.read(master_fd, 65536)
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@ for e in entries:
|
||||||
print name, uid
|
print name, uid
|
||||||
print 'pwd.getpwuid()'
|
print 'pwd.getpwuid()'
|
||||||
dbuid = pwd.getpwuid(uid)
|
dbuid = pwd.getpwuid(uid)
|
||||||
if dbuid[0] <> name:
|
if dbuid[0] != name:
|
||||||
print 'Mismatch in pwd.getpwuid()'
|
print 'Mismatch in pwd.getpwuid()'
|
||||||
print 'pwd.getpwnam()'
|
print 'pwd.getpwnam()'
|
||||||
dbname = pwd.getpwnam(name)
|
dbname = pwd.getpwnam(name)
|
||||||
if dbname[2] <> uid:
|
if dbname[2] != uid:
|
||||||
print 'Mismatch in pwd.getpwnam()'
|
print 'Mismatch in pwd.getpwnam()'
|
||||||
else:
|
else:
|
||||||
print 'name matches uid'
|
print 'name matches uid'
|
||||||
|
|
|
@ -15,7 +15,7 @@ try:
|
||||||
assert re.search('x*', 'axx').span() == (0, 0)
|
assert re.search('x*', 'axx').span() == (0, 0)
|
||||||
assert re.search('x+', 'axx').span(0) == (1, 3)
|
assert re.search('x+', 'axx').span(0) == (1, 3)
|
||||||
assert re.search('x+', 'axx').span() == (1, 3)
|
assert re.search('x+', 'axx').span() == (1, 3)
|
||||||
assert re.search('x', 'aaa') == None
|
assert re.search('x', 'aaa') is None
|
||||||
except:
|
except:
|
||||||
raise TestFailed, "re.search"
|
raise TestFailed, "re.search"
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ try:
|
||||||
assert re.match('a*', 'xxx').span() == (0, 0)
|
assert re.match('a*', 'xxx').span() == (0, 0)
|
||||||
assert re.match('x*', 'xxxa').span(0) == (0, 3)
|
assert re.match('x*', 'xxxa').span(0) == (0, 3)
|
||||||
assert re.match('x*', 'xxxa').span() == (0, 3)
|
assert re.match('x*', 'xxxa').span() == (0, 3)
|
||||||
assert re.match('a+', 'xxx') == None
|
assert re.match('a+', 'xxx') is None
|
||||||
except:
|
except:
|
||||||
raise TestFailed, "re.search"
|
raise TestFailed, "re.search"
|
||||||
|
|
||||||
|
@ -216,11 +216,11 @@ try:
|
||||||
p=""
|
p=""
|
||||||
for i in range(0, 256):
|
for i in range(0, 256):
|
||||||
p = p + chr(i)
|
p = p + chr(i)
|
||||||
assert re.match(re.escape(chr(i)), chr(i)) != None
|
assert re.match(re.escape(chr(i)), chr(i)) is not None
|
||||||
assert re.match(re.escape(chr(i)), chr(i)).span() == (0,1)
|
assert re.match(re.escape(chr(i)), chr(i)).span() == (0,1)
|
||||||
|
|
||||||
pat=re.compile( re.escape(p) )
|
pat=re.compile( re.escape(p) )
|
||||||
assert pat.match(p) != None
|
assert pat.match(p) is not None
|
||||||
assert pat.match(p).span() == (0,256)
|
assert pat.match(p).span() == (0,256)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
raise TestFailed, "re.escape"
|
raise TestFailed, "re.escape"
|
||||||
|
@ -335,14 +335,14 @@ for t in tests:
|
||||||
# Try the match on a unicode string, and check that it
|
# Try the match on a unicode string, and check that it
|
||||||
# still succeeds.
|
# still succeeds.
|
||||||
result = obj.search(unicode(s, "latin-1"))
|
result = obj.search(unicode(s, "latin-1"))
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Fails on unicode match', t
|
print '=== Fails on unicode match', t
|
||||||
|
|
||||||
# Try the match on a unicode pattern, and check that it
|
# Try the match on a unicode pattern, and check that it
|
||||||
# still succeeds.
|
# still succeeds.
|
||||||
obj=re.compile(unicode(pattern, "latin-1"))
|
obj=re.compile(unicode(pattern, "latin-1"))
|
||||||
result = obj.search(s)
|
result = obj.search(s)
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Fails on unicode pattern match', t
|
print '=== Fails on unicode pattern match', t
|
||||||
|
|
||||||
# Try the match with the search area limited to the extent
|
# Try the match with the search area limited to the extent
|
||||||
|
@ -351,29 +351,29 @@ for t in tests:
|
||||||
# string), so we'll ignore patterns that feature it.
|
# string), so we'll ignore patterns that feature it.
|
||||||
|
|
||||||
if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \
|
if pattern[:2] != '\\B' and pattern[-2:] != '\\B' \
|
||||||
and result != None:
|
and result is not None:
|
||||||
obj = re.compile(pattern)
|
obj = re.compile(pattern)
|
||||||
result = obj.search(s, result.start(0), result.end(0) + 1)
|
result = obj.search(s, result.start(0), result.end(0) + 1)
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Failed on range-limited match', t
|
print '=== Failed on range-limited match', t
|
||||||
|
|
||||||
# Try the match with IGNORECASE enabled, and check that it
|
# Try the match with IGNORECASE enabled, and check that it
|
||||||
# still succeeds.
|
# still succeeds.
|
||||||
obj = re.compile(pattern, re.IGNORECASE)
|
obj = re.compile(pattern, re.IGNORECASE)
|
||||||
result = obj.search(s)
|
result = obj.search(s)
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Fails on case-insensitive match', t
|
print '=== Fails on case-insensitive match', t
|
||||||
|
|
||||||
# Try the match with LOCALE enabled, and check that it
|
# Try the match with LOCALE enabled, and check that it
|
||||||
# still succeeds.
|
# still succeeds.
|
||||||
obj = re.compile(pattern, re.LOCALE)
|
obj = re.compile(pattern, re.LOCALE)
|
||||||
result = obj.search(s)
|
result = obj.search(s)
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Fails on locale-sensitive match', t
|
print '=== Fails on locale-sensitive match', t
|
||||||
|
|
||||||
# Try the match with UNICODE locale enabled, and check
|
# Try the match with UNICODE locale enabled, and check
|
||||||
# that it still succeeds.
|
# that it still succeeds.
|
||||||
obj = re.compile(pattern, re.UNICODE)
|
obj = re.compile(pattern, re.UNICODE)
|
||||||
result = obj.search(s)
|
result = obj.search(s)
|
||||||
if result == None:
|
if result is None:
|
||||||
print '=== Fails on unicode-sensitive match', t
|
print '=== Fails on unicode-sensitive match', t
|
||||||
|
|
|
@ -13,12 +13,12 @@ print `b`
|
||||||
|
|
||||||
A1 = r.decrypt(a)
|
A1 = r.decrypt(a)
|
||||||
print A1
|
print A1
|
||||||
if A1 <> A:
|
if A1 != A:
|
||||||
print 'decrypt failed'
|
print 'decrypt failed'
|
||||||
|
|
||||||
B1 = r.decryptmore(b)
|
B1 = r.decryptmore(b)
|
||||||
print B1
|
print B1
|
||||||
if B1 <> B:
|
if B1 != B:
|
||||||
print 'decryptmore failed'
|
print 'decryptmore failed'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -395,8 +395,8 @@ def test_expat_locator_noinfo():
|
||||||
parser.feed("</doc>")
|
parser.feed("</doc>")
|
||||||
parser.close()
|
parser.close()
|
||||||
|
|
||||||
return parser.getSystemId() == None and \
|
return parser.getSystemId() is None and \
|
||||||
parser.getPublicId() == None and \
|
parser.getPublicId() is None and \
|
||||||
parser.getLineNumber() == 1
|
parser.getLineNumber() == 1
|
||||||
|
|
||||||
def test_expat_locator_withinfo():
|
def test_expat_locator_withinfo():
|
||||||
|
@ -407,7 +407,7 @@ def test_expat_locator_withinfo():
|
||||||
parser.parse(findfile("test.xml"))
|
parser.parse(findfile("test.xml"))
|
||||||
|
|
||||||
return parser.getSystemId() == findfile("test.xml") and \
|
return parser.getSystemId() == findfile("test.xml") and \
|
||||||
parser.getPublicId() == None
|
parser.getPublicId() is None
|
||||||
|
|
||||||
|
|
||||||
# ===========================================================================
|
# ===========================================================================
|
||||||
|
@ -484,7 +484,7 @@ def verify_empty_attrs(attrs):
|
||||||
len(attrs) == 0 and \
|
len(attrs) == 0 and \
|
||||||
not attrs.has_key("attr") and \
|
not attrs.has_key("attr") and \
|
||||||
attrs.keys() == [] and \
|
attrs.keys() == [] and \
|
||||||
attrs.get("attrs") == None and \
|
attrs.get("attrs") is None and \
|
||||||
attrs.get("attrs", 25) == 25 and \
|
attrs.get("attrs", 25) == 25 and \
|
||||||
attrs.items() == [] and \
|
attrs.items() == [] and \
|
||||||
attrs.values() == [] and \
|
attrs.values() == [] and \
|
||||||
|
@ -552,7 +552,7 @@ def verify_empty_nsattrs(attrs):
|
||||||
len(attrs) == 0 and \
|
len(attrs) == 0 and \
|
||||||
not attrs.has_key((ns_uri, "attr")) and \
|
not attrs.has_key((ns_uri, "attr")) and \
|
||||||
attrs.keys() == [] and \
|
attrs.keys() == [] and \
|
||||||
attrs.get((ns_uri, "attr")) == None and \
|
attrs.get((ns_uri, "attr")) is None and \
|
||||||
attrs.get((ns_uri, "attr"), 25) == 25 and \
|
attrs.get((ns_uri, "attr"), 25) == 25 and \
|
||||||
attrs.items() == [] and \
|
attrs.items() == [] and \
|
||||||
attrs.values() == [] and \
|
attrs.values() == [] and \
|
||||||
|
|
|
@ -137,7 +137,7 @@ try:
|
||||||
msg = 'socket test'
|
msg = 'socket test'
|
||||||
s.send(msg)
|
s.send(msg)
|
||||||
data = s.recv(1024)
|
data = s.recv(1024)
|
||||||
if msg <> data:
|
if msg != data:
|
||||||
print 'parent/client mismatch'
|
print 'parent/client mismatch'
|
||||||
s.close()
|
s.close()
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -47,12 +47,12 @@ if verbose:
|
||||||
print 'Running tests on character literals'
|
print 'Running tests on character literals'
|
||||||
|
|
||||||
for i in [0, 8, 16, 32, 64, 127, 128, 255]:
|
for i in [0, 8, 16, 32, 64, 127, 128, 255]:
|
||||||
test(r"""sre.match(r"\%03o" % i, chr(i)) != None""", 1)
|
test(r"""sre.match(r"\%03o" % i, chr(i)) is not None""", 1)
|
||||||
test(r"""sre.match(r"\%03o0" % i, chr(i)+"0") != None""", 1)
|
test(r"""sre.match(r"\%03o0" % i, chr(i)+"0") is not None""", 1)
|
||||||
test(r"""sre.match(r"\%03o8" % i, chr(i)+"8") != None""", 1)
|
test(r"""sre.match(r"\%03o8" % i, chr(i)+"8") is not None""", 1)
|
||||||
test(r"""sre.match(r"\x%02x" % i, chr(i)) != None""", 1)
|
test(r"""sre.match(r"\x%02x" % i, chr(i)) is not None""", 1)
|
||||||
test(r"""sre.match(r"\x%02x0" % i, chr(i)+"0") != None""", 1)
|
test(r"""sre.match(r"\x%02x0" % i, chr(i)+"0") is not None""", 1)
|
||||||
test(r"""sre.match(r"\x%02xz" % i, chr(i)+"z") != None""", 1)
|
test(r"""sre.match(r"\x%02xz" % i, chr(i)+"z") is not None""", 1)
|
||||||
test(r"""sre.match("\911", "")""", None, sre.error)
|
test(r"""sre.match("\911", "")""", None, sre.error)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -197,11 +197,11 @@ if verbose:
|
||||||
p = ""
|
p = ""
|
||||||
for i in range(0, 256):
|
for i in range(0, 256):
|
||||||
p = p + chr(i)
|
p = p + chr(i)
|
||||||
test(r"""sre.match(sre.escape(chr(i)), chr(i)) != None""", 1)
|
test(r"""sre.match(sre.escape(chr(i)), chr(i)) is not None""", 1)
|
||||||
test(r"""sre.match(sre.escape(chr(i)), chr(i)).span()""", (0,1))
|
test(r"""sre.match(sre.escape(chr(i)), chr(i)).span()""", (0,1))
|
||||||
|
|
||||||
pat = sre.compile(sre.escape(p))
|
pat = sre.compile(sre.escape(p))
|
||||||
test(r"""pat.match(p) != None""", 1)
|
test(r"""pat.match(p) is not None""", 1)
|
||||||
test(r"""pat.match(p).span()""", (0,256))
|
test(r"""pat.match(p).span()""", (0,256))
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
|
|
|
@ -15,14 +15,14 @@ def simple_err(func, *args):
|
||||||
simple_err(struct.calcsize, 'Q')
|
simple_err(struct.calcsize, 'Q')
|
||||||
|
|
||||||
sz = struct.calcsize('i')
|
sz = struct.calcsize('i')
|
||||||
if sz * 3 <> struct.calcsize('iii'):
|
if sz * 3 != struct.calcsize('iii'):
|
||||||
raise TestFailed, 'inconsistent sizes'
|
raise TestFailed, 'inconsistent sizes'
|
||||||
|
|
||||||
fmt = 'cbxxxxxxhhhhiillffd'
|
fmt = 'cbxxxxxxhhhhiillffd'
|
||||||
fmt3 = '3c3b18x12h6i6l6f3d'
|
fmt3 = '3c3b18x12h6i6l6f3d'
|
||||||
sz = struct.calcsize(fmt)
|
sz = struct.calcsize(fmt)
|
||||||
sz3 = struct.calcsize(fmt3)
|
sz3 = struct.calcsize(fmt3)
|
||||||
if sz * 3 <> sz3:
|
if sz * 3 != sz3:
|
||||||
raise TestFailed, 'inconsistent sizes (3*%s -> 3*%d = %d, %s -> %d)' % (
|
raise TestFailed, 'inconsistent sizes (3*%s -> 3*%d = %d, %s -> %d)' % (
|
||||||
`fmt`, sz, 3*sz, `fmt3`, sz3)
|
`fmt`, sz, 3*sz, `fmt3`, sz3)
|
||||||
|
|
||||||
|
@ -49,8 +49,8 @@ for prefix in ('', '@', '<', '>', '=', '!'):
|
||||||
print "trying:", format
|
print "trying:", format
|
||||||
s = struct.pack(format, c, b, h, i, l, f, d)
|
s = struct.pack(format, c, b, h, i, l, f, d)
|
||||||
cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s)
|
cp, bp, hp, ip, lp, fp, dp = struct.unpack(format, s)
|
||||||
if (cp <> c or bp <> b or hp <> h or ip <> i or lp <> l or
|
if (cp != c or bp != b or hp != h or ip != i or lp != l or
|
||||||
int(100 * fp) <> int(100 * f) or int(100 * dp) <> int(100 * d)):
|
int(100 * fp) != int(100 * f) or int(100 * dp) != int(100 * d)):
|
||||||
# ^^^ calculate only to two decimal places
|
# ^^^ calculate only to two decimal places
|
||||||
raise TestFailed, "unpack/pack not transitive (%s, %s)" % (
|
raise TestFailed, "unpack/pack not transitive (%s, %s)" % (
|
||||||
str(format), str((cp, bp, hp, ip, lp, fp, dp)))
|
str(format), str((cp, bp, hp, ip, lp, fp, dp)))
|
||||||
|
|
|
@ -52,7 +52,7 @@ def fcmp(x, y): # fuzzy comparison function
|
||||||
elif type(x) == type(y) and type(x) in (type(()), type([])):
|
elif type(x) == type(y) and type(x) in (type(()), type([])):
|
||||||
for i in range(min(len(x), len(y))):
|
for i in range(min(len(x), len(y))):
|
||||||
outcome = fcmp(x[i], y[i])
|
outcome = fcmp(x[i], y[i])
|
||||||
if outcome <> 0:
|
if outcome != 0:
|
||||||
return outcome
|
return outcome
|
||||||
return cmp(len(x), len(y))
|
return cmp(len(x), len(y))
|
||||||
return cmp(x, y)
|
return cmp(x, y)
|
||||||
|
|
|
@ -4,12 +4,12 @@ time.altzone
|
||||||
time.clock()
|
time.clock()
|
||||||
t = time.time()
|
t = time.time()
|
||||||
time.asctime(time.gmtime(t))
|
time.asctime(time.gmtime(t))
|
||||||
if time.ctime(t) <> time.asctime(time.localtime(t)):
|
if time.ctime(t) != time.asctime(time.localtime(t)):
|
||||||
print 'time.ctime(t) <> time.asctime(time.localtime(t))'
|
print 'time.ctime(t) != time.asctime(time.localtime(t))'
|
||||||
|
|
||||||
time.daylight
|
time.daylight
|
||||||
if long(time.mktime(time.localtime(t))) <> long(t):
|
if long(time.mktime(time.localtime(t))) != long(t):
|
||||||
print 'time.mktime(time.localtime(t)) <> t'
|
print 'time.mktime(time.localtime(t)) != t'
|
||||||
|
|
||||||
time.sleep(1.2)
|
time.sleep(1.2)
|
||||||
tt = time.gmtime(t)
|
tt = time.gmtime(t)
|
||||||
|
|
|
@ -36,11 +36,11 @@ else: raise TestFailed, '1 and 1 is false instead of false'
|
||||||
if not 1: raise TestFailed, 'not 1 is true instead of false'
|
if not 1: raise TestFailed, 'not 1 is true instead of false'
|
||||||
|
|
||||||
print '6.3 Comparisons'
|
print '6.3 Comparisons'
|
||||||
if 0 < 1 <= 1 == 1 >= 1 > 0 <> 1: pass
|
if 0 < 1 <= 1 == 1 >= 1 > 0 != 1: pass
|
||||||
else: raise TestFailed, 'int comparisons failed'
|
else: raise TestFailed, 'int comparisons failed'
|
||||||
if 0L < 1L <= 1L == 1L >= 1L > 0L <> 1L: pass
|
if 0L < 1L <= 1L == 1L >= 1L > 0L != 1L: pass
|
||||||
else: raise TestFailed, 'long int comparisons failed'
|
else: raise TestFailed, 'long int comparisons failed'
|
||||||
if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 <> 1.0: pass
|
if 0.0 < 1.0 <= 1.0 == 1.0 >= 1.0 > 0.0 != 1.0: pass
|
||||||
else: raise TestFailed, 'float comparisons failed'
|
else: raise TestFailed, 'float comparisons failed'
|
||||||
if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass
|
if '' < 'a' <= 'a' == 'a' < 'abc' < 'abd' < 'b': pass
|
||||||
else: raise TestFailed, 'string comparisons failed'
|
else: raise TestFailed, 'string comparisons failed'
|
||||||
|
@ -50,9 +50,9 @@ if None is None and [] is not []: pass
|
||||||
else: raise TestFailed, 'identity test failed'
|
else: raise TestFailed, 'identity test failed'
|
||||||
|
|
||||||
print '6.4 Numeric types (mostly conversions)'
|
print '6.4 Numeric types (mostly conversions)'
|
||||||
if 0 <> 0L or 0 <> 0.0 or 0L <> 0.0: raise TestFailed, 'mixed comparisons'
|
if 0 != 0L or 0 != 0.0 or 0L != 0.0: raise TestFailed, 'mixed comparisons'
|
||||||
if 1 <> 1L or 1 <> 1.0 or 1L <> 1.0: raise TestFailed, 'mixed comparisons'
|
if 1 != 1L or 1 != 1.0 or 1L != 1.0: raise TestFailed, 'mixed comparisons'
|
||||||
if -1 <> -1L or -1 <> -1.0 or -1L <> -1.0:
|
if -1 != -1L or -1 != -1.0 or -1L != -1.0:
|
||||||
raise TestFailed, 'int/long/float value not equal'
|
raise TestFailed, 'int/long/float value not equal'
|
||||||
if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
|
if int(1.9) == 1 == int(1.1) and int(-1.1) == -1 == int(-1.9): pass
|
||||||
else: raise TestFailed, 'int() does not round properly'
|
else: raise TestFailed, 'int() does not round properly'
|
||||||
|
@ -61,10 +61,10 @@ else: raise TestFailed, 'long() does not round properly'
|
||||||
if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
|
if float(1) == 1.0 and float(-1) == -1.0 and float(0) == 0.0: pass
|
||||||
else: raise TestFailed, 'float() does not work properly'
|
else: raise TestFailed, 'float() does not work properly'
|
||||||
print '6.4.1 32-bit integers'
|
print '6.4.1 32-bit integers'
|
||||||
if 12 + 24 <> 36: raise TestFailed, 'int op'
|
if 12 + 24 != 36: raise TestFailed, 'int op'
|
||||||
if 12 + (-24) <> -12: raise TestFailed, 'int op'
|
if 12 + (-24) != -12: raise TestFailed, 'int op'
|
||||||
if (-12) + 24 <> 12: raise TestFailed, 'int op'
|
if (-12) + 24 != 12: raise TestFailed, 'int op'
|
||||||
if (-12) + (-24) <> -36: raise TestFailed, 'int op'
|
if (-12) + (-24) != -36: raise TestFailed, 'int op'
|
||||||
if not 12 < 24: raise TestFailed, 'int op'
|
if not 12 < 24: raise TestFailed, 'int op'
|
||||||
if not -24 < -12: raise TestFailed, 'int op'
|
if not -24 < -12: raise TestFailed, 'int op'
|
||||||
# Test for a particular bug in integer multiply
|
# Test for a particular bug in integer multiply
|
||||||
|
@ -72,10 +72,10 @@ xsize, ysize, zsize = 238, 356, 4
|
||||||
if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
|
if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
|
||||||
raise TestFailed, 'int mul commutativity'
|
raise TestFailed, 'int mul commutativity'
|
||||||
print '6.4.2 Long integers'
|
print '6.4.2 Long integers'
|
||||||
if 12L + 24L <> 36L: raise TestFailed, 'long op'
|
if 12L + 24L != 36L: raise TestFailed, 'long op'
|
||||||
if 12L + (-24L) <> -12L: raise TestFailed, 'long op'
|
if 12L + (-24L) != -12L: raise TestFailed, 'long op'
|
||||||
if (-12L) + 24L <> 12L: raise TestFailed, 'long op'
|
if (-12L) + 24L != 12L: raise TestFailed, 'long op'
|
||||||
if (-12L) + (-24L) <> -36L: raise TestFailed, 'long op'
|
if (-12L) + (-24L) != -36L: raise TestFailed, 'long op'
|
||||||
if not 12L < 24L: raise TestFailed, 'long op'
|
if not 12L < 24L: raise TestFailed, 'long op'
|
||||||
if not -24L < -12L: raise TestFailed, 'long op'
|
if not -24L < -12L: raise TestFailed, 'long op'
|
||||||
x = sys.maxint
|
x = sys.maxint
|
||||||
|
@ -91,49 +91,49 @@ try: int(long(x)-1L)
|
||||||
except OverflowError: pass
|
except OverflowError: pass
|
||||||
else:raise TestFailed, 'long op'
|
else:raise TestFailed, 'long op'
|
||||||
print '6.4.3 Floating point numbers'
|
print '6.4.3 Floating point numbers'
|
||||||
if 12.0 + 24.0 <> 36.0: raise TestFailed, 'float op'
|
if 12.0 + 24.0 != 36.0: raise TestFailed, 'float op'
|
||||||
if 12.0 + (-24.0) <> -12.0: raise TestFailed, 'float op'
|
if 12.0 + (-24.0) != -12.0: raise TestFailed, 'float op'
|
||||||
if (-12.0) + 24.0 <> 12.0: raise TestFailed, 'float op'
|
if (-12.0) + 24.0 != 12.0: raise TestFailed, 'float op'
|
||||||
if (-12.0) + (-24.0) <> -36.0: raise TestFailed, 'float op'
|
if (-12.0) + (-24.0) != -36.0: raise TestFailed, 'float op'
|
||||||
if not 12.0 < 24.0: raise TestFailed, 'float op'
|
if not 12.0 < 24.0: raise TestFailed, 'float op'
|
||||||
if not -24.0 < -12.0: raise TestFailed, 'float op'
|
if not -24.0 < -12.0: raise TestFailed, 'float op'
|
||||||
|
|
||||||
print '6.5 Sequence types'
|
print '6.5 Sequence types'
|
||||||
|
|
||||||
print '6.5.1 Strings'
|
print '6.5.1 Strings'
|
||||||
if len('') <> 0: raise TestFailed, 'len(\'\')'
|
if len('') != 0: raise TestFailed, 'len(\'\')'
|
||||||
if len('a') <> 1: raise TestFailed, 'len(\'a\')'
|
if len('a') != 1: raise TestFailed, 'len(\'a\')'
|
||||||
if len('abcdef') <> 6: raise TestFailed, 'len(\'abcdef\')'
|
if len('abcdef') != 6: raise TestFailed, 'len(\'abcdef\')'
|
||||||
if 'xyz' + 'abcde' <> 'xyzabcde': raise TestFailed, 'string concatenation'
|
if 'xyz' + 'abcde' != 'xyzabcde': raise TestFailed, 'string concatenation'
|
||||||
if 'xyz'*3 <> 'xyzxyzxyz': raise TestFailed, 'string repetition *3'
|
if 'xyz'*3 != 'xyzxyzxyz': raise TestFailed, 'string repetition *3'
|
||||||
if 0*'abcde' <> '': raise TestFailed, 'string repetition 0*'
|
if 0*'abcde' != '': raise TestFailed, 'string repetition 0*'
|
||||||
if min('abc') <> 'a' or max('abc') <> 'c': raise TestFailed, 'min/max string'
|
if min('abc') != 'a' or max('abc') != 'c': raise TestFailed, 'min/max string'
|
||||||
if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass
|
if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass
|
||||||
else: raise TestFailed, 'in/not in string'
|
else: raise TestFailed, 'in/not in string'
|
||||||
x = 'x'*103
|
x = 'x'*103
|
||||||
if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug'
|
if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug'
|
||||||
|
|
||||||
print '6.5.2 Tuples'
|
print '6.5.2 Tuples'
|
||||||
if len(()) <> 0: raise TestFailed, 'len(())'
|
if len(()) != 0: raise TestFailed, 'len(())'
|
||||||
if len((1,)) <> 1: raise TestFailed, 'len((1,))'
|
if len((1,)) != 1: raise TestFailed, 'len((1,))'
|
||||||
if len((1,2,3,4,5,6)) <> 6: raise TestFailed, 'len((1,2,3,4,5,6))'
|
if len((1,2,3,4,5,6)) != 6: raise TestFailed, 'len((1,2,3,4,5,6))'
|
||||||
if (1,2)+(3,4) <> (1,2,3,4): raise TestFailed, 'tuple concatenation'
|
if (1,2)+(3,4) != (1,2,3,4): raise TestFailed, 'tuple concatenation'
|
||||||
if (1,2)*3 <> (1,2,1,2,1,2): raise TestFailed, 'tuple repetition *3'
|
if (1,2)*3 != (1,2,1,2,1,2): raise TestFailed, 'tuple repetition *3'
|
||||||
if 0*(1,2,3) <> (): raise TestFailed, 'tuple repetition 0*'
|
if 0*(1,2,3) != (): raise TestFailed, 'tuple repetition 0*'
|
||||||
if min((1,2)) <> 1 or max((1,2)) <> 2: raise TestFailed, 'min/max tuple'
|
if min((1,2)) != 1 or max((1,2)) != 2: raise TestFailed, 'min/max tuple'
|
||||||
if 0 in (0,1,2) and 1 in (0,1,2) and 2 in (0,1,2) and 3 not in (0,1,2): pass
|
if 0 in (0,1,2) and 1 in (0,1,2) and 2 in (0,1,2) and 3 not in (0,1,2): pass
|
||||||
else: raise TestFailed, 'in/not in tuple'
|
else: raise TestFailed, 'in/not in tuple'
|
||||||
|
|
||||||
print '6.5.3 Lists'
|
print '6.5.3 Lists'
|
||||||
if len([]) <> 0: raise TestFailed, 'len([])'
|
if len([]) != 0: raise TestFailed, 'len([])'
|
||||||
if len([1,]) <> 1: raise TestFailed, 'len([1,])'
|
if len([1,]) != 1: raise TestFailed, 'len([1,])'
|
||||||
if len([1,2,3,4,5,6]) <> 6: raise TestFailed, 'len([1,2,3,4,5,6])'
|
if len([1,2,3,4,5,6]) != 6: raise TestFailed, 'len([1,2,3,4,5,6])'
|
||||||
if [1,2]+[3,4] <> [1,2,3,4]: raise TestFailed, 'list concatenation'
|
if [1,2]+[3,4] != [1,2,3,4]: raise TestFailed, 'list concatenation'
|
||||||
if [1,2]*3 <> [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3'
|
if [1,2]*3 != [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3'
|
||||||
if [1,2]*3L <> [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3L'
|
if [1,2]*3L != [1,2,1,2,1,2]: raise TestFailed, 'list repetition *3L'
|
||||||
if 0*[1,2,3] <> []: raise TestFailed, 'list repetition 0*'
|
if 0*[1,2,3] != []: raise TestFailed, 'list repetition 0*'
|
||||||
if 0L*[1,2,3] <> []: raise TestFailed, 'list repetition 0L*'
|
if 0L*[1,2,3] != []: raise TestFailed, 'list repetition 0L*'
|
||||||
if min([1,2]) <> 1 or max([1,2]) <> 2: raise TestFailed, 'min/max list'
|
if min([1,2]) != 1 or max([1,2]) != 2: raise TestFailed, 'min/max list'
|
||||||
if 0 in [0,1,2] and 1 in [0,1,2] and 2 in [0,1,2] and 3 not in [0,1,2]: pass
|
if 0 in [0,1,2] and 1 in [0,1,2] and 2 in [0,1,2] and 3 not in [0,1,2]: pass
|
||||||
else: raise TestFailed, 'in/not in list'
|
else: raise TestFailed, 'in/not in list'
|
||||||
a = [1, 2, 3, 4, 5]
|
a = [1, 2, 3, 4, 5]
|
||||||
|
@ -155,55 +155,55 @@ a = [0,1,2,3,4]
|
||||||
a[0L] = 1
|
a[0L] = 1
|
||||||
a[1L] = 2
|
a[1L] = 2
|
||||||
a[2L] = 3
|
a[2L] = 3
|
||||||
if a <> [1,2,3,3,4]: raise TestFailed, 'list item assignment [0L], [1L], [2L]'
|
if a != [1,2,3,3,4]: raise TestFailed, 'list item assignment [0L], [1L], [2L]'
|
||||||
a[0] = 5
|
a[0] = 5
|
||||||
a[1] = 6
|
a[1] = 6
|
||||||
a[2] = 7
|
a[2] = 7
|
||||||
if a <> [5,6,7,3,4]: raise TestFailed, 'list item assignment [0], [1], [2]'
|
if a != [5,6,7,3,4]: raise TestFailed, 'list item assignment [0], [1], [2]'
|
||||||
a[-2L] = 88
|
a[-2L] = 88
|
||||||
a[-1L] = 99
|
a[-1L] = 99
|
||||||
if a <> [5,6,7,88,99]: raise TestFailed, 'list item assignment [-2L], [-1L]'
|
if a != [5,6,7,88,99]: raise TestFailed, 'list item assignment [-2L], [-1L]'
|
||||||
a[-2] = 8
|
a[-2] = 8
|
||||||
a[-1] = 9
|
a[-1] = 9
|
||||||
if a <> [5,6,7,8,9]: raise TestFailed, 'list item assignment [-2], [-1]'
|
if a != [5,6,7,8,9]: raise TestFailed, 'list item assignment [-2], [-1]'
|
||||||
a[:2] = [0,4]
|
a[:2] = [0,4]
|
||||||
a[-3:] = []
|
a[-3:] = []
|
||||||
a[1:1] = [1,2,3]
|
a[1:1] = [1,2,3]
|
||||||
if a <> [0,1,2,3,4]: raise TestFailed, 'list slice assignment'
|
if a != [0,1,2,3,4]: raise TestFailed, 'list slice assignment'
|
||||||
a[ 1L : 4L] = [7,8,9]
|
a[ 1L : 4L] = [7,8,9]
|
||||||
if a <> [0,7,8,9,4]: raise TestFailed, 'list slice assignment using long ints'
|
if a != [0,7,8,9,4]: raise TestFailed, 'list slice assignment using long ints'
|
||||||
del a[1:4]
|
del a[1:4]
|
||||||
if a <> [0,4]: raise TestFailed, 'list slice deletion'
|
if a != [0,4]: raise TestFailed, 'list slice deletion'
|
||||||
del a[0]
|
del a[0]
|
||||||
if a <> [4]: raise TestFailed, 'list item deletion [0]'
|
if a != [4]: raise TestFailed, 'list item deletion [0]'
|
||||||
del a[-1]
|
del a[-1]
|
||||||
if a <> []: raise TestFailed, 'list item deletion [-1]'
|
if a != []: raise TestFailed, 'list item deletion [-1]'
|
||||||
a=range(0,5)
|
a=range(0,5)
|
||||||
del a[1L:4L]
|
del a[1L:4L]
|
||||||
if a <> [0,4]: raise TestFailed, 'list slice deletion'
|
if a != [0,4]: raise TestFailed, 'list slice deletion'
|
||||||
del a[0L]
|
del a[0L]
|
||||||
if a <> [4]: raise TestFailed, 'list item deletion [0]'
|
if a != [4]: raise TestFailed, 'list item deletion [0]'
|
||||||
del a[-1L]
|
del a[-1L]
|
||||||
if a <> []: raise TestFailed, 'list item deletion [-1]'
|
if a != []: raise TestFailed, 'list item deletion [-1]'
|
||||||
a.append(0)
|
a.append(0)
|
||||||
a.append(1)
|
a.append(1)
|
||||||
a.append(2)
|
a.append(2)
|
||||||
if a <> [0,1,2]: raise TestFailed, 'list append'
|
if a != [0,1,2]: raise TestFailed, 'list append'
|
||||||
a.insert(0, -2)
|
a.insert(0, -2)
|
||||||
a.insert(1, -1)
|
a.insert(1, -1)
|
||||||
a.insert(2,0)
|
a.insert(2,0)
|
||||||
if a <> [-2,-1,0,0,1,2]: raise TestFailed, 'list insert'
|
if a != [-2,-1,0,0,1,2]: raise TestFailed, 'list insert'
|
||||||
if a.count(0) <> 2: raise TestFailed, ' list count'
|
if a.count(0) != 2: raise TestFailed, ' list count'
|
||||||
if a.index(0) <> 2: raise TestFailed, 'list index'
|
if a.index(0) != 2: raise TestFailed, 'list index'
|
||||||
a.remove(0)
|
a.remove(0)
|
||||||
if a <> [-2,-1,0,1,2]: raise TestFailed, 'list remove'
|
if a != [-2,-1,0,1,2]: raise TestFailed, 'list remove'
|
||||||
a.reverse()
|
a.reverse()
|
||||||
if a <> [2,1,0,-1,-2]: raise TestFailed, 'list reverse'
|
if a != [2,1,0,-1,-2]: raise TestFailed, 'list reverse'
|
||||||
a.sort()
|
a.sort()
|
||||||
if a <> [-2,-1,0,1,2]: raise TestFailed, 'list sort'
|
if a != [-2,-1,0,1,2]: raise TestFailed, 'list sort'
|
||||||
def revcmp(a, b): return cmp(b, a)
|
def revcmp(a, b): return cmp(b, a)
|
||||||
a.sort(revcmp)
|
a.sort(revcmp)
|
||||||
if a <> [2,1,0,-1,-2]: raise TestFailed, 'list sort with cmp func'
|
if a != [2,1,0,-1,-2]: raise TestFailed, 'list sort with cmp func'
|
||||||
# The following dumps core in unpatched Python 1.5:
|
# The following dumps core in unpatched Python 1.5:
|
||||||
def myComparison(x,y):
|
def myComparison(x,y):
|
||||||
return cmp(x%3, y%7)
|
return cmp(x%3, y%7)
|
||||||
|
@ -219,22 +219,22 @@ if a[ 3: pow(2,145L) ] != [3,4]:
|
||||||
|
|
||||||
print '6.6 Mappings == Dictionaries'
|
print '6.6 Mappings == Dictionaries'
|
||||||
d = {}
|
d = {}
|
||||||
if d.keys() <> []: raise TestFailed, '{}.keys()'
|
if d.keys() != []: raise TestFailed, '{}.keys()'
|
||||||
if d.has_key('a') <> 0: raise TestFailed, '{}.has_key(\'a\')'
|
if d.has_key('a') != 0: raise TestFailed, '{}.has_key(\'a\')'
|
||||||
if len(d) <> 0: raise TestFailed, 'len({})'
|
if len(d) != 0: raise TestFailed, 'len({})'
|
||||||
d = {'a': 1, 'b': 2}
|
d = {'a': 1, 'b': 2}
|
||||||
if len(d) <> 2: raise TestFailed, 'len(dict)'
|
if len(d) != 2: raise TestFailed, 'len(dict)'
|
||||||
k = d.keys()
|
k = d.keys()
|
||||||
k.sort()
|
k.sort()
|
||||||
if k <> ['a', 'b']: raise TestFailed, 'dict keys()'
|
if k != ['a', 'b']: raise TestFailed, 'dict keys()'
|
||||||
if d.has_key('a') and d.has_key('b') and not d.has_key('c'): pass
|
if d.has_key('a') and d.has_key('b') and not d.has_key('c'): pass
|
||||||
else: raise TestFailed, 'dict keys()'
|
else: raise TestFailed, 'dict keys()'
|
||||||
if d['a'] <> 1 or d['b'] <> 2: raise TestFailed, 'dict item'
|
if d['a'] != 1 or d['b'] != 2: raise TestFailed, 'dict item'
|
||||||
d['c'] = 3
|
d['c'] = 3
|
||||||
d['a'] = 4
|
d['a'] = 4
|
||||||
if d['c'] <> 3 or d['a'] <> 4: raise TestFailed, 'dict item assignment'
|
if d['c'] != 3 or d['a'] != 4: raise TestFailed, 'dict item assignment'
|
||||||
del d['b']
|
del d['b']
|
||||||
if d <> {'a': 4, 'c': 3}: raise TestFailed, 'dict item deletion'
|
if d != {'a': 4, 'c': 3}: raise TestFailed, 'dict item deletion'
|
||||||
d = {1:1, 2:2, 3:3}
|
d = {1:1, 2:2, 3:3}
|
||||||
d.clear()
|
d.clear()
|
||||||
if d != {}: raise TestFailed, 'dict clear'
|
if d != {}: raise TestFailed, 'dict clear'
|
||||||
|
@ -246,24 +246,24 @@ if d.copy() != {1:1, 2:2, 3:3}: raise TestFailed, 'dict copy'
|
||||||
if {}.copy() != {}: raise TestFailed, 'empty dict copy'
|
if {}.copy() != {}: raise TestFailed, 'empty dict copy'
|
||||||
# dict.get()
|
# dict.get()
|
||||||
d = {}
|
d = {}
|
||||||
if d.get('c') != None: raise TestFailed, 'missing {} get, no 2nd arg'
|
if d.get('c') is not None: raise TestFailed, 'missing {} get, no 2nd arg'
|
||||||
if d.get('c', 3) != 3: raise TestFailed, 'missing {} get, w/ 2nd arg'
|
if d.get('c', 3) != 3: raise TestFailed, 'missing {} get, w/ 2nd arg'
|
||||||
d = {'a' : 1, 'b' : 2}
|
d = {'a' : 1, 'b' : 2}
|
||||||
if d.get('c') != None: raise TestFailed, 'missing dict get, no 2nd arg'
|
if d.get('c') is not None: raise TestFailed, 'missing dict get, no 2nd arg'
|
||||||
if d.get('c', 3) != 3: raise TestFailed, 'missing dict get, w/ 2nd arg'
|
if d.get('c', 3) != 3: raise TestFailed, 'missing dict get, w/ 2nd arg'
|
||||||
if d.get('a') != 1: raise TestFailed, 'present dict get, no 2nd arg'
|
if d.get('a') != 1: raise TestFailed, 'present dict get, no 2nd arg'
|
||||||
if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg'
|
if d.get('a', 3) != 1: raise TestFailed, 'present dict get, w/ 2nd arg'
|
||||||
# dict.setdefault()
|
# dict.setdefault()
|
||||||
d = {}
|
d = {}
|
||||||
if d.setdefault('key0') <> None:
|
if d.setdefault('key0') is not None:
|
||||||
raise TestFailed, 'missing {} setdefault, no 2nd arg'
|
raise TestFailed, 'missing {} setdefault, no 2nd arg'
|
||||||
if d.setdefault('key0') <> None:
|
if d.setdefault('key0') is not None:
|
||||||
raise TestFailed, 'present {} setdefault, no 2nd arg'
|
raise TestFailed, 'present {} setdefault, no 2nd arg'
|
||||||
d.setdefault('key', []).append(3)
|
d.setdefault('key', []).append(3)
|
||||||
if d['key'][0] <> 3:
|
if d['key'][0] != 3:
|
||||||
raise TestFailed, 'missing {} setdefault, w/ 2nd arg'
|
raise TestFailed, 'missing {} setdefault, w/ 2nd arg'
|
||||||
d.setdefault('key', []).append(4)
|
d.setdefault('key', []).append(4)
|
||||||
if len(d['key']) <> 2:
|
if len(d['key']) != 2:
|
||||||
raise TestFailed, 'present {} setdefault, w/ 2nd arg'
|
raise TestFailed, 'present {} setdefault, w/ 2nd arg'
|
||||||
# dict.popitem()
|
# dict.popitem()
|
||||||
for copymode in -1, +1:
|
for copymode in -1, +1:
|
||||||
|
|
|
@ -16,35 +16,35 @@ c = -1
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'unpack tuple'
|
print 'unpack tuple'
|
||||||
a, b, c = t
|
a, b, c = t
|
||||||
if a <> 1 or b <> 2 or c <> 3:
|
if a != 1 or b != 2 or c != 3:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# unpack list
|
# unpack list
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'unpack list'
|
print 'unpack list'
|
||||||
a, b, c = l
|
a, b, c = l
|
||||||
if a <> 4 or b <> 5 or c <> 6:
|
if a != 4 or b != 5 or c != 6:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# unpack implied tuple
|
# unpack implied tuple
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'unpack implied tuple'
|
print 'unpack implied tuple'
|
||||||
a, b, c = 7, 8, 9
|
a, b, c = 7, 8, 9
|
||||||
if a <> 7 or b <> 8 or c <> 9:
|
if a != 7 or b != 8 or c != 9:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# unpack string... fun!
|
# unpack string... fun!
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'unpack string'
|
print 'unpack string'
|
||||||
a, b, c = 'one'
|
a, b, c = 'one'
|
||||||
if a <> 'o' or b <> 'n' or c <> 'e':
|
if a != 'o' or b != 'n' or c != 'e':
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# unpack generic sequence
|
# unpack generic sequence
|
||||||
if verbose:
|
if verbose:
|
||||||
print 'unpack sequence'
|
print 'unpack sequence'
|
||||||
a, b, c = Seq()
|
a, b, c = Seq()
|
||||||
if a <> 0 or b <> 1 or c <> 2:
|
if a != 0 or b != 1 or c != 2:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# single element unpacking, with extra syntax
|
# single element unpacking, with extra syntax
|
||||||
|
@ -53,10 +53,10 @@ if verbose:
|
||||||
st = (99,)
|
st = (99,)
|
||||||
sl = [100]
|
sl = [100]
|
||||||
a, = st
|
a, = st
|
||||||
if a <> 99:
|
if a != 99:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
b, = sl
|
b, = sl
|
||||||
if b <> 100:
|
if b != 100:
|
||||||
raise TestFailed
|
raise TestFailed
|
||||||
|
|
||||||
# now for some failures
|
# now for some failures
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue