add pep8 headers so these scripts spit out errors when running pep8.
made some changes but mostly these scripts will give pep8 warnings.
This commit is contained in:
parent
1add5b58e8
commit
7fc4ab2aab
|
@ -24,7 +24,10 @@
|
|||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
import sys, os
|
||||
# <pep8 compliant>
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.stdout.write("Usage: datatoc <data_file>\n")
|
||||
|
@ -33,7 +36,7 @@ if len(sys.argv) < 2:
|
|||
filename = sys.argv[1]
|
||||
|
||||
try:
|
||||
fpin = open(filename, "rb");
|
||||
fpin = open(filename, "rb")
|
||||
except:
|
||||
sys.stdout.write("Unable to open input %s\n" % sys.argv[1])
|
||||
sys.exit(1)
|
||||
|
|
|
@ -24,15 +24,19 @@
|
|||
# The Original Code is: see repository.
|
||||
#
|
||||
# Contributor(s): see repository.
|
||||
#
|
||||
import sys, os, re
|
||||
|
||||
nanblenderhome = os.getenv("NANBLENDERHOME");
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
nanblenderhome = os.getenv("NANBLENDERHOME")
|
||||
|
||||
if nanblenderhome == None:
|
||||
nanblenderhome = os.path.dirname(os.path.abspath(sys.argv[0]))+"/.."
|
||||
nanblenderhome = os.path.dirname(os.path.abspath(sys.argv[0])) + "/.."
|
||||
|
||||
config = nanblenderhome+"/source/blender/blenkernel/BKE_blender.h"
|
||||
config = nanblenderhome + "/source/blender/blenkernel/BKE_blender.h"
|
||||
|
||||
infile = open(config)
|
||||
|
||||
|
@ -40,23 +44,23 @@ major = None
|
|||
minor = None
|
||||
|
||||
for line in infile.readlines():
|
||||
m = re.search("#define BLENDER_VERSION\s+(\d+)", line)
|
||||
if m:
|
||||
major = m.group(1)
|
||||
m = re.search("#define BLENDER_SUBVERSION\s+(\d+)", line)
|
||||
if m:
|
||||
minor = m.group(1)
|
||||
if minor and major:
|
||||
major = float(major) / 100.0
|
||||
break
|
||||
m = re.search("#define BLENDER_VERSION\s+(\d+)", line)
|
||||
if m:
|
||||
major = m.group(1)
|
||||
m = re.search("#define BLENDER_SUBVERSION\s+(\d+)", line)
|
||||
if m:
|
||||
minor = m.group(1)
|
||||
if minor and major:
|
||||
major = float(major) / 100.0
|
||||
break
|
||||
|
||||
infile.close()
|
||||
|
||||
# Major was changed to float, but minor is still a string
|
||||
if minor and major:
|
||||
if minor == "0":
|
||||
print "%.2f" % major
|
||||
else:
|
||||
print "%.2f.%s" % (major, minor)
|
||||
if minor == "0":
|
||||
print "%.2f" % major
|
||||
else:
|
||||
print "%.2f.%s" % (major, minor)
|
||||
else:
|
||||
print "unknownversion"
|
||||
print "unknownversion"
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
from math import atan, pi, degrees
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__ = ["Campbell Barton", "Bob Holcomb", "Richard Lärkäng", "Damien McGinnes", "Mark Stijnman"]
|
||||
__url__ = ("blenderartists.org", "www.blender.org", "www.gametutorials.com", "lib3ds.sourceforge.net/")
|
||||
__version__ = "0.90a"
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__ = "Campbell Barton"
|
||||
__url__ = ['www.blender.org', 'blenderartists.org']
|
||||
__version__ = "1.2"
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__ = "Bill L.Nieuwendorp"
|
||||
__bpydoc__ = """\
|
||||
This script Exports Lightwaves MotionDesigner format.
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
"""
|
||||
Name: 'Wavefront (.obj)...'
|
||||
Blender: 248
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
__author__ = "Bruce Merry"
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__ = ("Bart", "Campbell Barton")
|
||||
__email__ = ["Bart, bart:neeneenee*de"]
|
||||
__url__ = ["Author's (Bart) homepage, http://www.neeneenee.de/vrml"]
|
||||
|
|
|
@ -1,3 +1,23 @@
|
|||
# ##### BEGIN GPL LICENSE BLOCK #####
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import math
|
||||
|
||||
# import Blender
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__= ['Bob Holcomb', 'Richard L?rk?ng', 'Damien McGinnes', 'Campbell Barton', 'Mario Lapin']
|
||||
__url__ = ("blenderartists.org", "www.blender.org", "www.gametutorials.com", "lib3ds.sourceforge.net/")
|
||||
__version__= '0.996'
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
__author__= "Campbell Barton", "Jiri Hnidek", "Paolo Ciccone"
|
||||
__url__= ['http://wiki.blender.org/index.php/Scripts/Manual/Import/wavefront_obj', 'blender.org', 'blenderartists.org']
|
||||
__version__= "2.11"
|
||||
|
|
|
@ -13,4 +13,6 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
"""Package for console specific modules."""
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import inspect
|
||||
import re
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
"""Completer for import statements
|
||||
|
||||
Original code was from IPython/Extensions/ipy_completers.py. The following
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
"""Autocomplete with the standard library"""
|
||||
|
||||
import re
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
"""This module provides intellisense features such as:
|
||||
|
||||
* autocompletion
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8-80 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
def main(context):
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
# import Blender
|
||||
import time, functools
|
||||
import bpy
|
||||
|
|
|
@ -16,9 +16,12 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
import os
|
||||
|
||||
|
||||
class AddPresetBase(bpy.types.Operator):
|
||||
'''Base preset class, only for subclassing
|
||||
subclasses must define
|
||||
|
@ -27,7 +30,7 @@ class AddPresetBase(bpy.types.Operator):
|
|||
bl_idname = "render.preset_add"
|
||||
bl_label = "Add Render Preset"
|
||||
|
||||
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen= 64, default= "")
|
||||
name = bpy.props.StringProperty(name="Name", description="Name of the preset, used to make the path name", maxlen=64, default="")
|
||||
|
||||
def _as_filename(self, name): # could reuse for other presets
|
||||
for char in " !@#$%^&*(){}:\";'[]<>,./?":
|
||||
|
@ -104,6 +107,7 @@ class AddPresetSSS(AddPresetBase):
|
|||
|
||||
preset_subdir = "sss"
|
||||
|
||||
|
||||
class AddPresetCloth(AddPresetBase):
|
||||
'''Add a Cloth Preset.'''
|
||||
bl_idname = "cloth.preset_add"
|
||||
|
@ -124,4 +128,3 @@ class AddPresetCloth(AddPresetBase):
|
|||
bpy.ops.add(AddPresetRender)
|
||||
bpy.ops.add(AddPresetSSS)
|
||||
bpy.ops.add(AddPresetCloth)
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
#from Blender import Object, Draw, Window, sys, Mesh, Geometry
|
||||
from Mathutils import Matrix, Vector, RotationMatrix
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
# ***** END GPL LICENCE BLOCK *****
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
# History
|
||||
#
|
||||
# Originally written by Campbell Barton aka ideasman42
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import unittest
|
||||
import random
|
||||
|
||||
|
@ -29,269 +31,269 @@ test= bpy.data.test
|
|||
# same as above for other types except that the first letter is "i" for int and "b" for bool
|
||||
|
||||
class TestArray(unittest.TestCase):
|
||||
# test that assignment works by: assign -> test value
|
||||
# - rvalue = list of float
|
||||
# - rvalue = list of numbers
|
||||
# test.object
|
||||
# bpy.data.test.farr[3], iarr[3], barr[...], fmarr, imarr, bmarr
|
||||
# test that assignment works by: assign -> test value
|
||||
# - rvalue = list of float
|
||||
# - rvalue = list of numbers
|
||||
# test.object
|
||||
# bpy.data.test.farr[3], iarr[3], barr[...], fmarr, imarr, bmarr
|
||||
|
||||
def setUp(self):
|
||||
test.farr= (1.0, 2.0, 3.0)
|
||||
test.iarr= (7, 8, 9)
|
||||
test.barr= (False, True, False)
|
||||
|
||||
# test access
|
||||
# test slice access, negative indices
|
||||
def test_access(self):
|
||||
rvals= ([1.0, 2.0, 3.0], [7, 8, 9], [False, True, False])
|
||||
for arr, rval in zip((test.farr, test.iarr, test.barr), rvals):
|
||||
self.assertEqual(prop_to_list(arr), rval)
|
||||
self.assertEqual(arr[0:3], rval)
|
||||
self.assertEqual(arr[1:2], rval[1:2])
|
||||
self.assertEqual(arr[-1], arr[2])
|
||||
self.assertEqual(arr[-2], arr[1])
|
||||
self.assertEqual(arr[-3], arr[0])
|
||||
def setUp(self):
|
||||
test.farr= (1.0, 2.0, 3.0)
|
||||
test.iarr= (7, 8, 9)
|
||||
test.barr= (False, True, False)
|
||||
|
||||
# test access
|
||||
# test slice access, negative indices
|
||||
def test_access(self):
|
||||
rvals= ([1.0, 2.0, 3.0], [7, 8, 9], [False, True, False])
|
||||
for arr, rval in zip((test.farr, test.iarr, test.barr), rvals):
|
||||
self.assertEqual(prop_to_list(arr), rval)
|
||||
self.assertEqual(arr[0:3], rval)
|
||||
self.assertEqual(arr[1:2], rval[1:2])
|
||||
self.assertEqual(arr[-1], arr[2])
|
||||
self.assertEqual(arr[-2], arr[1])
|
||||
self.assertEqual(arr[-3], arr[0])
|
||||
|
||||
# fail when index out of bounds
|
||||
def test_access_fail(self):
|
||||
for arr in (test.farr, test.iarr, test.barr):
|
||||
self.assertRaises(IndexError, lambda : arr[4])
|
||||
|
||||
# test assignment of a whole array
|
||||
def test_assign_array(self):
|
||||
# should accept int as float
|
||||
test.farr= (1, 2, 3)
|
||||
# fail when index out of bounds
|
||||
def test_access_fail(self):
|
||||
for arr in (test.farr, test.iarr, test.barr):
|
||||
self.assertRaises(IndexError, lambda : arr[4])
|
||||
|
||||
# test assignment of a whole array
|
||||
def test_assign_array(self):
|
||||
# should accept int as float
|
||||
test.farr= (1, 2, 3)
|
||||
|
||||
# fail when: unexpected no. of items, invalid item type
|
||||
def test_assign_array_fail(self):
|
||||
def assign_empty_list(arr):
|
||||
setattr(test, arr, ())
|
||||
# fail when: unexpected no. of items, invalid item type
|
||||
def test_assign_array_fail(self):
|
||||
def assign_empty_list(arr):
|
||||
setattr(test, arr, ())
|
||||
|
||||
for arr in ("farr", "iarr", "barr"):
|
||||
self.assertRaises(ValueError, assign_empty_list, arr)
|
||||
for arr in ("farr", "iarr", "barr"):
|
||||
self.assertRaises(ValueError, assign_empty_list, arr)
|
||||
|
||||
def assign_invalid_float():
|
||||
test.farr= (1.0, 2.0, "3.0")
|
||||
def assign_invalid_float():
|
||||
test.farr= (1.0, 2.0, "3.0")
|
||||
|
||||
def assign_invalid_int():
|
||||
test.iarr= ("1", 2, 3)
|
||||
def assign_invalid_int():
|
||||
test.iarr= ("1", 2, 3)
|
||||
|
||||
def assign_invalid_bool():
|
||||
test.barr= (True, 0.123, False)
|
||||
def assign_invalid_bool():
|
||||
test.barr= (True, 0.123, False)
|
||||
|
||||
for func in [assign_invalid_float, assign_invalid_int, assign_invalid_bool]:
|
||||
self.assertRaises(TypeError, func)
|
||||
for func in [assign_invalid_float, assign_invalid_int, assign_invalid_bool]:
|
||||
self.assertRaises(TypeError, func)
|
||||
|
||||
# shouldn't accept float as int
|
||||
def assign_float_as_int():
|
||||
test.iarr= (1, 2, 3.0)
|
||||
self.assertRaises(TypeError, assign_float_as_int)
|
||||
# shouldn't accept float as int
|
||||
def assign_float_as_int():
|
||||
test.iarr= (1, 2, 3.0)
|
||||
self.assertRaises(TypeError, assign_float_as_int)
|
||||
|
||||
# non-dynamic arrays cannot change size
|
||||
def assign_different_size(arr, val):
|
||||
setattr(test, arr, val)
|
||||
for arr, val in zip(("iarr", "farr", "barr"), ((1, 2), (1.0, 2.0), (True, False))):
|
||||
self.assertRaises(ValueError, assign_different_size, arr, val)
|
||||
# non-dynamic arrays cannot change size
|
||||
def assign_different_size(arr, val):
|
||||
setattr(test, arr, val)
|
||||
for arr, val in zip(("iarr", "farr", "barr"), ((1, 2), (1.0, 2.0), (True, False))):
|
||||
self.assertRaises(ValueError, assign_different_size, arr, val)
|
||||
|
||||
# test assignment of specific items
|
||||
def test_assign_item(self):
|
||||
for arr, rand_func in zip((test.farr, test.iarr, test.barr), (rand_float, rand_int, rand_bool)):
|
||||
for i in range(len(arr)):
|
||||
val= rand_func()
|
||||
arr[i]= val
|
||||
|
||||
self.assertEqual(arr[i], val)
|
||||
# test assignment of specific items
|
||||
def test_assign_item(self):
|
||||
for arr, rand_func in zip((test.farr, test.iarr, test.barr), (rand_float, rand_int, rand_bool)):
|
||||
for i in range(len(arr)):
|
||||
val= rand_func()
|
||||
arr[i]= val
|
||||
|
||||
self.assertEqual(arr[i], val)
|
||||
|
||||
# float prop should accept also int
|
||||
for i in range(len(test.farr)):
|
||||
val= rand_int()
|
||||
test.farr[i]= val
|
||||
self.assertEqual(test.farr[i], float(val))
|
||||
# float prop should accept also int
|
||||
for i in range(len(test.farr)):
|
||||
val= rand_int()
|
||||
test.farr[i]= val
|
||||
self.assertEqual(test.farr[i], float(val))
|
||||
|
||||
#
|
||||
#
|
||||
|
||||
def test_assign_item_fail(self):
|
||||
def assign_bad_index(arr):
|
||||
arr[4] = 1.0
|
||||
def test_assign_item_fail(self):
|
||||
def assign_bad_index(arr):
|
||||
arr[4] = 1.0
|
||||
|
||||
def assign_bad_type(arr):
|
||||
arr[1]= "123"
|
||||
|
||||
for arr in [test.farr, test.iarr, test.barr]:
|
||||
self.assertRaises(IndexError, assign_bad_index, arr)
|
||||
def assign_bad_type(arr):
|
||||
arr[1]= "123"
|
||||
|
||||
for arr in [test.farr, test.iarr, test.barr]:
|
||||
self.assertRaises(IndexError, assign_bad_index, arr)
|
||||
|
||||
# not testing bool because bool allows not only (True|False)
|
||||
for arr in [test.farr, test.iarr]:
|
||||
self.assertRaises(TypeError, assign_bad_type, arr)
|
||||
# not testing bool because bool allows not only (True|False)
|
||||
for arr in [test.farr, test.iarr]:
|
||||
self.assertRaises(TypeError, assign_bad_type, arr)
|
||||
|
||||
def test_dynamic_assign_array(self):
|
||||
# test various lengths here
|
||||
for arr, rand_func in zip(("fdarr", "idarr", "bdarr"), (rand_float, rand_int, rand_bool)):
|
||||
for length in range(1, 64):
|
||||
rval= make_random_array(length, rand_func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
def test_dynamic_assign_array(self):
|
||||
# test various lengths here
|
||||
for arr, rand_func in zip(("fdarr", "idarr", "bdarr"), (rand_float, rand_int, rand_bool)):
|
||||
for length in range(1, 64):
|
||||
rval= make_random_array(length, rand_func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
|
||||
def test_dynamic_assign_array_fail(self):
|
||||
# could also test too big length here
|
||||
|
||||
def assign_empty_list(arr):
|
||||
setattr(test, arr, ())
|
||||
def test_dynamic_assign_array_fail(self):
|
||||
# could also test too big length here
|
||||
|
||||
def assign_empty_list(arr):
|
||||
setattr(test, arr, ())
|
||||
|
||||
for arr in ("fdarr", "idarr", "bdarr"):
|
||||
self.assertRaises(ValueError, assign_empty_list, arr)
|
||||
for arr in ("fdarr", "idarr", "bdarr"):
|
||||
self.assertRaises(ValueError, assign_empty_list, arr)
|
||||
|
||||
|
||||
class TestMArray(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# reset dynamic array sizes
|
||||
for arr, func in zip(("fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool)):
|
||||
setattr(test, arr, make_random_3d_array((3, 4, 5), func))
|
||||
def setUp(self):
|
||||
# reset dynamic array sizes
|
||||
for arr, func in zip(("fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool)):
|
||||
setattr(test, arr, make_random_3d_array((3, 4, 5), func))
|
||||
|
||||
# test assignment
|
||||
def test_assign_array(self):
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
# assignment of [3][4][5]
|
||||
rval= make_random_3d_array((3, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
# test assignment
|
||||
def test_assign_array(self):
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
# assignment of [3][4][5]
|
||||
rval= make_random_3d_array((3, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
|
||||
# test assignment of [2][4][5], [1][4][5] should work on dynamic arrays
|
||||
# test assignment of [2][4][5], [1][4][5] should work on dynamic arrays
|
||||
|
||||
def test_assign_array_fail(self):
|
||||
def assign_empty_array():
|
||||
test.fmarr= ()
|
||||
self.assertRaises(ValueError, assign_empty_array)
|
||||
def test_assign_array_fail(self):
|
||||
def assign_empty_array():
|
||||
test.fmarr= ()
|
||||
self.assertRaises(ValueError, assign_empty_array)
|
||||
|
||||
def assign_invalid_size(arr, rval):
|
||||
setattr(test, arr, rval)
|
||||
def assign_invalid_size(arr, rval):
|
||||
setattr(test, arr, rval)
|
||||
|
||||
# assignment of 3,4,4 or 3,3,5 should raise ex
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
rval= make_random_3d_array((3, 4, 4), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
# assignment of 3,4,4 or 3,3,5 should raise ex
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
rval= make_random_3d_array((3, 4, 4), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
|
||||
rval= make_random_3d_array((3, 3, 5), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
rval= make_random_3d_array((3, 3, 5), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
|
||||
rval= make_random_3d_array((3, 3, 3), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
rval= make_random_3d_array((3, 3, 3), func)
|
||||
self.assertRaises(ValueError, assign_invalid_size, arr, rval)
|
||||
|
||||
def test_assign_item(self):
|
||||
# arr[i] = x
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr", "fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool) * 2):
|
||||
rval= make_random_2d_array((4, 5), func)
|
||||
def test_assign_item(self):
|
||||
# arr[i] = x
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr", "fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool) * 2):
|
||||
rval= make_random_2d_array((4, 5), func)
|
||||
|
||||
for i in range(3):
|
||||
getattr(test, arr)[i]= rval
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)[i]), rval)
|
||||
for i in range(3):
|
||||
getattr(test, arr)[i]= rval
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)[i]), rval)
|
||||
|
||||
# arr[i][j] = x
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr", "fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool) * 2):
|
||||
# arr[i][j] = x
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr", "fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool) * 2):
|
||||
|
||||
arr= getattr(test, arr)
|
||||
rval= make_random_array(5, func)
|
||||
arr= getattr(test, arr)
|
||||
rval= make_random_array(5, func)
|
||||
|
||||
for i in range(3):
|
||||
for j in range(4):
|
||||
arr[i][j]= rval
|
||||
self.assertEqual(prop_to_list(arr[i][j]), rval)
|
||||
for i in range(3):
|
||||
for j in range(4):
|
||||
arr[i][j]= rval
|
||||
self.assertEqual(prop_to_list(arr[i][j]), rval)
|
||||
|
||||
|
||||
def test_assign_item_fail(self):
|
||||
def assign_wrong_size(arr, i, rval):
|
||||
getattr(test, arr)[i]= rval
|
||||
def test_assign_item_fail(self):
|
||||
def assign_wrong_size(arr, i, rval):
|
||||
getattr(test, arr)[i]= rval
|
||||
|
||||
# assign wrong size at level 2
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
rval1= make_random_2d_array((3, 5), func)
|
||||
rval2= make_random_2d_array((4, 3), func)
|
||||
# assign wrong size at level 2
|
||||
for arr, func in zip(("fmarr", "imarr", "bmarr"), (rand_float, rand_int, rand_bool)):
|
||||
rval1= make_random_2d_array((3, 5), func)
|
||||
rval2= make_random_2d_array((4, 3), func)
|
||||
|
||||
for i in range(3):
|
||||
self.assertRaises(ValueError, assign_wrong_size, arr, i, rval1)
|
||||
self.assertRaises(ValueError, assign_wrong_size, arr, i, rval2)
|
||||
for i in range(3):
|
||||
self.assertRaises(ValueError, assign_wrong_size, arr, i, rval1)
|
||||
self.assertRaises(ValueError, assign_wrong_size, arr, i, rval2)
|
||||
|
||||
def test_dynamic_assign_array(self):
|
||||
for arr, func in zip(("fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool)):
|
||||
# assignment of [3][4][5]
|
||||
rval= make_random_3d_array((3, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
def test_dynamic_assign_array(self):
|
||||
for arr, func in zip(("fdmarr", "idmarr", "bdmarr"), (rand_float, rand_int, rand_bool)):
|
||||
# assignment of [3][4][5]
|
||||
rval= make_random_3d_array((3, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
|
||||
# [2][4][5]
|
||||
rval= make_random_3d_array((2, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
# [2][4][5]
|
||||
rval= make_random_3d_array((2, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
|
||||
# [1][4][5]
|
||||
rval= make_random_3d_array((1, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
# [1][4][5]
|
||||
rval= make_random_3d_array((1, 4, 5), func)
|
||||
setattr(test, arr, rval)
|
||||
self.assertEqual(prop_to_list(getattr(test, arr)), rval)
|
||||
|
||||
|
||||
# test access
|
||||
def test_access(self):
|
||||
pass
|
||||
# test access
|
||||
def test_access(self):
|
||||
pass
|
||||
|
||||
# test slice access, negative indices
|
||||
def test_access_fail(self):
|
||||
pass
|
||||
# test slice access, negative indices
|
||||
def test_access_fail(self):
|
||||
pass
|
||||
|
||||
random.seed()
|
||||
|
||||
def rand_int():
|
||||
return random.randint(-1000, 1000)
|
||||
return random.randint(-1000, 1000)
|
||||
|
||||
def rand_float():
|
||||
return float(rand_int())
|
||||
return float(rand_int())
|
||||
|
||||
def rand_bool():
|
||||
return bool(random.randint(0, 1))
|
||||
return bool(random.randint(0, 1))
|
||||
|
||||
def make_random_array(len, rand_func):
|
||||
arr= []
|
||||
for i in range(len):
|
||||
arr.append(rand_func())
|
||||
|
||||
return arr
|
||||
arr= []
|
||||
for i in range(len):
|
||||
arr.append(rand_func())
|
||||
|
||||
return arr
|
||||
|
||||
def make_random_2d_array(dimsize, rand_func):
|
||||
marr= []
|
||||
for i in range(dimsize[0]):
|
||||
marr.append([])
|
||||
marr= []
|
||||
for i in range(dimsize[0]):
|
||||
marr.append([])
|
||||
|
||||
for j in range(dimsize[1]):
|
||||
marr[-1].append(rand_func())
|
||||
for j in range(dimsize[1]):
|
||||
marr[-1].append(rand_func())
|
||||
|
||||
return marr
|
||||
return marr
|
||||
|
||||
def make_random_3d_array(dimsize, rand_func):
|
||||
marr= []
|
||||
for i in range(dimsize[0]):
|
||||
marr.append([])
|
||||
marr= []
|
||||
for i in range(dimsize[0]):
|
||||
marr.append([])
|
||||
|
||||
for j in range(dimsize[1]):
|
||||
marr[-1].append([])
|
||||
for j in range(dimsize[1]):
|
||||
marr[-1].append([])
|
||||
|
||||
for k in range(dimsize[2]):
|
||||
marr[-1][-1].append(rand_func())
|
||||
for k in range(dimsize[2]):
|
||||
marr[-1][-1].append(rand_func())
|
||||
|
||||
return marr
|
||||
return marr
|
||||
|
||||
def prop_to_list(prop):
|
||||
ret= []
|
||||
ret= []
|
||||
|
||||
for x in prop:
|
||||
if type(x) not in (bool, int, float):
|
||||
ret.append(prop_to_list(x))
|
||||
else:
|
||||
ret.append(x)
|
||||
for x in prop:
|
||||
if type(x) not in (bool, int, float):
|
||||
ret.append(prop_to_list(x))
|
||||
else:
|
||||
ret.append(x)
|
||||
|
||||
return ret
|
||||
return ret
|
||||
|
||||
def suite():
|
||||
return unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(TestArray), unittest.TestLoader().loadTestsFromTestCase(TestMArray)])
|
||||
return unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(TestArray), unittest.TestLoader().loadTestsFromTestCase(TestMArray)])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
||||
unittest.TextTestRunner(verbosity=2).run(suite())
|
||||
|
||||
|
|
Loading…
Reference in New Issue