Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-03-19 02:58:13 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-03-19 02:58:13 +0300
commit3b8d4aa25f23f1c4c1d9a42e6c876333c4f2c6d2 (patch)
treef9b24c457bde77645dd34d10d2e0bd9dce9ae6aa /source/tests/bl_load_addons.py
parent5f8e8f2251d473c61f46e6d35cc52b0f7ae20720 (diff)
2 tests for ctest.
- script_load_addons: loads and onloads all addons, error if any cant be enabled or disabled. - script_load_modules: loads all blenders modules, error if any modules raise an exception or if any modules in the scripts dir are not tested (except for presets and templates). These are useful because lazy module loading means a module can have an error which isnt raised until the tools used. This gives a way to detect basic errors that used to happen on startup or when enabling the addon.
Diffstat (limited to 'source/tests/bl_load_addons.py')
-rw-r--r--source/tests/bl_load_addons.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/source/tests/bl_load_addons.py b/source/tests/bl_load_addons.py
new file mode 100644
index 00000000000..5bd83abbcb6
--- /dev/null
+++ b/source/tests/bl_load_addons.py
@@ -0,0 +1,78 @@
+# ##### 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>
+
+# simple script to enable all addons, and disable
+
+import bpy
+import addon_utils
+
+import sys
+import imp
+
+
+def reload_addons(do_reload=True, do_reverse=True):
+ modules = addon_utils.modules({})
+ modules.sort(key=lambda mod: mod.__name__)
+ addons = bpy.context.user_preferences.addons
+
+ # first disable all
+ for mod_name in list(addons.keys()):
+ addon_utils.disable(mod_name)
+
+ assert(bool(addons) == False)
+
+ # Run twice each time.
+ for i in (0, 1):
+ for mod in modules:
+ mod_name = mod.__name__
+ print("\tenabling:", mod_name)
+ addon_utils.enable(mod_name)
+ assert(mod_name in addons)
+
+ for mod in addon_utils.modules({}):
+ mod_name = mod.__name__
+ print("\tdisabling:", mod_name)
+ addon_utils.disable(mod_name)
+ assert(not (mod_name in addons))
+
+ # now test reloading
+ if do_reload:
+ imp.reload(sys.modules[mod_name])
+
+ if do_reverse:
+ # incase order matters when it shouldnt
+ modules.reverse()
+
+
+def main():
+ reload_addons(do_reload=False, do_reverse=False)
+ reload_addons(do_reload=False, do_reverse=True)
+ reload_addons(do_reload=True, do_reverse=True)
+
+
+if __name__ == "__main__":
+
+ # So a python error exits(1)
+ try:
+ main()
+ except:
+ import traceback
+ traceback.print_exc()
+ sys.exit(1)