diff --git a/tests/blendfile_templates.py b/tests/blendfile_templates.py index cd39119..5896dc7 100644 --- a/tests/blendfile_templates.py +++ b/tests/blendfile_templates.py @@ -23,11 +23,11 @@ def _clear_blend(): bpy_data_iter.remove(id_data) -def create_blank(blendfile_root, deps): +def create_blank(blendfile_root, _create_data, deps): assert(isinstance(deps, list)) -def create_image_single(blendfile_root, deps): +def create_image_single(blendfile_root, _create_data, deps): import bpy path = "//my_image.png" @@ -39,7 +39,7 @@ def create_image_single(blendfile_root, deps): image.save() -def create_from_files(blendfile_root, deps): +def create_from_files(blendfile_root, _create_data, deps): """Create a blend file which users all sub-directories. (currently images only) """ @@ -62,12 +62,20 @@ def create_from_files(blendfile_root, deps): deps.append(f_abs) + + if __name__ == "__main__": import sys - blendfile, blendfile_root, blendfile_deps_json, create_id, returncode = sys.argv[-5:] + blendfile, blendfile_root, blendfile_deps_json, create_id, create_data, returncode = sys.argv[-6:] returncode = int(returncode) create_fn = globals()[create_id] + if create_data != "NONE": + with open(create_data, 'r') as f: + import json + create_data = json.load(f) + del json + # ---- import bpy # no need for blend1's @@ -81,7 +89,7 @@ if __name__ == "__main__": _clear_blend() deps = [] - create_fn(blendfile_root, deps) + create_fn(blendfile_root, create_data, deps) if deps: with open(blendfile_deps_json, 'w') as f: diff --git a/tests/test_cli.py b/tests/test_cli.py index 922d16d..cad1220 100755 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -337,10 +337,25 @@ def _dbg_dump_path(path): print("\n".join(sorted(stdout.decode('utf-8').split("\n")))) -def blendfile_template_create(blendfile, blendfile_root, create_id, deps): +def blendfile_template_create(blendfile, blendfile_root, create_id, create_data, deps): returncode_test = 123 blendfile_deps_json = os.path.join(TEMP_LOCAL, "blend_template_deps.json") os.makedirs(os.path.dirname(blendfile), exist_ok=True) + + if create_data is not None: + blendfile_create_data_json = os.path.join(TEMP_LOCAL, "blendfile_create_data.json") + with open(blendfile_create_data_json, 'w') as f: + import json + json.dump( + create_data, f, ensure_ascii=False, + check_circular=False, + # optional (pretty) + sort_keys=True, indent=4, separators=(',', ': '), + ) + del json + else: + blendfile_create_data_json = None + cmd = ( "blender", "--background", @@ -353,18 +368,23 @@ def blendfile_template_create(blendfile, blendfile_root, create_id, deps): blendfile_root, blendfile_deps_json, create_id, + "NONE" if blendfile_create_data_json is None else blendfile_create_data_json, str(returncode_test), ) stdout, stderr, returncode = run(cmd) if os.path.exists(blendfile_deps_json): - import json with open(blendfile_deps_json, 'r') as f: + import json deps[:] = json.load(f) + del json os.remove(blendfile_deps_json) else: deps.clear() + if blendfile_create_data_json is not None: + os.remove(blendfile_create_data_json) + if returncode != returncode_test: # verbose will have already printed if not VERBOSE: @@ -386,7 +406,7 @@ def blendfile_template_create_from_files(proj_path, session_path, blendfile, ima blendfile_abs = os.path.join(session_path, blendfile[0]) deps = [] - blendfile_template_create(blendfile_abs, session_path, "create_from_files", deps) + blendfile_template_create(blendfile_abs, session_path, "create_from_files", None, deps) # not essential but we need to be sure what we made has correct deps # otherwise further tests will fail @@ -720,7 +740,7 @@ class BamBlendTest(BamSimpleTestCase): blendfile = os.path.join(TEMP_SESSION, create_id + ".blend") deps = [] - if not blendfile_template_create(blendfile, TEMP_SESSION, create_id, deps): + if not blendfile_template_create(blendfile, TEMP_SESSION, create_id, None, deps): # self.fail("blend file couldn't be create") # ... we want to keep running self.assertTrue(False, True) # GRR, a better way? @@ -743,7 +763,7 @@ class BamBlendTest(BamSimpleTestCase): def test_empty(self): file_name = "testfile.blend" blendfile = os.path.join(TEMP_LOCAL, file_name) - if not blendfile_template_create(blendfile, TEMP_LOCAL, "create_blank", []): + if not blendfile_template_create(blendfile, TEMP_LOCAL, "create_blank", None, []): self.fail("blend file couldn't be created") return @@ -765,7 +785,7 @@ class BamDeleteTest(BamSessionTestCase): # now do a real commit blendfile = os.path.join(session_path, file_name) - if not blendfile_template_create(blendfile, session_path, "create_blank", []): + if not blendfile_template_create(blendfile, session_path, "create_blank", None, []): self.fail("blend file couldn't be created") return