-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import sys | ||
import unittest | ||
|
||
def test_main(): | ||
import os | ||
path = os.path.dirname(__file__) | ||
sys.path.append(path) | ||
|
||
import screencast_keys_test | ||
|
||
test_cases = [ | ||
screencast_keys_test.ops_test.TestOps, | ||
] | ||
|
||
suite = unittest.TestSuite() | ||
for case in test_cases: | ||
suite.addTest(unittest.makeSuite(case)) | ||
ret = unittest.TextTestRunner().run(suite).wasSuccessful() | ||
sys.exit(not ret) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_main() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import ops_test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import sys | ||
import unittest | ||
|
||
import bpy | ||
|
||
|
||
TESTEE_FILE = "testee.blend" | ||
|
||
|
||
def check_addon_enabled(mod): | ||
if compat.check_version(2, 80, 0) < 0: | ||
result = bpy.ops.wm.addon_enable(module=mod) | ||
else: | ||
result = bpy.ops.preferences.addon_enable(module=mod) | ||
assert (result == {'FINISHED'}), "Failed to enable add-on %s" % (mod) | ||
assert (mod in compat.get_user_preferences(bpy.context).addons.keys()), "Failed to enable add-on %s" % (mod) | ||
|
||
|
||
def check_addon_disabled(mod): | ||
if compat.check_version(2, 80, 0) < 0: | ||
result = bpy.ops.wm.addon_disable(module=mod) | ||
else: | ||
result = bpy.ops.preferences.addon_disable(module=mod) | ||
assert (result == {'FINISHED'}), "Failed to disable add-on %s" % (mod) | ||
assert (not mod in compat.get_user_preferences(bpy.context).addons.keys()), "Failed to disable add-on %s" % (mod) | ||
|
||
|
||
def operator_exists(idname): | ||
try: | ||
from bpy.ops import op_as_string | ||
op_as_string(idname) | ||
return True | ||
except: | ||
return False | ||
|
||
|
||
def menu_exists(idname): | ||
return idname in dir(bpy.types) | ||
|
||
|
||
class TestBase(unittest.TestCase): | ||
|
||
package_name = "magic_uv" | ||
module_name = "" | ||
submodule_name = None | ||
idname = [] | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
if cls.submodule_name is not None: | ||
print("\n======== Module Test: {}.{} ({}) ========" | ||
.format(cls.package_name, cls.module_name, cls.submodule_name)) | ||
else: | ||
print("\n======== Module Test: {}.{} ========" | ||
.format(cls.package_name, cls.module_name)) | ||
try: | ||
bpy.ops.wm.read_factory_settings() | ||
check_addon_enabled(cls.package_name) | ||
for op in cls.idname: | ||
if op[0] == 'OPERATOR': | ||
assert operator_exists(op[1]), \ | ||
"Operator {} does not exist".format(op[1]) | ||
elif op[0] == 'MENU': | ||
assert menu_exists(op[1]), \ | ||
"Menu {} does not exist".format(op[1]) | ||
bpy.ops.wm.save_as_mainfile(filepath=TESTEE_FILE) | ||
except AssertionError as e: | ||
print(e) | ||
sys.exit(1) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
try: | ||
check_addon_disabled(cls.package_name) | ||
for op in cls.idname: | ||
if op[0] == 'OPERATOR': | ||
assert not operator_exists(op[1]), "Operator {} exists".format(op[1]) | ||
elif op[0] == 'MENU': | ||
assert not menu_exists(op[1]), "Menu %s exists".format(op[1]) | ||
except AssertionError as e: | ||
print(e) | ||
sys.exit(1) | ||
|
||
def setUp(self): | ||
bpy.ops.wm.open_mainfile(filepath=TESTEE_FILE) | ||
self.setUpEachMethod() | ||
|
||
def setUpEachMethod(self): | ||
pass | ||
|
||
def tearDown(self): | ||
self.tearDownEachMethod() | ||
|
||
def tearDownEachMethod(self): | ||
pass |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from . import common | ||
|
||
|
||
class TestOps(common.TestBase): | ||
module_name = "ops" | ||
idname = [ | ||
('OPERATOR', 'wm.sk_screencast_keys'), | ||
] | ||
|
||
# this test can not be done because area always NoneType in console run | ||
def test_nothing(self): | ||
pass |