manual_test.py
Go to the documentation of this file.
1 import argparse
2 import inspect
3 from zipfile_interface import get_test_cases
4 from ros_introspection.package import Package
5 from roscompile import get_functions
6 import os.path
7 
8 
9 def compare(pkg_in, pkg_out, debug=True):
10  matches, missed_deletes, missed_generations = pkg_in.compare_filesets(pkg_out)
11 
12  success = True
13 
14  for fn in missed_deletes:
15  if debug:
16  print('Should have deleted %s' % fn)
17  success = False
18  for fn in missed_generations:
19  if debug:
20  print('Failed to generate %s' % fn)
21  success = False
22  for filename in matches:
23  generated_contents = pkg_in.get_contents(filename)
24  canonical_contents = pkg_out.get_contents(filename)
25  if generated_contents.strip() == canonical_contents.strip():
26  continue
27  success = False
28  if debug:
29  A = generated_contents.split('\n')
30  B = canonical_contents.split('\n')
31  while len(A) < len(B):
32  A.append(None)
33  while len(B) < len(A):
34  B.append(None)
35  for a, b in zip(A, B):
36  print(a == b, repr(a), repr(b))
37  return success
38 
39 
40 if __name__ == '__main__':
41  parser = argparse.ArgumentParser()
42  parser.add_argument('zipfile')
43  parser.add_argument('-f', '--fail_once', action='store_true')
44  parser.add_argument('-l', '--last', action='store_true')
45  args = parser.parse_args()
46  config, cases = get_test_cases(args.zipfile)
47  roscompile_functions = get_functions()
48  successes = 0
49  total = 0
50 
51  for test_config in config:
52  if args.last and test_config != config[-1]:
53  continue
54 
55  with cases[test_config['in']] as pkg_in:
56  try:
57  total += 1
58  if test_config['in'] == test_config['out']:
59  pkg_out = pkg_in.copy()
60  else:
61  pkg_out = cases[test_config['out']]
62 
63  print('{:25} >> {:25} {}'.format(test_config['in'], test_config['out'],
64  ','.join(test_config['functions'])))
65  root = pkg_in.root
66  if 'subpkg' in test_config:
67  root = os.path.join(root, test_config['subpkg'])
68  pp = Package(root)
69  local_config = test_config.get('config', {})
70  for function_name in test_config['functions']:
71  fne = roscompile_functions[function_name]
72  if 'config' in inspect.getargspec(fne).args:
73  fne(pp, config=local_config)
74  else:
75  fne(pp)
76  pp.write()
77  if compare(pkg_in, pkg_out):
78  print(' SUCCESS')
79  successes += 1
80  else:
81  print(' FAIL')
82  if args.fail_once:
83  break
84  except Exception as e:
85  print(' EXCEPTION', e.message)
86  if args.last:
87  raise
88  if args.fail_once:
89  break
90  if not args.last:
91  print('{}/{}'.format(successes, total))
def compare(pkg_in, pkg_out, debug=True)
Definition: manual_test.py:9
def get_test_cases(zip_filename)


roscompile
Author(s):
autogenerated on Wed Jun 19 2019 19:56:53