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