Created
November 17, 2015 12:59
-
-
Save nutti/631d8d8e763cf20ce697 to your computer and use it in GitHub Desktop.
[Blender] GitHubとTravisCIを用いてBlenderアドオンのテストを自動化する ref: http://qiita.com/nutti/items/fe3f3f14168155df5916
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# プログラミング言語の指定 | |
# BlenderのアドオンはPythonで記述するためpythonを指定 | |
language: python | |
# 使用するPythonのバージョン | |
# ★BlenderのPythonコンソールから利用されているPythonのバージョンを特定可能 | |
python: | |
- "3.4" | |
# install前に実行する処理 | |
before_install: | |
# 可能な限り最新のBlenderをインストール | |
# パッケージマネージャー経由でインストールすることで、Blenderに依存しているパッケージを自動的にインストール(手動で依存するパッケージをインストールするのは手間がかかるため) | |
- sudo apt-get update -qq | |
- sudo apt-get install blender | |
# テスト実行の前準備 | |
install: | |
# 作業領域の作成し、移動 | |
- mkdir tmp && cd tmp | |
# ★最新版のBlenderをダウンロード | |
- wget http://mirror.cs.umn.edu/blender.org/release/Blender2.76/blender-2.76-linux-glibc211-x86_64.tar.bz2 | |
# ★ダウンロードしたBlenderを解凍 | |
- tar jxf blender-2.76-linux-glibc211-x86_64.tar.bz2 | |
- mv blender-2.76-linux-glibc211-x86_64 blender | |
- rm blender-2.76-linux-glibc211-x86_64.tar.bz2 | |
- cd .. | |
# ★アドオンをインストール(Blenderのバージョンに合わせて、ディレクトリを指定) | |
- sudo ln -s ${PWD}/test_addon.py ${PWD}/tmp/blender/2.76/scripts/addons/test_addon.py | |
# テスト実行 | |
script: python ${PWD}/run_tests.py ${PWD}/tmp/blender/blender |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/ # リポジトリのルートディレクトリ | |
├ .travis.yml # Travis CI用設定ファイル | |
├ test_addon.py # テストするアドオン | |
├ run_tests.py # 個別のテストを呼び出すスクリプト | |
├ test_1.py # test_addon.pyのテストスクリプト | |
└ test_1.blend # test_1.py用の.blendファイル |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git push |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import subprocess | |
if len(sys.argv) != 2: | |
exit(-1) | |
blender_path = sys.argv[1] # Blender本体のパス | |
addon_name = 'test_addon' # テストするアドオン | |
blend_file = 'test_1.blend' # テスト用に作成した.blendファイル | |
src_file = 'test_1.py' # 個別のテスト用スクリプト | |
# 個別のテスト用スクリプト(test_1.py)を実行 | |
# 実行されるコマンド: blender --addons test_addon --factory-startup -noaudio -b test_1.blend --python test_1.py | |
# オプション: | |
# --addons: test_addonを有効化 | |
# --factory-startup: startup.blendファイルを読み込まない | |
# -noaudio: サウンドの無効化 | |
# -b: UIなしBlender起動 | |
# blend_file: 読み込む.blendファイル | |
# --python: src_fileに指定したPythonスクリプトを実行 | |
subprocess.call([blender_path, '--addons', addon_name, '--factory-startup', '-noaudio', '-b', blend_file, '--python', src_file]) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest # Pythonのテストフレームワーク | |
import bpy | |
# テストセット | |
class TestAddon(unittest.TestCase): | |
# アドオンが正常に有効化されたことを確認 | |
def test_addon_enabled(self): | |
self.assertIsNotNone(by.ops.uv.test_ops) | |
# アドオンを実行して正常終了したことを確認 | |
def test_execute(self): | |
result = boy.ops.uv.test_ops() | |
self.assertSetEqual(result, {'FINISHED'}) | |
# テストセットの作成 | |
suite = unittest.defaultTestLoader.loadTestsFromTestCase(TestAddon) | |
# テスト実行 | |
unittest.TextTestRunner().run(suite) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
bl_info = { | |
"name": "テストするアドオン", | |
"author": "Nutti", | |
"version": (1, 0), | |
"blender": (2, 75, 0), | |
"location": "UV Mapping > テストするアドオン", | |
"description": "テスト対象のアドオン", | |
"warning": "", | |
"support": "TESTING", | |
"wiki_url": "", | |
"tracker_url": "", | |
"category": "UV" | |
} | |
class TestOps(bpy.types.Operator): | |
bl_idname = "uv.test_ops" | |
bl_label = "テスト" | |
bl_description = "テストするオペレーション" | |
bl_options = {'REGISTER', 'UNDO'} | |
def execute(self, context): | |
return {'FINISHED'} | |
def register(): | |
bpy.utils.register_module(__name__) | |
def unregister(): | |
bpy.utils.unregister_module(__name__) | |
if __name__ == "__main__": | |
register() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment