Page MenuHome
Paste P1411

D7813 stress test
ActivePublic

Authored by Campbell Barton (campbellbarton) on May 22 2020, 5:44 AM.
# Run with:
# blender -b --python D7813_stress_test.py
import random
from bpy.utils.units import to_value
TESTS = 10000
SEED = 321
choose_numbers = (
"2", "2e-2", "2e+2", "2e+2", "0.2e+2", "0.2e+2_2",
# Parenthesized.
"(0.2-2_2)", "(0.2+2_2)", "(0.2e-2_2)", "(0.2e+2_2)",
)
choose_ops = ("-", "+", "*")
choose_spaces = ("", " ")
from bpy import context
unit_system = context.scene.unit_settings.system
unit_category = 'LENGTH'
random.seed(SEED)
for i in range(TESTS):
values = []
for i in range(random.randint(2, 24)):
if i != 0:
values.append(random.choice(choose_ops))
values.append(random.choice(choose_spaces))
values.append(random.choice(choose_numbers))
expr = "".join(values)
value_unit = to_value(unit_system, unit_category, expr)
value_python = eval(expr)
assert(value_unit == value_python)