1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
# SPDX-FileCopyrightText: 2019-2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
"""
Utility script, called by ``run.py`` to run inside Blender,
to avoid boilerplate code having to be added into each test.
"""
import os
import sys
def create_parser():
import argparse
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawTextHelpFormatter,
)
parser.add_argument(
"--keep-open",
dest="keep_open",
default=False,
action='store_true',
required=False,
help="Keep the Blender window open after running the test.",
)
parser.add_argument(
"--step-command-pre",
dest="step_command_pre",
default=None,
required=False,
help="See 'run.py'",
)
parser.add_argument(
"--step-command-post",
dest="step_command_post",
default=None,
required=False,
help="See 'run.py'",
)
parser.add_argument(
"--tests",
dest="tests",
nargs='+',
required=True,
metavar="TEST_ID",
help="Names of tests to run.",
)
return parser
def main():
directory = os.path.dirname(__file__)
sys.path.insert(0, directory)
if "bpy" not in sys.modules:
raise Exception("This must run inside Blender")
import bpy
import gpu
parser = create_parser()
args = parser.parse_args(sys.argv[sys.argv.index("--") + 1:])
verbose = os.getenv('BLENDER_VERBOSE') is not None
# Check if `bpy.app.use_event_simulate` has been enabled by the test itself.
# When writing tests, it's useful if the test can temporarily be set to keep the window open.
def on_error():
if not bpy.app.use_event_simulate:
args.keep_open = True
if not args.keep_open:
sys.exit(1)
def on_exit():
if not bpy.app.use_event_simulate:
args.keep_open = True
if not args.keep_open:
sys.exit(0)
else:
bpy.app.use_event_simulate = False
gpu_device = gpu.platform.device_type_get()
BLOCKLIST = []
if os.getenv("BLENDER_TEST_IGNORE_BLOCKLIST") is None:
if sys.platform == "win32" and gpu_device == "INTEL":
# See #149084 for the tracking issue
BLOCKLIST = ["test_workspace"]
is_first = True
for test_id in args.tests:
mod_name, fn_name = test_id.partition(".")[0::2]
if mod_name in BLOCKLIST or test_id in BLOCKLIST:
if not args.keep_open:
sys.exit(0)
if not is_first:
bpy.ops.wm.read_homefile()
is_first = False
mod = __import__(mod_name)
test_fn = getattr(mod, fn_name)
from modules import easy_keys
# So we can get the operator ID's.
bpy.context.preferences.view.show_developer_ui = True
# Hack back in operator search.
easy_keys.setup_default_preferences(bpy.context.preferences)
easy_keys.run(
test_fn(),
on_error=on_error,
on_exit=on_exit,
# Optional.
on_step_command_pre=args.step_command_pre,
on_step_command_post=args.step_command_post,
)
if __name__ == "__main__":
main()
|