Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Feb 1, 2024
1 parent b1cf89a commit 24d1244
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Get required packages for Blender
run: |
sudo apt-get update -qq
sudo apt-get install -y blender wget python3 python3-pip zip libglu1 libfreetype6
sudo apt-get install -y blender wget python3 python3-pip zip libglu1 libfreetype6 libgl1-mesa-dev

Check failure on line 42 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / yamllint

42:81 [line-length] line too long (107 > 80 characters)
- name: Get required pip packages
run: pip3 install -r requirements.txt
Expand All @@ -51,4 +51,4 @@ jobs:
run: cp -r src/screencast_keys blender-bin/blender-v${{ matrix.blender_version }}-bin/${{ matrix.blender_version }}/scripts/addons

Check failure on line 51 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / yamllint

51:81 [line-length] line too long (138 > 80 characters)

- name: Run add-on unittest
run: blender-bin/blender-v${{ matrix.blender_version }}-bin/blender --factory-startup --background -noaudio # --python tests/python/run_tests.py
run: blender-bin/blender-v${{ matrix.blender_version }}-bin/blender --factory-startup --background -noaudio --python tests/python/run_tests.py

Check failure on line 54 in .github/workflows/ci.yml

View workflow job for this annotation

GitHub Actions / yamllint

54:81 [line-length] line too long (150 > 80 characters)
23 changes: 23 additions & 0 deletions tests/python/run_tests.py
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()
1 change: 1 addition & 0 deletions tests/python/screencast_keys_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import ops_test
95 changes: 95 additions & 0 deletions tests/python/screencast_keys_test/common.py
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
12 changes: 12 additions & 0 deletions tests/python/screencast_keys_test/ops_test.py
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

0 comments on commit 24d1244

Please sign in to comment.