33
44import pytest
55
6- import comfy_script .transpile as transpile
6+ from comfy_script .transpile import *
77
88@pytest .mark .parametrize ('workflow, script' , [
99 ('default.json' ,
6868""" )
6969])
7070def test_workflow (workflow , script ):
71+ format = FormatOptions (args = ArgsFormat .Pos )
7172 with open (Path (__file__ ).parent / workflow ) as f :
72- assert transpile .WorkflowToScriptTranspiler (f .read ()).to_script () == script
73+ assert WorkflowToScriptTranspiler (f .read ()).to_script (format = format ) == script
74+
75+ @pytest .mark .parametrize ('workflow, script' , [
76+ ('default.json' ,
77+ r"""model, clip, vae = CheckpointLoaderSimple(ckpt_name='v1-5-pruned-emaonly.ckpt')
78+ conditioning = CLIPTextEncode(text='beautiful scenery nature glass bottle landscape, , purple galaxy bottle,', clip=clip)
79+ conditioning2 = CLIPTextEncode(text='text, watermark', clip=clip)
80+ latent = EmptyLatentImage(width=512, height=512, batch_size=1)
81+ latent = KSampler(model=model, seed=156680208700286, steps=20, cfg=8, sampler_name='euler', scheduler='normal', positive=conditioning, negative=conditioning2, latent_image=latent, denoise=1)
82+ image = VAEDecode(samples=latent, vae=vae)
83+ SaveImage(images=image, filename_prefix='ComfyUI')
84+ """ ),
85+ ('bypass.json' ,
86+ r"""image, _ = LoadImage(image='ComfyUI_temp_rcuxh_00001_.png')
87+ image2 = ImageScaleToSide(image=image, side_length=1024, side='Longest', upscale_method='nearest-exact', crop='disabled')
88+ PreviewImage(images=image2)
89+ image3, _ = CRUpscaleImage(image=image2, upscale_model='8x_NMKD-Superscale_150000_G.pth', mode='rescale', rescale_factor=2, resize_width=1024, resampling_method='lanczos', supersample='true', rounding_modulus=8)
90+ segs = ImpactMakeTileSEGS(image=image3, bbox_size=600, crop_factor=1.5, min_overlap=200, max_overlap=100, sub_batch_size_for_dilation=0, filter_segs_dilation='Reuse fast', mask_irregularity=None, irregular_mask_mode=None)
91+ # _ = SEGSPreview(segs=segs, alpha_mode=True, falloff=0.1, image=image3)
92+ image4 = image3
93+ PreviewImage(images=image4)
94+ segs2 = segs
95+ model, clip, vae = CheckpointLoaderSimple(ckpt_name=r'XL\turbovisionxlSuperFastXLBasedOnNew_alphaV0101Bakedvae.safetensors')
96+ lora_stack, _ = CRLoRAStack(switch_1='On', lora_name_1=r'xl\LCMTurboMix_LCM_Sampler.safetensors', model_weight_1=1, clip_weight_1=1, switch_2='On', lora_name_2=r'xl\xl_more_art-full_v1.safetensors', model_weight_2=1, clip_weight_2=1, switch_3='On', lora_name_3=r'xl\add-detail-xl.safetensors', model_weight_3=1, clip_weight_3=1, lora_stack=None)
97+ model, clip, _ = CRApplyLoRAStack(model=model, clip=clip, lora_stack=lora_stack)
98+ conditioning = CLIPTextEncode(text='Shot Size - extreme wide shot,( Marrakech market at night time:1.5), Moroccan young beautiful woman, smiling, exotic, (loose hijab:0.1)', clip=clip)
99+ conditioning2 = CLIPTextEncode(text='(worst quality, low quality, normal quality:2), blurry, depth of field, nsfw', clip=clip)
100+ basic_pipe = ToBasicPipe(model=model, clip=clip, vae=vae, positive=conditioning, negative=conditioning2)
101+ image5, _, _, _ = DetailerForEachPipe(image=image3, segs=segs2, guide_size=1024, guide_size_for=True, max_size=1024, seed=403808226377311, steps=10, cfg=3, sampler_name='lcm', scheduler='ddim_uniform', denoise=0.1, feather=50, noise_mask=True, force_inpaint=True, basic_pipe=basic_pipe, wildcard='', cycle=0, inpaint_model=1, noise_mask_feather=None, scheduler_func_opt=None, detailer_hook=True, refiner_ratio=50)
102+ PreviewImage(images=image5)
103+ PreviewImage(images=image)
104+ """ ),
105+ ('rgthree-comfy.json' ,
106+ r"""model, clip, vae = CheckpointLoaderSimple(ckpt_name='v1-5-pruned-emaonly.ckpt')
107+ # _ = CLIPTextEncode(text='n', clip=clip)
108+ conditioning = CLIPTextEncode(text='p', clip=clip)
109+ latent = EmptyLatentImage(width=512, height=512, batch_size=1)
110+ latent = KSampler(model=model, seed=0, steps=20, cfg=8, sampler_name='euler', scheduler='normal', positive=conditioning, negative=conditioning, latent_image=latent, denoise=1)
111+ image = VAEDecode(samples=latent, vae=vae)
112+ SaveImage(images=image, filename_prefix='ComfyUI')
113+ """ ),
114+ ('SplitSigmasDenoise.api.json' ,
115+ r"""noise = DisableNoise()
116+ width, height, _, _, _, empty_latent, _ = CRAspectRatio(width=512, height=768, aspect_ratio='custom', swap_dimensions='Off', upscale_factor=1, prescale_factor=1, batch_size=1)
117+ model = UNETLoader(unet_name='flux1-dev.safetensors', weight_dtype='fp8_e4m3fn')
118+ model = LoraLoaderModelOnly(model=model, lora_name='a.safetensors', strength_model=0.7000000000000001)
119+ model = LoraLoaderModelOnly(model=model, lora_name='b.safetensors', strength_model=0.7000000000000001)
120+ model = ModelSamplingFlux(model=model, max_shift=1.1500000000000001, base_shift=0.5, width=width, height=height)
121+ clip = DualCLIPLoader(clip_name1='t5.safetensors', clip_name2='clip_l.safetensors', type='flux')
122+ conditioning = CLIPTextEncode(text='prompt text', clip=clip)
123+ conditioning = FluxGuidance(conditioning=conditioning, guidance=3.5)
124+ guider = BasicGuider(model=model, conditioning=conditioning)
125+ sampler = KSamplerSelect(sampler_name='deis')
126+ sigmas = BasicScheduler(model=model, scheduler='beta', steps=30, denoise=1)
127+ sigmas, low_sigmas = SplitSigmasDenoise(sigmas=sigmas, denoise=0.4)
128+ noise2 = RandomNoise(noise_seed=149684926930931)
129+ empty_latent, _ = SamplerCustomAdvanced(noise=noise2, guider=guider, sampler=sampler, sigmas=sigmas, latent_image=empty_latent)
130+ empty_latent = InjectLatentNoise(latent=empty_latent, noise_seed=49328841076664, noise_strength=0.3, normalize='true')
131+ empty_latent, _ = SamplerCustomAdvanced(noise=noise, guider=guider, sampler=sampler, sigmas=low_sigmas, latent_image=empty_latent)
132+ vae = VAELoader(vae_name='ae.safetensors')
133+ image = VAEDecode(samples=empty_latent, vae=vae)
134+ SaveImage(images=image, filename_prefix='ComfyUI')
135+ """ )
136+ ])
137+ def test_workflow_with_keyword_args (workflow , script ):
138+ format = FormatOptions (args = ArgsFormat .Kwd )
139+ with open (Path (__file__ ).parent / workflow ) as f :
140+ assert WorkflowToScriptTranspiler (f .read ()).to_script (format = format ) == script
0 commit comments