utest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 import inspect
3 from catkin.find_in_workspaces import find_in_workspaces
4 from . import zipfile_interface
5 from ros_introspection.package import Package
6 from roscompile import get_functions
7 from roscompile.diff import prepare_diff_lines
8 import os.path
9 
10 FILE_ERROR_MESSAGE = 'These files should have been {} but weren\'t: {}'
11 
12 zipfile = find_in_workspaces(path='roscompile/test/test_data.zip', first_match_only=True)[0]
13 config, cases = zipfile_interface.get_test_cases(zipfile)
14 roscompile_functions = get_functions()
15 
16 
18  for test_config in config:
19  yield roscompile_check, test_config['in'], test_config['out'], \
20  test_config['functions'], test_config.get('subpkg', None), test_config.get('config', {})
21 
22 
23 def roscompile_check(input_package, output_package, list_o_functions, subpkg=None, local_config=None):
24  with cases[input_package] as pkg_in:
25  pkg_out = cases[output_package]
26 
27  root = pkg_in.root
28  if subpkg:
29  root = os.path.join(root, subpkg)
30  pp = Package(root)
31  for function_name in list_o_functions:
32  fne = roscompile_functions[function_name]
33  if 'config' in inspect.getargspec(fne).args:
34  fne(pp, config=local_config)
35  else:
36  fne(pp)
37  pp.write()
38 
39  matches, missed_deletes, missed_gens = pkg_in.compare_filesets(pkg_out)
40  assert len(missed_deletes) == 0, FILE_ERROR_MESSAGE.format('deleted', str(missed_deletes))
41  assert len(missed_gens) == 0, FILE_ERROR_MESSAGE.format('generated', str(missed_gens))
42  for filename in matches:
43  generated_contents = pkg_in.get_contents(filename).strip()
44  canonical_contents = pkg_out.get_contents(filename).strip()
45  if generated_contents != canonical_contents:
46  for gen_line, can_line in prepare_diff_lines(generated_contents, canonical_contents):
47  if gen_line != can_line:
48  print(repr(gen_line) + ' should be ' + repr(can_line))
49 
50  assert generated_contents == canonical_contents, 'The contents of {} do not match!'.format(filename)
def prepare_diff_lines(string_a, string_b)
Definition: diff.py:97
def roscompile_check(input_package, output_package, list_o_functions, subpkg=None, local_config=None)
Definition: utest.py:23
def test_generator()
Definition: utest.py:17


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