Tests: Add tests for image format saving and loading #104442

Closed
Jesse Yurkovich wants to merge 6 commits from deadpin:image-tests into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 8 additions and 12 deletions
Showing only changes of commit 6ecb3cbb2f - Show all commits

View File

@ -7,7 +7,7 @@ import unittest
import bpy
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(str(pathlib.Path(__file__).parent.absolute()))
deadpin marked this conversation as resolved

We're trying to move away from os.path towards pathlib. I think removing the few usages in the new code in this patch is relatively straightforward.

We're trying to move away from os.path towards pathlib. I think removing the few usages in the new code in this patch is relatively straightforward.
from modules.imbuf_test import (
print_message,
AbstractImBufTest
@ -34,15 +34,12 @@ class ImBufTest(AbstractImBufTest):
actual_metadata = f"{channels=} {is_float=} {colorspace=} {alpha_mode=}"
# Save actual metadata
with open(out_metadata_path, "w+") as meta:
meta.write(actual_metadata)
out_metadata_path.write_text(actual_metadata, encoding="utf-8")
deadpin marked this conversation as resolved

Can just be "w"?

Or better out_metadata_path.write_text(out_metadata_path) when using pathlib.

Can just be `"w"`? Or better `out_metadata_path.write_text(out_metadata_path)` when using `pathlib`.
if os.path.exists(ref_metadata_path):
# Diff the metadata
expected_metadata = ""
if ref_metadata_path.exists():
# Compare with expected
try:
with open(ref_metadata_path, "r") as meta:
expected_metadata = meta.read()
expected_metadata = ref_metadata_path.read_text(encoding="utf-8")
failed = not (actual_metadata == expected_metadata)
except BaseException as e:
@ -56,9 +53,8 @@ class ImBufTest(AbstractImBufTest):
failed = True
if failed and self.update:
# Update reference metadata if requested.
with open(ref_metadata_path, "w+") as meta:
meta.write(actual_metadata)
# Update reference if requested.
ref_metadata_path.write_text(actual_metadata, encoding="utf-8")
failed = False
return not failed
deadpin marked this conversation as resolved

Same comment.

Same comment.

View File

@ -6,7 +6,7 @@ import unittest
import bpy
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(str(pathlib.Path(__file__).parent.absolute()))
from modules.imbuf_test import (
print_message,
AbstractImBufTest