from ppp import PromptPostProcessor # pylint: disable=import-error from .base_tests import PromptPair, TestPromptPostProcessorBase if __name__ == "__main__": raise SystemExit("This script must not be run directly") class TestCommands(TestPromptPostProcessorBase): def setUp(self): # pylint: disable=arguments-differ super().setUp(enable_file_logging=False) # Command tests def test_cmd_stn_complex_features(self): # complex stn command with AND, BREAK and other features self.process( PromptPair( "[neg5] this \\(is\\): a (([complex|simpleneg6|regular] testneg1)(test:2.0):1.5) \nBREAK, BREAK with [abcneg4:defneg2(neg3:1.6):5]:0.5 AND loratrigger AND AND hypernettrigger :0.3", "normal quality, ", ), PromptPair( "this \\(is\\): a (([complex|simple|regular] test)(test:2):1.5)\nBREAK with [abc:def:5]:0.5 AND loratrigger AND hypernettrigger :0.3", "[neg5], ([|neg6|]:1.65), (neg1:1.65), [neg4::5], normal quality, [neg2(neg3:1.6):5]", ), ) def test_cmd_if_complex_features(self): # complex if command self.process( PromptPair( "this \\(is\\): a (([complex|simple|regular] test)(test:2.0):1.5) \nBREAK, BREAK with [abcneg4:def:5]:0.5 AND loratrigger hypernettrigger nothing:0.3", "normal quality", ), PromptPair( "this \\(is\\): a (([complex|simple|regular] test)(test:2):1.5)\nBREAK :0.5 AND hypernettrigger :0.3", "normal quality", ), ) def test_cmd_if_nested(self): # nested if command self.process( PromptPair( "this is SD1PONYSD2NOPONYNOPONY", "", ), PromptPair("this is PONY", ""), ppp=PromptPostProcessor( self.ppp_logger, self.interrupt, { **self.def_env_info, "model_filename": "./webui/models/Stable-diffusion/ponymodel.safetensors", }, self.defopts, self.grammar_content, self.wildcards_obj, self.extranetwork_maps_obj, ), ) def test_cmd_set_if(self): # set and if commands self.process( PromptPair("valuethis test is OKnot OK", ""), PromptPair("this test is OK", ""), ) def test_cmd_set_empty(self): # set to empty self.process( PromptPair("${v2=}this test is not OKOK", ""), PromptPair("this test is OK", ""), ) def test_cmd_set_eval_if(self): # set and if commands self.process( PromptPair("valuethis test is OKnot OK", ""), PromptPair("this test is OK", ""), ) def test_cmd_set_if_echo_nested(self): # nested set, if and echo commands self.process( PromptPair( "1OKnot OK NOK OK", "", ), PromptPair("OK OK OK", ""), ) def test_cmd_set_if_complex_conditions_1(self): # complex conditions (or) self.process( PromptPair( "truefalsethis test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_2(self): # complex conditions (and) self.process( PromptPair( "truetruethis test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_3(self): # complex conditions (not) self.process( PromptPair("falsethis test is OKnot OK", ""), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_4(self): # complex conditions (not, precedence) self.process( PromptPair( "truefalsethis test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_5(self): # complex conditions (not, precedence, comparison) self.process( PromptPair( "1falsethis test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_6(self): # complex conditions self.process( PromptPair( "123this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if_complex_conditions_7(self): # complex conditions self.process( PromptPair( "123this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_if2(self): # set and more complex if commands self.process( PromptPair( "First: value1this test is OKOK2not OK\nSecond: value3this test is OKnot OK", "", ), PromptPair("First: this test is OK\nSecond: this test is OK", ""), ) def test_cmd_set_add_if(self): # set, add and if commands self.process( PromptPair( "value2this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_add_DP_if(self): # set, add (DP format) and if commands self.process( PromptPair( "${v=value}${v+=2}this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_immediateeval(self): # set (DP format) with mixed evaluation self.process( PromptPair( "${var=!__yaml/wildcard1__}the choices are: ${var}, ${var}, ${var2:default}, ${var3=__yaml/wildcard1__}${var3}, ${var3}", "", ), PromptPair("the choices are: choice2, choice2, default, choice3, choice1", ""), ppp="nocup", ) def test_cmd_set_mixeval(self): # set and add (DP format) with mixed evaluation self.process( PromptPair( "${var=__yaml/wildcard1__}the choices are: ${var}, ${var}, ${var+=, __yaml/wildcard2__}${var}, ${var}, ${var+=!, __yaml/wildcard3__}${var}, ${var}", "", ), PromptPair( "the choices are: choice2, choice3, choice1, choice1- choice2 -choice3, choice2, choice2 -choice1-choice3, choice2, choice3-choice1- choice2 , choice1, choice2 , choice2, choice3-choice1- choice2 , choice1, choice2 ", "", ), ppp="nocup", ) def test_cmd_set_ifundefined_if(self): # set, ifundefined and if commands self.process( PromptPair( "valuethis test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_ifundefined_if_2(self): # set, ifundefined and if commands self.process( PromptPair( "valuevalue2this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_ifundefined_DP_if(self): # set, ifundefined (DP format) and if commands self.process( PromptPair( "${v?=value}this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_set_ifundefined_DP_if_2(self): # set, ifundefined (DP format) and if commands self.process( PromptPair( "${v=!value}${v?=!value2}this test is OKnot OK", "", ), PromptPair("this test is OK", ""), ) def test_cmd_ext(self): # ext self.process( PromptPair( "trigger1trigger2trigger4trigger5", "", ), PromptPair( "trigger1,trigger2,trigger4,trigger5", "", ), ) def test_cmd_ext_map_notrigger(self): # ext mapping, no trigger self.process( PromptPair( "", "", ), PromptPair("triggergeneric1, triggergeneric2, two, triggergeneric1, triggergeneric2, two", ""), ) def test_cmd_ext_map1(self): # ext mapping, no lora self.process( PromptPair( "inlinetrigger", "", ), PromptPair("inlinetrigger, triggergeneric1, triggergeneric2, two", ""), ) def test_cmd_ext_map2(self): # ext mapping, lora with weight self.process( PromptPair( "inlinetrigger", "", ), PromptPair("inlinetrigger, triggerpony1, triggerpony2", ""), ppp=PromptPostProcessor( self.ppp_logger, self.interrupt, { **self.def_env_info, "model_filename": "./webui/models/Stable-diffusion/ponymodel.safetensors", }, self.defopts, self.grammar_content, self.wildcards_obj, self.extranetwork_maps_obj, ), ) def test_cmd_ext_map3(self): # ext mapping, lora with weight adjusted self.process( PromptPair( "inlinetrigger", "", ), PromptPair("inlinetrigger, triggerpony1, triggerpony2", ""), ppp=PromptPostProcessor( self.ppp_logger, self.interrupt, { **self.def_env_info, "model_filename": "./webui/models/Stable-diffusion/ponymodel.safetensors", }, self.defopts, self.grammar_content, self.wildcards_obj, self.extranetwork_maps_obj, ), ) def test_cmd_ext_map4(self): # ext mapping, lora with parameters self.process( PromptPair( "inlinetrigger", "", ), PromptPair("inlinetrigger, triggerpony1, triggerpony2", ""), ppp=PromptPostProcessor( self.ppp_logger, self.interrupt, { **self.def_env_info, "model_filename": "./webui/models/Stable-diffusion/ponymodel.safetensors", }, self.defopts, self.grammar_content, self.wildcards_obj, self.extranetwork_maps_obj, ), ) def test_cmd_ext_map5(self): # ext mapping, lora with no parameters self.process( PromptPair( "inlinetrigger", "", ), PromptPair("inlinetrigger, triggerillustrious1, triggerillustrious2", ""), ppp=PromptPostProcessor( self.ppp_logger, self.interrupt, { **self.def_env_info, "model_filename": "./webui/models/Stable-diffusion/ilxlmodel.safetensors", }, self.defopts, self.grammar_content, self.wildcards_obj, self.extranetwork_maps_obj, ), )