def _RunTest(self, template, expected, template_dict): src = cStringIO.StringIO(template) dst = cStringIO.StringIO() easy_template.RunTemplate(src, dst, template_dict) if dst.getvalue() != expected: expected_lines = expected.splitlines(1) actual_lines = dst.getvalue().splitlines(1) diff = ''.join(difflib.unified_diff( expected_lines, actual_lines, fromfile='expected', tofile='actual')) self.fail('Unexpected output:\n' + diff)
def RunTemplateFile(srcfile, dstfile, replace): dst = cStringIO.StringIO() with open(srcfile) as srcf: easy_template.RunTemplate(srcf, dst, replace) if os.path.exists(dstfile): with open(dstfile) as dstf: if dstf.read() == dst.getvalue(): Trace('Generated %s is the same. Skipping' % dstfile) return with open(dstfile, 'w') as dstf: dstf.write(dst.getvalue())