comparison tests/conftest.py @ 398:af17c143b9ab

tests: Fail bake tests with a proper error message when bake fails.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 18 May 2015 19:28:47 -0700
parents 879b6b5647a8
children a0724af26c12
comparison
equal deleted inserted replaced
397:879b6b5647a8 398:af17c143b9ab
144 from piecrust.baking.baker import Baker 144 from piecrust.baking.baker import Baker
145 with mock_fs_scope(fs): 145 with mock_fs_scope(fs):
146 out_dir = fs.path('kitchen/_counter') 146 out_dir = fs.path('kitchen/_counter')
147 app = fs.getApp() 147 app = fs.getApp()
148 baker = Baker(app, out_dir) 148 baker = Baker(app, out_dir)
149 baker.bake() 149 record = baker.bake()
150
151 if not record.success:
152 errors = []
153 for e in record.entries:
154 errors += e.getAllErrors()
155 raise BakeError(errors)
150 156
151 if expected_output_files: 157 if expected_output_files:
152 actual = fs.getStructure('kitchen/_counter') 158 actual = fs.getStructure('kitchen/_counter')
153 error = _compare_dicts(expected_output_files, actual) 159 error = _compare_dicts(expected_output_files, actual)
154 if error: 160 if error:
180 if isinstance(excinfo.value, ExpectedBakeOutputError): 186 if isinstance(excinfo.value, ExpectedBakeOutputError):
181 return ('\n'.join( 187 return ('\n'.join(
182 ['Unexpected bake output. Left is expected output, ' 188 ['Unexpected bake output. Left is expected output, '
183 'right is actual output'] + 189 'right is actual output'] +
184 excinfo.value.args[0])) 190 excinfo.value.args[0]))
191 elif isinstance(excinfo.value, BakeError):
192 return ('\n'.join(
193 ['Errors occured during bake:'] +
194 excinfo.value.args[0]))
185 return super(BakeTestItem, self).repr_failure(excinfo) 195 return super(BakeTestItem, self).repr_failure(excinfo)
196
197
198 class BakeError(Exception):
199 pass
186 200
187 201
188 class ExpectedBakeOutputError(Exception): 202 class ExpectedBakeOutputError(Exception):
189 pass 203 pass
190 204