@@ -25,7 +25,10 @@ def split(s):
2525parser .add_argument ('--publish' , action = 'store_true' , help = 'publish the crates' )
2626parser .add_argument ('--build' , action = 'store_true' , help = 'build the crates' )
2727parser .add_argument ('--test' , action = 'store_true' , help = 'test the crates' )
28- parser .add_argument ('--test_outputs' , action = 'store_true' , help = 'run the unittests' )
28+ parser .add_argument ('--make_golden_outputs' , action = 'store_true' , help = 'make the golden outputs' )
29+ parser .add_argument ('--test_outputs' , action = 'store_true' , help = 'run the output tests' )
30+ parser .add_argument ('--ignore_new_outputs' , action = 'store_true' , help = 'whether to ignore new outputs' )
31+ parser .add_argument ('--changed_outputs' , type = str , default = '' , help = 'comma separated list of outputs to ignore failures in, e.g. "foo.png,bar.png"' )
2932parser .add_argument ('--clean' , action = 'store_true' , help = 'clean the crates' )
3033parser .add_argument ('--doc' , action = 'store_true' , help = 'build the documentation' )
3134parser .add_argument ('--format' , action = 'store_true' , help = 'format all the non-sys crates' )
@@ -95,12 +98,16 @@ def cargo_cmd(*command):
9598 check_call (cargo_cmd ('test' ), cwd = crate )
9699 check_call (cargo_cmd ('fmt' , '--check' ), cwd = crate )
97100
98- if args .test_outputs :
101+ if args .test_outputs or args . make_golden_outputs :
99102 import numpy as np
100103 from PIL import Image
101104
102- os .makedirs ('test_outputs' , exist_ok = True )
103- output_dir = os .path .abspath ('test_outputs' )
105+ if args .test_outputs :
106+ output_dir = 'test_outputs'
107+ else :
108+ output_dir = 'golden_outputs'
109+ os .makedirs (output_dir , exist_ok = True )
110+ output_dir = os .path .abspath (output_dir )
104111 metadata = json .loads (check_output (cargo_cmd ('metadata' , '--format-version=1' , '--no-deps' ), cwd = 'gnuplot' ).decode ('utf8' ))
105112 for target in metadata ['packages' ][0 ]['targets' ]:
106113 if target ['kind' ] != ['example' ]:
@@ -115,6 +122,9 @@ def cargo_cmd(*command):
115122
116123 check_call (cargo_cmd ('run' , '--example' , target ['name' ], '--' , '--no-show' , '--output-dir' , output_dir , '--save-png' ), cwd = 'gnuplot' )
117124
125+ if args .make_golden_outputs :
126+ exit (0 )
127+
118128 golden_images = [pathlib .Path (f ) for f in glob .glob ('golden_outputs/*.png' )]
119129 test_images = [pathlib .Path (f ) for f in glob .glob (f'{ output_dir } /*.png' )]
120130
@@ -123,19 +133,26 @@ def cargo_cmd(*command):
123133 if golden_filenames != test_filenames :
124134 missing = set (golden_filenames ) - set (test_filenames )
125135 extra = set (test_filenames ) - set (golden_filenames )
126- assert False , f"Test images don't match golden images.\n Extra: { extra } \n Missing: { missing } "
136+ if not args .ignore_new_outputs or missing :
137+ assert False , f"Test images don't match golden images.\n Extra: { extra } \n Missing: { missing } "
127138
139+ changed_outputs = args .changed_outputs .split (',' )
140+ failed = False
128141 for image_name in golden_images :
129142 golden_image_path = pathlib .Path (image_name )
130143 test_image_path = pathlib .Path (output_dir ) / golden_image_path .name
131144 assert test_image_path .exists (), f"{ test_image_path } not found"
132-
145+ if golden_image_path .name in changed_outputs :
146+ continue
133147 golden_image = np .array (Image .open (golden_image_path )).astype (np .float32 )
134148 test_image = np .array (Image .open (test_image_path )).astype (np .float32 )
135149 try :
136150 np .testing .assert_allclose (golden_image , test_image , atol = 5 , err_msg = f"{ golden_image_path .resolve ()} \n { test_image_path .resolve ()} " )
137151 except AssertionError as e :
152+ failed = True
138153 print (e )
154+ if failed :
155+ exit (1 )
139156
140157
141158if args .clean :
0 commit comments