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 from roscompile.diff import prepare_diff_lines
7 import os.path
8 import click
9 
10 
11 def compare(pkg_in, pkg_out, debug=True):
12  matches, missed_deletes, missed_generations = pkg_in.compare_filesets(pkg_out)
13 
14  success = True
15 
16  for fn in missed_deletes:
17  if debug:
18  click.secho('Should have deleted %s' % fn, fg='yellow')
19  success = False
20  for fn in missed_generations:
21  if debug:
22  click.secho('Failed to generate %s' % fn, fg='yellow')
23  success = False
24  for filename in matches:
25  generated_contents = pkg_in.get_contents(filename).replace('\r\n', '\n')
26  canonical_contents = pkg_out.get_contents(filename).replace('\r\n', '\n')
27  if generated_contents.strip() == canonical_contents.strip():
28  continue
29  success = False
30  if debug:
31  for gen_line, can_line in prepare_diff_lines(generated_contents, canonical_contents):
32  if gen_line == can_line:
33  click.echo(repr(gen_line))
34  else:
35  click.secho(repr(gen_line) + ' should be ' + repr(can_line), fg='yellow')
36  return success
37 
38 
39 if __name__ == '__main__':
40  parser = argparse.ArgumentParser()
41  parser.add_argument('zipfile')
42  parser.add_argument('-f', '--fail_once', action='store_true')
43  parser.add_argument('-l', '--last', action='store_true')
44  args = parser.parse_args()
45  config, cases = get_test_cases(args.zipfile)
46  roscompile_functions = get_functions()
47  successes = 0
48  total = 0
49 
50  for test_config in config:
51  if args.last and test_config != config[-1]:
52  continue
53 
54  with cases[test_config['in']] as pkg_in:
55  try:
56  total += 1
57  if test_config['in'] == test_config['out']:
58  pkg_out = pkg_in.copy()
59  else:
60  pkg_out = cases[test_config['out']]
61 
62  click.secho('{:25} >> {:25} {}'.format(test_config['in'], test_config['out'],
63  ','.join(test_config['functions'])),
64  bold=True, fg='white')
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  click.secho(' SUCCESS', fg='green')
79  successes += 1
80  else:
81  click.secho(' FAIL', fg='red')
82  if args.fail_once:
83  break
84  except Exception as e:
85  click.secho(' EXCEPTION ' + str(e), fg='red')
86  if args.last:
87  raise
88  if args.fail_once:
89  break
90  if not args.last:
91  click.secho('{}/{}'.format(successes, total), bold=True, fg='white')
def prepare_diff_lines(string_a, string_b)
Definition: diff.py:97
def compare(pkg_in, pkg_out, debug=True)
Definition: manual_test.py:11
def get_test_cases(zip_filename)


roscompile
Author(s):
autogenerated on Wed Mar 3 2021 03:56:01