Mercurial > piecrust2
changeset 1142:952f3c24a99d
tests: Improve servings tests' error reporting.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 05 Jun 2018 21:58:53 -0700 |
parents | 5d9b2581b8a1 |
children | 1c324407bd1f |
files | tests/conftest.py |
diffstat | 1 files changed, 19 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/conftest.py Sun May 20 22:37:48 2018 -0700 +++ b/tests/conftest.py Tue Jun 05 21:58:53 2018 -0700 @@ -334,7 +334,7 @@ if isinstance(excinfo.value, UnexpectedBakeOutputError): return ('\n'.join( ['Unexpected bake output. Left is expected output, ' - 'right is actual output'] + + 'right is actual output.'] + excinfo.value.args[0])) elif isinstance(excinfo.value, BakeError): res = ('\n'.join( @@ -390,13 +390,19 @@ (expected_status, resp.status_code), resp) + cctx = CompareContext() + if expected_headers: for k, v in expected_headers.items(): - assert v == resp.headers.get(k) + cmpres = _compare_str(v, resp.headers.get(k), cctx) + if cmpres: + raise UnexpectedChefServingOutput(cmpres) actual = resp.data.decode('utf8').rstrip() if expected_output: - assert expected_output.rstrip() == actual + cmpres = _compare_str(expected_output.rstrip(), actual, cctx) + if cmpres: + raise UnexpectedChefServingOutput(cmpres) if expected_contains: assert expected_contains.rstrip() in actual @@ -424,6 +430,12 @@ res += '\nWhile requesting URL: %s' % excinfo.value.url res += '\nBody:\n%s' % excinfo.value.resp.data.decode('utf8') return res + elif isinstance(excinfo.value, UnexpectedChefServingOutput): + res = '\n'.join( + ["Unexpected serving output. Left is expected output, " + "right is actual output."] + + excinfo.value.args[0]) + return res return super(ServeTestItem, self).repr_failure(excinfo) @@ -434,6 +446,10 @@ self.resp = resp +class UnexpectedChefServingOutput(Exception): + pass + + class ServeTestFile(YamlTestFileBase): __item_class__ = ServeTestItem