def test_all_correct_contents(self):
"""Tests that the content of all non-static output files is expected."""
for dirname, _, filenames in os.walk(TTS_REFERENCE_PATH):
for filename in filenames:
if filename == caterpillar.SW_SCRIPT_NAME:
# Service worker is partly random, so test it elsewhere.
continue
reference_path = os.path.join(dirname, filename)
relpath = os.path.relpath(reference_path, TTS_REFERENCE_PATH)
if not (relpath.startswith(self.boilerplate_dir)
or relpath.startswith(self.report_dir)):
output_path = os.path.join(self.output_dir, relpath)
with open(reference_path) as reference_file:
with open(output_path) as output_file:
output_data = output_file.read().decode('utf-8')
reference_data = reference_file.read().decode('utf-8')
self.assertEqual(output_data, reference_data,
'Difference found in file `{}`.\n{}'.format(relpath,
'\n'.join(difflib.unified_diff(
output_data.split('\n'),
reference_data.split('\n'),
fromfile=reference_path,
tofile=output_path,
n=0))))
评论列表
文章目录