Files
test2/tests/files/auto/test_utils.py
Sergey Sharybin bbfc97ad6f Move tests/data and assets to the main repository
This change moves the tests data files and publish folder of assets
repository to the main blender.git repository as LFS files.

The goal of this change is to eliminate toil of modifying tests,
cherry-picking changes to LFS branches, adding tests as part of a
PR which brings new features or fixes.

More detailed explanation and conversation can be found in the
design task.

Ref #137215

Pull Request: https://projects.blender.org/blender/blender/pulls/137219
2025-05-05 15:10:22 +02:00

78 lines
1.8 KiB
Python

# SPDX-FileCopyrightText: 2024 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import sys
import bpy
import time
# Get the cycles test directory
filepath = bpy.data.filepath
blend_files_dir = os.path.dirname(filepath)
test_dir = os.path.dirname(__file__)
# Get the filename without ending
basename = os.path.basename(filepath)
filename = os.path.splitext(basename)[0]
def write_log_file(seconds, dir, blend_file, shading):
rev = get_blender_revision()
seconds = round(seconds, 2)
path = "%s/test_renders/log.txt" % dir
try:
logfile = open(path, "a")
try:
logfile.write('%s - %s - %s - %s seconds\n' % (blend_file, rev, shading, seconds))
finally:
logfile.close()
except IOError:
pass
def is_background():
return bpy.app.background
def get_blender_revision():
return bpy.app.build_revision
def set_shading_system(scene, system):
if system == 'svm':
scene.cycles['shading_system'] = 0
elif system == 'osl':
scene.cycles['shading_system'] = 1
def render(shading_system):
scene = bpy.context.scene
if shading_system == "":
scene.render.filepath = "%s/test_renders/%s" % (test_dir, filename)
else:
set_shading_system(scene, shading_system)
scene.render.filepath = "%s/test_renders/%s_%s" % (test_dir, filename, shading_system)
scene.render.image_settings.file_format = 'PNG'
scene.render.use_file_extension = True
start_time = time.time()
bpy.ops.render.render(write_still=True)
end_time = time.time()
write_log_file((end_time - start_time), test_dir, basename, shading_system)
def main():
# Only run in background mode
if not is_background():
return
if filepath.find("cycles") == -1:
render("")
else:
render("svm")
render("osl")