Tests: Add tests for image format saving and loading #104442
|
@ -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
|
||||
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
Brecht Van Lommel
commented
Can just be Or better 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
Brecht Van Lommel
commented
Same comment. Same comment.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
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.