diff options
author | Campbell Barton <ideasman42@gmail.com> | 2009-12-13 17:38:30 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2009-12-13 17:38:30 +0300 |
commit | 7fc4ab2aab403e5db27c7dc7097c8db8afc2cfe8 (patch) | |
tree | 5400b0440397ef3011a8af0131815d7e552dc966 | |
parent | 1add5b58e8e290003a40cf3a123af22703c2fb3b (diff) |
add pep8 headers so these scripts spit out errors when running pep8.
made some changes but mostly these scripts will give pep8 warnings.
26 files changed, 309 insertions, 236 deletions
diff --git a/release/datafiles/datatoc.py b/release/datafiles/datatoc.py index a78b64c5095..8a0e5290cb5 100755 --- a/release/datafiles/datatoc.py +++ b/release/datafiles/datatoc.py @@ -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) diff --git a/release/getversion.py b/release/getversion.py index fd52129bf4a..a9bf3b1d04e 100755 --- a/release/getversion.py +++ b/release/getversion.py @@ -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" diff --git a/release/scripts/io/engine_render_pov.py b/release/scripts/io/engine_render_pov.py index adff98ce9c4..d5f02fa3b6a 100644 --- a/release/scripts/io/engine_render_pov.py +++ b/release/scripts/io/engine_render_pov.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + import bpy from math import atan, pi, degrees diff --git a/release/scripts/io/export_3ds.py b/release/scripts/io/export_3ds.py index ad8ffac1147..edbb80b0272 100644 --- a/release/scripts/io/export_3ds.py +++ b/release/scripts/io/export_3ds.py @@ -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" diff --git a/release/scripts/io/export_fbx.py b/release/scripts/io/export_fbx.py index e0a0367f18e..97af4cb6ebf 100644 --- a/release/scripts/io/export_fbx.py +++ b/release/scripts/io/export_fbx.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + __author__ = "Campbell Barton" __url__ = ['www.blender.org', 'blenderartists.org'] __version__ = "1.2" diff --git a/release/scripts/io/export_mdd.py b/release/scripts/io/export_mdd.py index 98d87ef6a7f..fc85b2996d0 100644 --- a/release/scripts/io/export_mdd.py +++ b/release/scripts/io/export_mdd.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + __author__ = "Bill L.Nieuwendorp" __bpydoc__ = """\ This script Exports Lightwaves MotionDesigner format. diff --git a/release/scripts/io/export_obj.py b/release/scripts/io/export_obj.py index 37ade121311..d6026d10ba9 100644 --- a/release/scripts/io/export_obj.py +++ b/release/scripts/io/export_obj.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + """ Name: 'Wavefront (.obj)...' Blender: 248 diff --git a/release/scripts/io/export_ply.py b/release/scripts/io/export_ply.py index f2cf04ae792..ed85c7fc6d9 100644 --- a/release/scripts/io/export_ply.py +++ b/release/scripts/io/export_ply.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + import bpy __author__ = "Bruce Merry" diff --git a/release/scripts/io/export_x3d.py b/release/scripts/io/export_x3d.py index 969c4cf0752..6cfe0f45626 100644 --- a/release/scripts/io/export_x3d.py +++ b/release/scripts/io/export_x3d.py @@ -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"] diff --git a/release/scripts/io/import_anim_bvh.py b/release/scripts/io/import_anim_bvh.py index a7e621a61a7..a8fe887b950 100644 --- a/release/scripts/io/import_anim_bvh.py +++ b/release/scripts/io/import_anim_bvh.py @@ -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 diff --git a/release/scripts/io/import_scene_3ds.py b/release/scripts/io/import_scene_3ds.py index 6255c80b3a3..4744c5df01a 100644 --- a/release/scripts/io/import_scene_3ds.py +++ b/release/scripts/io/import_scene_3ds.py @@ -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' diff --git a/release/scripts/io/import_scene_obj.py b/release/scripts/io/import_scene_obj.py index a94e0f5e22d..cbd2b831e55 100644 --- a/release/scripts/io/import_scene_obj.py +++ b/release/scripts/io/import_scene_obj.py @@ -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" diff --git a/release/scripts/modules/console/__init__.py b/release/scripts/modules/console/__init__.py index eb32d78b1ef..efd2ed85acc 100644 --- a/release/scripts/modules/console/__init__.py +++ b/release/scripts/modules/console/__init__.py @@ -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.""" diff --git a/release/scripts/modules/console/complete_calltip.py b/release/scripts/modules/console/complete_calltip.py index 486f9469d60..c4687b4f10b 100644 --- a/release/scripts/modules/console/complete_calltip.py +++ b/release/scripts/modules/console/complete_calltip.py @@ -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 diff --git a/release/scripts/modules/console/complete_import.py b/release/scripts/modules/console/complete_import.py index 65a507b349d..875c557f497 100644 --- a/release/scripts/modules/console/complete_import.py +++ b/release/scripts/modules/console/complete_import.py @@ -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 diff --git a/release/scripts/modules/console/complete_namespace.py b/release/scripts/modules/console/complete_namespace.py index 4aa0de558f2..7a9fd331e49 100644 --- a/release/scripts/modules/console/complete_namespace.py +++ b/release/scripts/modules/console/complete_namespace.py @@ -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 diff --git a/release/scripts/modules/console/intellisense.py b/release/scripts/modules/console/intellisense.py index 686b3e7294b..96896d5fd0e 100644 --- a/release/scripts/modules/console/intellisense.py +++ b/release/scripts/modules/console/intellisense.py @@ -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 diff --git a/release/scripts/op/mesh.py b/release/scripts/op/mesh.py index 0e57bc440d1..6ca03b409f0 100644 --- a/release/scripts/op/mesh.py +++ b/release/scripts/op/mesh.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8-80 compliant> + import bpy def main(context): diff --git a/release/scripts/op/mesh_skin.py b/release/scripts/op/mesh_skin.py index 5cf526cc23e..436cd21c9ee 100644 --- a/release/scripts/op/mesh_skin.py +++ b/release/scripts/op/mesh_skin.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + # import Blender import time, functools import bpy diff --git a/release/scripts/op/presets.py b/release/scripts/op/presets.py index 0ce19f712ab..0f6d5e11b5c 100644 --- a/release/scripts/op/presets.py +++ b/release/scripts/op/presets.py @@ -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) - diff --git a/release/scripts/op/uvcalc_smart_project.py b/release/scripts/op/uvcalc_smart_project.py index 2da7174ed99..0dd1f8b1e08 100644 --- a/release/scripts/op/uvcalc_smart_project.py +++ b/release/scripts/op/uvcalc_smart_project.py @@ -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 diff --git a/release/scripts/op/vertexpaint_dirt.py b/release/scripts/op/vertexpaint_dirt.py index 585a2231e21..b4b30fed06f 100644 --- a/release/scripts/op/vertexpaint_dirt.py +++ b/release/scripts/op/vertexpaint_dirt.py @@ -19,6 +19,8 @@ # ***** END GPL LICENCE BLOCK ***** # -------------------------------------------------------------------------- +# <pep8 compliant> + # History # # Originally written by Campbell Barton aka ideasman42 diff --git a/release/scripts/ui/space_dopesheet.py b/release/scripts/ui/space_dopesheet.py index f9381432e27..4710d9de3aa 100644 --- a/release/scripts/ui/space_dopesheet.py +++ b/release/scripts/ui/space_dopesheet.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + import bpy diff --git a/release/scripts/ui/space_graph.py b/release/scripts/ui/space_graph.py index 57e42f9d48c..d97fa2bfeed 100644 --- a/release/scripts/ui/space_graph.py +++ b/release/scripts/ui/space_graph.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + import bpy diff --git a/release/scripts/ui/space_nla.py b/release/scripts/ui/space_nla.py index 622ebb42ab7..285ada5f46e 100644 --- a/release/scripts/ui/space_nla.py +++ b/release/scripts/ui/space_nla.py @@ -16,6 +16,8 @@ # # ##### END GPL LICENSE BLOCK ##### +# <pep8 compliant> + import bpy diff --git a/release/test/rna_array.py b/release/test/rna_array.py index 08aea1c7967..6c6539f5509 100644 --- a/release/test/rna_array.py +++ b/release/test/rna_array.py @@ -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 - - 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: 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) - - def assign_invalid_float(): - test.farr= (1.0, 2.0, "3.0") - - def assign_invalid_int(): - test.iarr= ("1", 2, 3) - - 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) - - # 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) - - # 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)) - - # - - 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) - - # 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_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) + # 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]) + + # 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, ()) + + 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_int(): + test.iarr= ("1", 2, 3) + + 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) + + # 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) + + # 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)) + + # + + 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) + + # 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_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) 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()) |