Mercurial > piecrust2
comparison tests/conftest.py @ 559:b95977d97652
tests: Print more information when a bake test fails to find an output file.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 14 Aug 2015 22:43:39 -0700 |
parents | cc6f3dbe3048 |
children | a65f04ddbea2 |
comparison
equal
deleted
inserted
replaced
558:9ab005db2592 | 559:b95977d97652 |
---|---|
97 for key in keys: | 97 for key in keys: |
98 try: | 98 try: |
99 actual = fs.getFileEntry('kitchen/_counter/' + | 99 actual = fs.getFileEntry('kitchen/_counter/' + |
100 key.lstrip('/')) | 100 key.lstrip('/')) |
101 except Exception as e: | 101 except Exception as e: |
102 lines = print_fs_tree(fs.path('kitchen/_counter')) | |
102 raise error_type([ | 103 raise error_type([ |
103 "Can't access output file %s: %s" % (key, e)]) | 104 "Can't access output file %s: %s" % (key, e), |
105 "Got output directory:"] + | |
106 lines) | |
104 | 107 |
105 expected = expected_partial_files[key] | 108 expected = expected_partial_files[key] |
106 # HACK because for some reason PyYAML adds a new line for | 109 # HACK because for some reason PyYAML adds a new line for |
107 # those and I have no idea why. | 110 # those and I have no idea why. |
108 actual = actual.rstrip('\n') | 111 actual = actual.rstrip('\n') |
109 expected = expected.rstrip('\n') | 112 expected = expected.rstrip('\n') |
110 cctx.path = key | 113 cctx.path = key |
111 cmpres = _compare_str(expected, actual, cctx) | 114 cmpres = _compare_str(expected, actual, cctx) |
112 if cmpres: | 115 if cmpres: |
113 raise error_type(cmpres) | 116 raise error_type(cmpres) |
117 | |
118 | |
119 def print_fs_tree(rootpath): | |
120 import os | |
121 import os.path | |
122 lines = [] | |
123 offset = len(rootpath) | |
124 for pathname, dirnames, filenames in os.walk(rootpath): | |
125 level = pathname[offset:].count(os.sep) | |
126 indent = ' ' * 4 * (level) | |
127 lines.append(indent + os.path.basename(pathname) + '/') | |
128 indent2 = ' ' * 4 * (level + 1) | |
129 for f in filenames: | |
130 lines.append(indent2 + f) | |
131 return lines | |
114 | 132 |
115 | 133 |
116 class ChefTestItem(YamlTestItemBase): | 134 class ChefTestItem(YamlTestItemBase): |
117 __initialized_logging__ = False | 135 __initialized_logging__ = False |
118 | 136 |