Files
ComfyAssets-ComfyUI_PromptM…/tests/test_focused_node.py
T
Vito d88cf9e7c6 fix(quality): sweep the Code Quality standard findings (#558)
* fix(quality): preserve cursor iteration and option validation

Keep prefetched rows on ManagedCursor so partial loops and explicit fetches share one position, and stop existing iterators after close or retirement. Preserve chunked reads and native SQLite result lifetime on reexecution and errors.

Catch OptionError before ValueError so legacy auto-tag requests receive the actual validation error. Remove the overwritten ViewerJS title option.

Regression tests failed before the fixes for lost rows, reads after close/retirement, and misleading option errors. Focused Python checks pass; cursor checks also pass on Python 3.13 and 3.14. Refs #321.

* fix(quality): make the test doubles legal raises and hashes

The fake queue no longer raises an attribute that starts as None. The
oversized kind records hashes instead of raising from __hash__, which
also catches a hash that production code swallows. Hostile.__bool__
raises the TypeError a truth test may raise.

* fix(quality): drop the extra saveCoverage argument

* refactor(quality): remove assignments that are overwritten before use

* refactor(quality): remove the remaining overwritten test assignments

* refactor(quality): drop imports repeated inside functions

* refactor(quality): give duplicate identity keys one shape

* refactor(quality): name the unused job event loop variable

* refactor(quality): release model gates in finally, not except BaseException

* refactor(quality): end the job runners with an explicit return

* refactor(quality): use the precise unittest asserts

* refactor(quality): import unittest.mock one way in the tests

* fix(quality): say why each empty except is safe, log the broad ones

* refactor(quality): stop binding values the tests never read

* refactor(quality): remove the unused preview aliases and tag page query

* refactor(quality): remove re-exports nothing imports

* refactor(quality): parenthesize deliberate string joins in lists

* refactor(quality): remove unused JavaScript variables and imports

* refactor(quality): use the precise assert in the model status test
2026-10-31 05:43:48 +00:00

62 lines
2.7 KiB
Python

"""Focused shares encoding and tracking while exposing composition sockets."""
import logging
import unittest
import unittest.mock as mock
from prompt_manager import PromptManager, PromptManagerFocused
from utils.prompt_graph import positive_prompt_nodes, run_prompt_nodes
class TestFocusedNode(unittest.TestCase):
def test_focused_keeps_the_execution_contract_and_visible_string_inputs(self):
self.assertTrue(issubclass(PromptManagerFocused, PromptManager))
self.assertEqual(PromptManagerFocused.RETURN_TYPES, PromptManager.RETURN_TYPES)
self.assertEqual(PromptManagerFocused.FUNCTION, PromptManager.FUNCTION)
focused = PromptManagerFocused.INPUT_TYPES()
for name in ("prepend_text", "append_text"):
self.assertTrue(focused["optional"][name][1]["forceInput"])
self.assertNotIn(
"forceInput", PromptManager.INPUT_TYPES()["optional"][name][1]
)
self.assertEqual(focused["hidden"]["unique_id"], "UNIQUE_ID")
def test_focused_encodes_composition_and_tracks_main_text_and_graph(self):
node = PromptManagerFocused.__new__(PromptManagerFocused)
node.logger = logging.getLogger("test.focused")
node.comfyui_integration = mock.Mock()
node._inject_lora_trigger_words = lambda text: text
node._track_prompt_execution = mock.Mock(return_value=42)
clip = mock.Mock()
graph = {"1": {"class_type": "PromptManagerFocused", "inputs": {"text": "cat"}}}
conditioning, text = node.encode_prompt(
clip,
"cat",
prepend_text="trigger",
append_text="detailed",
prompt=graph,
unique_id="1",
)
self.assertEqual(text, "trigger cat detailed")
clip.tokenize.assert_called_once_with(text)
self.assertIs(conditioning, clip.encode_from_tokens_scheduled.return_value)
tracked = node._track_prompt_execution.call_args.kwargs
self.assertEqual(tracked["text"], "cat")
self.assertEqual(tracked["prompt_graph"], graph)
def test_focused_is_traced_as_positive_and_not_as_the_negative_run(self):
graph = {
"1": {"class_type": "PromptManagerFocused", "inputs": {"text": "cat"}},
"2": {"class_type": "PromptManagerFocused", "inputs": {"text": "blur"}},
"3": {
"class_type": "KSampler",
"inputs": {
"model": ["4", 0],
"positive": ["1", 0],
"negative": ["2", 0],
},
},
}
self.assertEqual(positive_prompt_nodes(graph), ["1"])
self.assertEqual(run_prompt_nodes(graph), ["1"])