diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-01-19 02:12:02 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-01-19 02:12:02 +0300 |
commit | 11f8b5fceb45b6e7a04686fa6f9ed255c83b58a4 (patch) | |
tree | bb2ce01982d5abfab57ecf504baa306fc601cb5c /release/test | |
parent | eff0e29cbae095baae26fc650baed36ff0573f50 (diff) |
move release/test to source/test, there is nothing release about this dir.
Diffstat (limited to 'release/test')
-rw-r--r-- | release/test/pep8.py | 101 | ||||
-rw-r--r-- | release/test/rna_array.py | 297 | ||||
-rw-r--r-- | release/test/rna_info_dump.py | 131 |
3 files changed, 0 insertions, 529 deletions
diff --git a/release/test/pep8.py b/release/test/pep8.py deleted file mode 100644 index 3ccd7dd79b6..00000000000 --- a/release/test/pep8.py +++ /dev/null @@ -1,101 +0,0 @@ -# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -# <pep8 compliant> - -import os - -# depends on pep8, pyflakes, pylint -# for ubuntu -# -# sudo apt-get install pylint pyflakes -# -# sudo apt-get install python-setuptools python-pip -# sudo pip install pep8 -# -# in debian install pylint pyflakes pep8 with apt-get/aptitude/etc -# -# on *nix run -# python release/test/pep8.py > pep8_error.txt 2>&1 - -# how many lines to read into the file, pep8 comment -# should be directly after the licence header, ~20 in most cases -PEP8_SEEK_COMMENT = 40 -SKIP_PREFIX = "./tools", "./config", "./scons", "./extern" - - -def file_list_py(path): - for dirpath, dirnames, filenames in os.walk(path): - for filename in filenames: - if filename.endswith(".py"): - yield os.path.join(dirpath, filename) - - -def is_pep8(path): - print(path) - f = open(path, 'r', encoding="utf8") - for i in range(PEP8_SEEK_COMMENT): - line = f.readline() - if line.startswith("# <pep8"): - if line.startswith("# <pep8 compliant>"): - return 1 - elif line.startswith("# <pep8-80 compliant>"): - return 2 - f.close() - return 0 - - -def main(): - files = [] - files_skip = [] - for f in file_list_py("."): - if [None for prefix in SKIP_PREFIX if f.startswith(prefix)]: - continue - - pep8_type = is_pep8(f) - - if pep8_type: - # so we can batch them for each tool. - files.append((os.path.abspath(f), pep8_type)) - else: - files_skip.append(f) - - print("\nSkipping...") - for f in files_skip: - print(" %s" % f) - - # pyflakes - print("\n\n\n# running pep8...") - for f, pep8_type in files: - if pep8_type == 1: - # E501:80 line length - os.system("pep8 --repeat --ignore=E501 '%s'" % (f)) - else: - os.system("pep8 --repeat '%s'" % (f)) - - print("\n\n\n# running pyflakes...") - for f, pep8_type in files: - os.system("pyflakes '%s'" % f) - - print("\n\n\n# running pylint...") - for f, pep8_type in files: - # let pep8 complain about line length - os.system("pylint --reports=n --max-line-length=1000 '%s'" % f) - -if __name__ == "__main__": - main() diff --git a/release/test/rna_array.py b/release/test/rna_array.py deleted file mode 100644 index 06b4735cc0d..00000000000 --- a/release/test/rna_array.py +++ /dev/null @@ -1,297 +0,0 @@ -# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -import unittest -import random - -test= bpy.data.test - -# farr - 1-dimensional array of float -# fdarr - dynamic 1-dimensional array of float -# fmarr - 3-dimensional ([3][4][5]) array of float -# fdmarr - dynamic 3-dimensional (ditto size) array of float - -# 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) - - -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)) - - # 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 - - 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) - - # 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, 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) - - 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= 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) - - - 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) - - 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) - - # [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) - - - # test access - def test_access(self): - pass - - # test slice access, negative indices - def test_access_fail(self): - pass - -random.seed() - -def rand_int(): - return random.randint(-1000, 1000) - -def rand_float(): - return float(rand_int()) - -def rand_bool(): - 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 - -def make_random_2d_array(dimsize, rand_func): - marr= [] - for i in range(dimsize[0]): - marr.append([]) - - for j in range(dimsize[1]): - marr[-1].append(rand_func()) - - return marr - -def make_random_3d_array(dimsize, rand_func): - marr= [] - for i in range(dimsize[0]): - marr.append([]) - - for j in range(dimsize[1]): - marr[-1].append([]) - - for k in range(dimsize[2]): - marr[-1][-1].append(rand_func()) - - return marr - -def prop_to_list(prop): - ret= [] - - for x in prop: - if type(x) not in (bool, int, float): - ret.append(prop_to_list(x)) - else: - ret.append(x) - - return ret - -def suite(): - return unittest.TestSuite([unittest.TestLoader().loadTestsFromTestCase(TestArray), unittest.TestLoader().loadTestsFromTestCase(TestMArray)]) - -if __name__ == "__main__": - unittest.TextTestRunner(verbosity=2).run(suite()) - diff --git a/release/test/rna_info_dump.py b/release/test/rna_info_dump.py deleted file mode 100644 index 62c1248d733..00000000000 --- a/release/test/rna_info_dump.py +++ /dev/null @@ -1,131 +0,0 @@ -# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -# -# ##### END GPL LICENSE BLOCK ##### - -# <pep8 compliant> - -# Used for generating API diff's between releases -# ./blender.bin --background --python release/test/rna_info_dump.py - -import bpy - - -def api_dump(use_properties=True, use_functions=True): - - def prop_type(prop): - if prop.type == "pointer": - return prop.fixed_type.identifier - else: - return prop.type - - def func_to_str(struct_id_str, func_id, func): - - args = [] - for prop in func.args: - data_str = "%s %s" % (prop_type(prop), prop.identifier) - if prop.array_length: - data_str += "[%d]" % prop.array_length - if not prop.is_required: - data_str += "=%s" % prop.default_str - args.append(data_str) - - data_str = "%s.%s(%s)" % (struct_id_str, func_id, ", ".join(args)) - if func.return_values: - return_args = ", ".join(prop_type(arg) for arg in func.return_values) - if len(func.return_values) > 1: - data_str += " --> (%s)" % return_args - else: - data_str += " --> %s" % return_args - return data_str - - def prop_to_str(struct_id_str, prop_id, prop): - - prop_str = " <-- %s" % prop_type(prop) - if prop.array_length: - prop_str += "[%d]" % prop.array_length - - data_str = "%s.%s %s" % (struct_id_str, prop_id, prop_str) - return data_str - - def struct_full_id(v): - struct_id_str = v.identifier # "".join(sid for sid in struct_id if struct_id) - - for base in v.get_bases(): - struct_id_str = base.identifier + "|" + struct_id_str - - return struct_id_str - - def dump_funcs(): - data = [] - for struct_id, v in sorted(struct.items()): - struct_id_str = struct_full_id(v) - - funcs = [(func.identifier, func) for func in v.functions] - - for func_id, func in funcs: - data.append(func_to_str(struct_id_str, func_id, func)) - - for prop in v.properties: - if prop.collection_type: - funcs = [(prop.identifier + "." + func.identifier, func) for func in prop.collection_type.functions] - for func_id, func in funcs: - data.append(func_to_str(struct_id_str, func_id, func)) - data.sort() - data.append("# * functions *") - return data - - def dump_props(): - data = [] - for struct_id, v in sorted(struct.items()): - struct_id_str = struct_full_id(v) - - props = [(prop.identifier, prop) for prop in v.properties] - - for prop_id, prop in props: - data.append(prop_to_str(struct_id_str, prop_id, prop)) - - for prop in v.properties: - if prop.collection_type: - props = [(prop.identifier + "." + prop_sub.identifier, prop_sub) for prop_sub in prop.collection_type.properties] - for prop_sub_id, prop_sub in props: - data.append(prop_to_str(struct_id_str, prop_sub_id, prop_sub)) - data.sort() - data.insert(0, "# * properties *") - return data - - import rna_info - struct = rna_info.BuildRNAInfo()[0] - data = [] - - if use_functions: - data.extend(dump_funcs()) - - if use_properties: - data.extend(dump_props()) - - if bpy.app.background: - import sys - sys.stderr.write("\n".join(data)) - sys.stderr.write("\n\nEOF\n") - else: - text = bpy.data.texts.new(name="api.py") - text.from_string(data) - - print("END") - -if __name__ == "__main__": - api_dump() |