Add Save Image Dumas node
This commit is contained in:
@@ -24,10 +24,18 @@ class FakeImageArray:
|
||||
|
||||
|
||||
class FakeTensorBatch:
|
||||
def __init__(self, width=8, height=6):
|
||||
def __init__(self, width=8, height=6, count=1):
|
||||
self.image = FakeImageArray(width=width, height=height)
|
||||
self.shape = (count, height, width, 3)
|
||||
self.count = count
|
||||
|
||||
def __getitem__(self, index):
|
||||
if isinstance(index, slice):
|
||||
return FakeTensorBatch(
|
||||
width=self.shape[2],
|
||||
height=self.shape[1],
|
||||
count=len(range(*index.indices(self.count))),
|
||||
)
|
||||
if index != 0:
|
||||
raise IndexError(index)
|
||||
return self.image
|
||||
@@ -36,8 +44,11 @@ class FakeTensorBatch:
|
||||
class FakePILImage:
|
||||
saved_paths = []
|
||||
|
||||
def save(self, path, compress_level=0):
|
||||
self.saved_paths.append((path, compress_level))
|
||||
def save(self, path, *args, **kwargs):
|
||||
self.saved_paths.append((path, args, kwargs))
|
||||
|
||||
def convert(self, _mode):
|
||||
return self
|
||||
|
||||
|
||||
class DumasImageNodeTests(unittest.TestCase):
|
||||
@@ -52,6 +63,7 @@ class DumasImageNodeTests(unittest.TestCase):
|
||||
fake_pil_module = types.SimpleNamespace(Image=fake_pil_image_module)
|
||||
fake_folder_paths = types.SimpleNamespace(
|
||||
get_temp_directory=lambda: cls.temp_dir,
|
||||
get_output_directory=lambda: cls.temp_dir,
|
||||
get_save_image_path=lambda prefix, _out, _width, _height: (
|
||||
cls.temp_dir,
|
||||
prefix,
|
||||
@@ -119,6 +131,59 @@ class DumasImageNodeTests(unittest.TestCase):
|
||||
self.assertTrue(result["ui"]["images"][0]["filename"].startswith("dumas_compare"))
|
||||
self.assertTrue(os.path.basename(FakePILImage.saved_paths[0][0]).startswith("dumas_compare"))
|
||||
|
||||
def test_save_image_uses_second_input_token(self):
|
||||
node = self.image_nodes.DumasSaveImageNode()
|
||||
image = FakeTensorBatch(width=10, height=12)
|
||||
|
||||
node.save_images(
|
||||
images=image,
|
||||
folder=self.temp_dir,
|
||||
pattern="shot_%input%_%input2%_%counter%",
|
||||
format="png",
|
||||
quality=100,
|
||||
embed_workflow=False,
|
||||
save_on_run=True,
|
||||
name="alpha.png",
|
||||
name_2="beta/final",
|
||||
)
|
||||
|
||||
saved_name = os.path.basename(FakePILImage.saved_paths[0][0])
|
||||
self.assertEqual(saved_name, "shot_alpha_beta_final_001.png")
|
||||
|
||||
def test_save_image_returns_ui_entries_for_output_folder(self):
|
||||
node = self.image_nodes.DumasSaveImageNode()
|
||||
image = FakeTensorBatch()
|
||||
|
||||
result = node.save_images(
|
||||
images=image,
|
||||
folder="",
|
||||
pattern="result_%counter%",
|
||||
format="jpg",
|
||||
quality=90,
|
||||
embed_workflow=False,
|
||||
save_on_run=True,
|
||||
)
|
||||
|
||||
self.assertEqual(result["ui"]["images"][0]["type"], "output")
|
||||
self.assertTrue(result["ui"]["images"][0]["filename"].endswith(".jpg"))
|
||||
|
||||
def test_save_image_skips_when_save_is_disabled(self):
|
||||
node = self.image_nodes.DumasSaveImageNode()
|
||||
image = FakeTensorBatch()
|
||||
|
||||
result = node.save_images(
|
||||
images=image,
|
||||
folder=self.temp_dir,
|
||||
pattern="ignored_%counter%",
|
||||
format="png",
|
||||
quality=100,
|
||||
embed_workflow=False,
|
||||
save_on_run=False,
|
||||
)
|
||||
|
||||
self.assertEqual(result["ui"]["images"], [])
|
||||
self.assertEqual(FakePILImage.saved_paths, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user