blender/tests/python/io_stl_import_test.py
Aras Pranckevicius 1ad083dabf Tests: Add FBX import tests, switch OBJ/PLY/STL import tests to the same machinery
"Expected textual data output" comparison based tests for FBX,
OBJ, PLY, STL import.

- There's a tests/python/modules/io_report.py that can produce
  a "fairly short text description of the scene" (meshes, objects,
  curves, cameras, lights, materials, armatures, actions, images).
  About each object, it lists some basic information (e.g. number
  of vertices in the mesh), plus a small slice of "data" (e.g.
  first few values of each mesh attribute).
    - Custom import parameters, if needed, can be provided by
      having a sidecar .json file next to imported file (same
      basename, json extension), that would have a single json
      object with custom arguments.
- Add FBX test coverage, with 46 fairly small files (total size 3.8MB)
  covering various possible cases (meshes, animations, materials,
  hierarchies, cameras, etc. etc.).
- Switch OBJ/PLY/STL import tests to the above machinery, remove C++
  testing code.

Pull Request: https://projects.blender.org/blender/blender/pulls/132624
2025-01-15 05:52:15 +01:00

60 lines
1.7 KiB
Python

# SPDX-FileCopyrightText: 2025 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
import pathlib
import sys
import unittest
import bpy
sys.path.append(str(pathlib.Path(__file__).parent.absolute()))
args = None
class STLImportTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.testdir = args.testdir
cls.output_dir = args.outdir
def test_import_stl(self):
input_files = sorted(pathlib.Path(self.testdir).glob("*.stl"))
self.passed_tests = []
self.failed_tests = []
self.updated_tests = []
from modules import io_report
report = io_report.Report("STL Import", self.output_dir, self.testdir, self.testdir.joinpath("reference"))
for input_file in input_files:
with self.subTest(pathlib.Path(input_file).stem):
bpy.ops.wm.open_mainfile(filepath=str(self.testdir / "../empty.blend"))
ok = report.import_and_check(
input_file, lambda filepath, params: bpy.ops.wm.stl_import(
filepath=str(input_file), **params))
if not ok:
self.fail(f"{input_file.stem} import result does not match expectations")
report.finish("io_stl")
def main():
global args
import argparse
if '--' in sys.argv:
argv = [sys.argv[0]] + sys.argv[sys.argv.index('--') + 1:]
else:
argv = sys.argv
parser = argparse.ArgumentParser()
parser.add_argument('--testdir', required=True, type=pathlib.Path)
parser.add_argument('--outdir', required=True, type=pathlib.Path)
args, remaining = parser.parse_known_args(argv)
unittest.main(argv=remaining)
if __name__ == "__main__":
main()