Go to the documentation of this file.00001 import argparse
00002 import inspect
00003 from zipfile_interface import get_test_cases
00004 from ros_introspection.package import Package
00005 from roscompile import get_functions
00006 import os.path
00007
00008
00009 def compare(pkg_in, pkg_out, debug=True):
00010 matches, missed_deletes, missed_generations = pkg_in.compare_filesets(pkg_out)
00011
00012 success = True
00013
00014 for fn in missed_deletes:
00015 if debug:
00016 print('Should have deleted %s' % fn)
00017 success = False
00018 for fn in missed_generations:
00019 if debug:
00020 print('Failed to generate %s' % fn)
00021 success = False
00022 for filename in matches:
00023 generated_contents = pkg_in.get_contents(filename)
00024 canonical_contents = pkg_out.get_contents(filename)
00025 if generated_contents.strip() == canonical_contents.strip():
00026 continue
00027 success = False
00028 if debug:
00029 A = generated_contents.split('\n')
00030 B = canonical_contents.split('\n')
00031 while len(A) < len(B):
00032 A.append(None)
00033 while len(B) < len(A):
00034 B.append(None)
00035 for a, b in zip(A, B):
00036 print(a == b, repr(a), repr(b))
00037 return success
00038
00039
00040 if __name__ == '__main__':
00041 parser = argparse.ArgumentParser()
00042 parser.add_argument('zipfile')
00043 parser.add_argument('-f', '--fail_once', action='store_true')
00044 parser.add_argument('-l', '--last', action='store_true')
00045 args = parser.parse_args()
00046 config, cases = get_test_cases(args.zipfile)
00047 roscompile_functions = get_functions()
00048 successes = 0
00049 total = 0
00050
00051 for test_config in config:
00052 if args.last and test_config != config[-1]:
00053 continue
00054
00055 with cases[test_config['in']] as pkg_in:
00056 try:
00057 total += 1
00058 if test_config['in'] == test_config['out']:
00059 pkg_out = pkg_in.copy()
00060 else:
00061 pkg_out = cases[test_config['out']]
00062
00063 print('{:25} >> {:25} {}'.format(test_config['in'], test_config['out'],
00064 ','.join(test_config['functions'])))
00065 root = pkg_in.root
00066 if 'subpkg' in test_config:
00067 root = os.path.join(root, test_config['subpkg'])
00068 pp = Package(root)
00069 local_config = test_config.get('config', {})
00070 for function_name in test_config['functions']:
00071 fne = roscompile_functions[function_name]
00072 if 'config' in inspect.getargspec(fne).args:
00073 fne(pp, config=local_config)
00074 else:
00075 fne(pp)
00076 pp.write()
00077 if compare(pkg_in, pkg_out):
00078 print(' SUCCESS')
00079 successes += 1
00080 else:
00081 print(' FAIL')
00082 if args.fail_once:
00083 break
00084 except Exception as e:
00085 print(' EXCEPTION', e.message)
00086 if args.last:
00087 raise
00088 if args.fail_once:
00089 break
00090 if not args.last:
00091 print('{}/{}'.format(successes, total))