Add editable reference image preprocessor node
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import importlib.util
|
||||
import pathlib
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = pathlib.Path(__file__).parents[1]
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"dumas_reference_image_preprocessor_test",
|
||||
ROOT / "dumas_reference_image_preprocessor.py",
|
||||
)
|
||||
MODULE = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
class ReferenceImagePreprocessorTests(unittest.TestCase):
|
||||
def test_all_reference_types_use_the_selected_token(self):
|
||||
for reference_type in MODULE.REFERENCE_TYPES:
|
||||
prompt = MODULE.build_reference_prompt(reference_type, "3", "blue details")
|
||||
self.assertIn("@R3", prompt)
|
||||
self.assertIn("Additional information about the", prompt)
|
||||
self.assertIn('"blue details"', prompt)
|
||||
|
||||
def test_invalid_reference_id_is_rejected(self):
|
||||
with self.assertRaises(ValueError):
|
||||
MODULE.build_reference_prompt("Character", "10")
|
||||
|
||||
def test_empty_description_is_not_appended(self):
|
||||
prompt = MODULE.build_reference_prompt("Scene", 1)
|
||||
self.assertNotIn("Additional information", prompt)
|
||||
|
||||
def test_node_preserves_image_and_allows_manual_prompt(self):
|
||||
image = object()
|
||||
node = MODULE.DumasReferenceImagePreprocessor()
|
||||
result = node.process(image, "Vehicle", "9", "red van", "my edited prompt")
|
||||
self.assertIs(result[0], image)
|
||||
self.assertEqual(result[1], "my edited prompt")
|
||||
|
||||
def test_node_generates_prompt_when_widget_is_empty(self):
|
||||
node = MODULE.DumasReferenceImagePreprocessor()
|
||||
result = node.process(object(), "Object", "2", "wooden handle", "")
|
||||
self.assertIn("@R2", result[1])
|
||||
self.assertIn("wooden handle", result[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user