autopep8 cleanup of Examples/test-suite/python

automated cleanup of python pep8 whitespace compliance
This commit is contained in:
Jon Schlueter 2015-05-06 08:27:35 -04:00 committed by Jon Schlueter
commit b77f3afafb
202 changed files with 3477 additions and 3382 deletions

View file

@ -1,158 +1,170 @@
# Check std::vector and std::list behaves the same as Python iterable types (list)
# Check std::vector and std::list behaves the same as Python iterable
# types (list)
from li_std_containers_int import *
import sys
def failed(a, b, msg):
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
raise RuntimeError, msg + " " + str(list(a)) + " " + str(list(b))
def compare_sequences(a, b):
if len(a) != len(b):
failed(a, b, "different sizes")
for i in range(len(a)):
if a[i] != b[i]:
failed(a, b, "elements are different")
if len(a) != len(b):
failed(a, b, "different sizes")
for i in range(len(a)):
if a[i] != b[i]:
failed(a, b, "elements are different")
def compare_containers(pythonlist, swigvector, swiglist):
compare_sequences(pythonlist, swigvector)
compare_sequences(pythonlist, swiglist)
compare_sequences(pythonlist, swigvector)
compare_sequences(pythonlist, swiglist)
# Check std::vector and std::list assignment behaves same as Python list
# assignment including exceptions
# Check std::vector and std::list assignment behaves same as Python list assignment including exceptions
def container_insert_step(i, j, step, newval):
ps = range(6)
iv = vector_int(ps)
il = list_int(ps)
ps = range(6)
iv = vector_int(ps)
il = list_int(ps)
# Python slice
try:
if step == None:
if j == None:
ps[i] = newval
else:
ps[i:j] = newval
else:
if j == None:
ps[i::step] = newval
else:
ps[i:j:step] = newval
ps_error = None
except ValueError, e:
ps_error = e
except IndexError, e:
ps_error = e
# Python slice
try:
if step == None:
if j == None:
ps[i] = newval
else:
ps[i:j] = newval
else:
if j == None:
ps[i::step] = newval
else:
ps[i:j:step] = newval
ps_error = None
except ValueError, e:
ps_error = e
except IndexError, e:
ps_error = e
# std::vector<int>
try:
if step == None:
if j == None:
iv[i] = newval
else:
iv[i:j] = newval
else:
if j == None:
iv[i::step] = newval
else:
iv[i:j:step] = newval
iv_error = None
except ValueError, e:
iv_error = e
except IndexError, e:
iv_error = e
# std::vector<int>
try:
if step == None:
if j == None:
iv[i] = newval
else:
iv[i:j] = newval
else:
if j == None:
iv[i::step] = newval
else:
iv[i:j:step] = newval
iv_error = None
except ValueError, e:
iv_error = e
except IndexError, e:
iv_error = e
# std::list<int>
try:
if step == None:
if j == None:
il[i] = newval
else:
il[i:j] = newval
else:
if j == None:
il[i::step] = newval
else:
il[i:j:step] = newval
il_error = None
except ValueError, e:
il_error = e
except IndexError, e:
il_error = e
# std::list<int>
try:
if step == None:
if j == None:
il[i] = newval
else:
il[i:j] = newval
else:
if j == None:
il[i::step] = newval
else:
il[i:j:step] = newval
il_error = None
except ValueError, e:
il_error = e
except IndexError, e:
il_error = e
# Python 2.6 contains bug fixes in extended slicing syntax:
# http://docs.python.org/2/whatsnew/2.6.html
skip_check = ps_error != None and(
iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6))
if not(skip_check):
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error)
compare_containers(ps, iv, il)
# Check std::vector and std::list delete behaves same as Python list
# delete including exceptions
def container_delete_step(i, j, step):
ps = range(6)
iv = vector_int(ps)
il = list_int(ps)
# Python slice
try:
if step == None:
if j == None:
del ps[i]
else:
del ps[i:j]
else:
if j == None:
del ps[i::step]
else:
del ps[i:j:step]
ps_error = None
except ValueError, e:
ps_error = e
except IndexError, e:
ps_error = e
# std::vector<int>
try:
if step == None:
if j == None:
del iv[i]
else:
del iv[i:j]
else:
if j == None:
del iv[i::step]
else:
del iv[i:j:step]
iv_error = None
except ValueError, e:
iv_error = e
except IndexError, e:
iv_error = e
# std::list<int>
try:
if step == None:
if j == None:
del il[i]
else:
del il[i:j]
else:
if j == None:
del il[i::step]
else:
del il[i:j:step]
il_error = None
except ValueError, e:
il_error = e
except IndexError, e:
il_error = e
# Python 2.6 contains bug fixes in extended slicing syntax: http://docs.python.org/2/whatsnew/2.6.html
skip_check = ps_error != None and(iv_error == il_error == None) and step > 0 and (sys.version_info[0:2] < (2, 6))
if not(skip_check):
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error)
raise RuntimeError, "ValueError exception not consistently thrown: " + \
str(ps_error) + " " + str(iv_error) + " " + str(il_error)
compare_containers(ps, iv, il)
# Check std::vector and std::list delete behaves same as Python list delete including exceptions
def container_delete_step(i, j, step):
ps = range(6)
iv = vector_int(ps)
il = list_int(ps)
# Python slice
try:
if step == None:
if j == None:
del ps[i]
else:
del ps[i:j]
else:
if j == None:
del ps[i::step]
else:
del ps[i:j:step]
ps_error = None
except ValueError, e:
ps_error = e
except IndexError, e:
ps_error = e
# std::vector<int>
try:
if step == None:
if j == None:
del iv[i]
else:
del iv[i:j]
else:
if j == None:
del iv[i::step]
else:
del iv[i:j:step]
iv_error = None
except ValueError, e:
iv_error = e
except IndexError, e:
iv_error = e
# std::list<int>
try:
if step == None:
if j == None:
del il[i]
else:
del il[i:j]
else:
if j == None:
del il[i::step]
else:
del il[i:j:step]
il_error = None
except ValueError, e:
il_error = e
except IndexError, e:
il_error = e
if not((type(ps_error) == type(iv_error)) and (type(ps_error) == type(il_error))):
raise RuntimeError, "ValueError exception not consistently thrown: " + str(ps_error) + " " + str(iv_error) + " " + str(il_error)
compare_containers(ps, iv, il)
ps = [0,1,2,3,4,5]
ps = [0, 1, 2, 3, 4, 5]
iv = vector_int(ps)
il = list_int(ps)
@ -164,7 +176,7 @@ compare_containers(ps[1:3], iv[1:3], il[1:3])
compare_containers(ps[2:4], iv[2:4], il[2:4])
compare_containers(ps[0:3], iv[0:3], il[0:3])
compare_containers(ps[3:6], iv[3:6], il[3:6])
compare_containers(ps[3:10], iv[3:10], il[3:10]) # beyond end of range
compare_containers(ps[3:10], iv[3:10], il[3:10]) # beyond end of range
# before beginning of range (negative indexing)
compare_containers(ps[-1:7], iv[-1:7], il[-1:7])
@ -172,7 +184,8 @@ compare_containers(ps[-2:7], iv[-2:7], il[-2:7])
compare_containers(ps[-5:7], iv[-5:7], il[-5:7])
compare_containers(ps[-6:7], iv[-6:7], il[-6:7])
# before beginning of range (negative indexing, negative index is > container size)
# before beginning of range (negative indexing, negative index is >
# container size)
compare_containers(ps[-7:7], iv[-7:7], il[-7:7])
compare_containers(ps[-100:7], iv[-100:7], il[-100:7])
@ -222,48 +235,52 @@ compare_containers(ps[::-5], iv[::-5], il[::-5])
# insert sequences (growing, shrinking and staying same size)
for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
# single element set/replace
container_insert_step(start, None, None, 111)
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666, 777])
container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666])
container_insert_step(start, end, None, [111, 222, 333, 444, 555])
container_insert_step(start, end, None, [111, 222, 333, 444])
container_insert_step(start, end, None, [111, 222, 333])
container_insert_step(start, end, None, [111, 222])
container_insert_step(start, end, None, [111])
container_insert_step(start, end, None, [])
# single element set/replace
container_insert_step(start, None, None, 111)
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
container_insert_step(
start, end, None, [111, 222, 333, 444, 555, 666, 777])
container_insert_step(start, end, None, [111, 222, 333, 444, 555, 666])
container_insert_step(start, end, None, [111, 222, 333, 444, 555])
container_insert_step(start, end, None, [111, 222, 333, 444])
container_insert_step(start, end, None, [111, 222, 333])
container_insert_step(start, end, None, [111, 222])
container_insert_step(start, end, None, [111])
container_insert_step(start, end, None, [])
# delete sequences (growing, shrinking and staying same size)
for start in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
# single element delete
container_delete_step(start, None, None)
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
container_delete_step(start, end, None)
for step in range(-7,7):
container_delete_step(start, end, step)
# single element delete
container_delete_step(start, None, None)
for end in [-102, -100, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 100, 102]:
container_delete_step(start, end, None)
for step in range(-7, 7):
container_delete_step(start, end, step)
ps = range(6)
iv = vector_int(ps)
il = list_int(ps)
del ps[:]; del iv[:]; del il[:]
del ps[:]
del iv[:]
del il[:]
compare_containers(ps, iv, il)
for end in range(7):
for step in range(-7,7):
for start in range(7):
container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666, 777])
container_insert_step(start, end, step, [111, 222, 333, 444, 555, 666])
container_insert_step(start, end, step, [111, 222, 333, 444, 555])
container_insert_step(start, end, step, [111, 222, 333, 444])
container_insert_step(start, end, step, [111, 222, 333])
container_insert_step(start, end, step, [111, 222])
container_insert_step(start, end, step, [111])
container_insert_step(start, end, step, [])
for step in range(-7, 7):
for start in range(7):
container_insert_step(
start, end, step, [111, 222, 333, 444, 555, 666, 777])
container_insert_step(
start, end, step, [111, 222, 333, 444, 555, 666])
container_insert_step(start, end, step, [111, 222, 333, 444, 555])
container_insert_step(start, end, step, [111, 222, 333, 444])
container_insert_step(start, end, step, [111, 222, 333])
container_insert_step(start, end, step, [111, 222])
container_insert_step(start, end, step, [111])
container_insert_step(start, end, step, [])
try:
x = iv[::0]
raise RuntimeError("Zero step not caught")
x = iv[::0]
raise RuntimeError("Zero step not caught")
except ValueError:
pass
pass