utest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 import inspect
00003 from catkin.find_in_workspaces import find_in_workspaces
00004 import zipfile_interface
00005 from ros_introspection.package import Package
00006 from roscompile import get_functions
00007 import os.path
00008 
00009 FILE_ERROR_MESSAGE = 'These files should have been {} but weren\'t: {}'
00010 
00011 zipfile = find_in_workspaces(path='roscompile/test/test_data.zip', first_match_only=True)[0]
00012 config, cases = zipfile_interface.get_test_cases(zipfile)
00013 roscompile_functions = get_functions()
00014 
00015 
00016 def test_generator():
00017     for test_config in config:
00018         yield roscompile_check, test_config['in'], test_config['out'], \
00019             test_config['functions'], test_config.get('subpkg', None), test_config.get('config', {})
00020 
00021 
00022 def roscompile_check(input_package, output_package, list_o_functions, subpkg=None, local_config=None):
00023     with cases[input_package] as pkg_in:
00024         pkg_out = cases[output_package]
00025 
00026         root = pkg_in.root
00027         if subpkg:
00028             root = os.path.join(root, subpkg)
00029         pp = Package(root)
00030         for function_name in list_o_functions:
00031             fne = roscompile_functions[function_name]
00032             if 'config' in inspect.getargspec(fne).args:
00033                 fne(pp, config=local_config)
00034             else:
00035                 fne(pp)
00036         pp.write()
00037 
00038         matches, missed_deletes, missed_gens = pkg_in.compare_filesets(pkg_out)
00039         assert len(missed_deletes) == 0, FILE_ERROR_MESSAGE.format('deleted', str(missed_deletes))
00040         assert len(missed_gens) == 0, FILE_ERROR_MESSAGE.format('generated', str(missed_gens))
00041         for filename in matches:
00042             generated_contents = pkg_in.get_contents(filename).strip()
00043             canonical_contents = pkg_out.get_contents(filename).strip()
00044             assert generated_contents == canonical_contents, 'The contents of {} do not match!'.format(filename)


roscompile
Author(s):
autogenerated on Wed Jun 19 2019 19:21:36