From 3b98bfd4023b0cdd853013a3d52a052551ecdbb8 Mon Sep 17 00:00:00 2001 From: "borenet@google.com" Date: Mon, 17 Dec 2012 17:21:04 +0000 Subject: Address comments for r6822: https://codereview.appspot.com/6946052/ Review URL: https://codereview.appspot.com/6943059 git-svn-id: http://skia.googlecode.com/svn/trunk@6847 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tools/tests/bench_pictures_cfg_test.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'tools/tests/bench_pictures_cfg_test.py') diff --git a/tools/tests/bench_pictures_cfg_test.py b/tools/tests/bench_pictures_cfg_test.py index 1913e4208c..77ad553b28 100644 --- a/tools/tests/bench_pictures_cfg_test.py +++ b/tools/tests/bench_pictures_cfg_test.py @@ -12,25 +12,35 @@ import os import sys +def ThrowIfNotAString(obj): + """ Raise a TypeError if obj is not a string. """ + if str(obj) != obj: + raise TypeError('%s is not a string!' % str(obj)) + + def Main(argv): + """ Verify that the bench_pictures.cfg file is sane. + + - Exec the file to ensure that it uses correct Python syntax. + - Make sure that every element is a string, because the buildbot scripts will + fail to execute if this is not the case. + + This test does not verify that the well-formed configs are actually valid. + """ vars = {'import_path': 'tools'} execfile(os.path.join('tools', 'bench_pictures.cfg'), vars) bench_pictures_cfg = vars['bench_pictures_cfg'] for config_name, config_list in bench_pictures_cfg.iteritems(): - if str(config_name) != config_name: - raise TypeError('%s is not a string!' % str(config_name)) + ThrowIfNotAString(config_name) for config in config_list: for key, value in config.iteritems(): - if str(key) != key: - raise TypeError('%s is not a string!\n%s' % (str(key), config)) + ThrowIfNotAString(key) if type(value).__name__ == 'list': for item in value: - if str(item) != item: - raise TypeError('%s is not a string!\n%s' % (str(item), config)) + ThrowIfNotAString(item) else: - if str(value) != value: - raise TypeError('%s is not a string!\n%s' % (str(value), config)) + ThrowIfNotAString(value) if __name__ == '__main__': sys.exit(Main(sys.argv)) \ No newline at end of file -- cgit v1.2.3