def test_get_included_files(self):
     path = interpret_path(
         "$(find fkie_node_manager_daemon)/tests/resources/include_dummy.launch"
     )
     file_list = [
         file_tuple for file_tuple in self.ls.get_included_files_set(
             path, recursive=True, include_pattern=[])
     ]
     #        for linenr, path, exists, file_list in inc_files:
     self.assertEqual(
         len(file_list), 5,
         "Count of unique included, recursive files is wrong, got: %d, expected: %d"
         % (len(file_list), 5))
     file_list = [
         file_tuple for file_tuple in self.ls.get_included_files_set(
             path, recursive=False, include_pattern=[])
     ]
     self.assertEqual(
         len(file_list), 3,
         "Count of unique included files while not recursive search is wrong, got: %d, expected: %d"
         % (len(file_list), 3))
     file_list = [
         file_tuple for file_tuple in self.ls.get_included_files(
             path, recursive=False, include_pattern=[])
     ]
     self.assertEqual(
         len(file_list), 6,
         "Count of recursive, not unique included files is wrong, got: %d, expected: %d"
         % (len(file_list), 6))
     file_list = [
         file_tuple for file_tuple in self.ls.get_included_files(
             path, recursive=True, include_pattern=[])
     ]
     self.assertEqual(
         len(file_list), 10,
         "Count of recursive included files is wrong, got: %d, expected: %d"
         % (len(file_list), 10))
     self.assertEqual(
         file_list[0].line_number, 6,
         "Wrong line number of first included file, got: %d, expected: %d" %
         (file_list[0].line_number, 6))
     #self.assertEqual(file_list[0][1], file_list[0][3][0][1], "Wrong root path of second included file, expected: %s, got: %s" % (file_list[0][1], file_list[0][3][0][1]))
     self.assertEqual(
         file_list[1].line_number, 4,
         "Wrong line number of second included file, got: %d, expected: %d"
         % (file_list[1].line_number, 4))
     self.assertEqual(
         file_list[2].line_number, 10,
         "Wrong line number of third included file, got: %d, expected: %d" %
         (file_list[2].line_number, 10))
예제 #2
0
 def test_save_content(self):
     fs = FileServicer()
     test_data = b'This is a test file for save content test.'
     content = fmsg.SaveFileContentRequest()
     content.file.path = self.test_save_content_path
     content.file.mtime = 1.0  # something not zero to update a not existing file
     content.file.size = len(test_data)
     content.file.data = test_data
     save_response = next(fs.SaveFileContent([content], DummyContext()))
     self.assertEqual(save_response.status.code, fmsg.ReturnStatus.StatusType.Value('REMOVED_FILE'), "wrong status code '%d' if file was removed in meantime." % save_response.status.code)
     # save new file
     content.file.mtime = 0
     save_response = next(fs.SaveFileContent([content], DummyContext()))
     self.assertEqual(save_response.status.code, fmsg.ReturnStatus.StatusType.Value('OK'), 'new file was not saved')
     self.assertTrue(os.path.exists(self.test_save_content_path), 'new file was not saved to %s' % self.test_save_content_path)
     self.assertEqual(save_response.ack.mtime, os.path.getmtime(self.test_save_content_path), 'wrong mtime returned after create a new file')
     # sleep to change the mtime in file
     time.sleep(0.3)
     # change file in meantime
     new_utime = time.time()
     os.utime(self.test_save_content_path, (new_utime, new_utime))
     new_test_data = b'This is a changed text for save content test.'
     content.file.mtime = save_response.ack.mtime
     content.file.size = len(new_test_data)
     content.file.data = new_test_data
     save_response = next(fs.SaveFileContent([content], DummyContext()))
     self.assertEqual(save_response.status.code, fmsg.ReturnStatus.StatusType.Value('CHANGED_FILE'), 'wrong status code if file was changed in meantime.')
     # overwrite the changed file
     content.overwrite = True
     save_response = next(fs.SaveFileContent([content], DummyContext()))
     self.assertEqual(save_response.status.code, fmsg.ReturnStatus.StatusType.Value('OK'), 'file was not overwritten')
     self.assertEqual(save_response.ack.mtime, os.path.getmtime(self.test_save_content_path), 'wrong mtime returned after overwrite file')
     with FileIO(self.test_save_content_path, 'r') as outfile:
         self.assertEqual(new_test_data, outfile.read(), 'wrong content in file')
     # try to save in root folder
     content.file.path = '/content_test.txt'
     content.file.mtime = 0
     save_response = next(fs.SaveFileContent([content], DummyContext()))
     if save_response.status.code == fmsg.ReturnStatus.StatusType.Value('OK'):
         # test in industrial ci, use source folder
         content.file.path = interpret_path('$(find fkie_node_manager_daemon)/') + content.file.path
         save_response = next(fs.SaveFileContent([content], DummyContext()))
     self.assertEqual(save_response.status.code, fmsg.ReturnStatus.StatusType.Value('IO_ERROR'), 'save in root folder returns a wrong result: %d, expected: %d' % (save_response.status.code, fmsg.ReturnStatus.StatusType.Value('IO_ERROR')))
     # save file in more chunks
     test_data = [b'First line.\n', b'Second line.\n', b'Third line.\n']
     for resp in fs.SaveFileContent(self._read_from_list(test_data, self.test_save_content_path), DummyContext()):
         self.assertEqual(resp.status.code, fmsg.ReturnStatus.StatusType.Value('OK'), 'file was not overwritten, result code: %d' % resp.status.code)
         self.assertEqual(resp.ack.size, self.current_pose, 'incorrect transferred file size: %d, expected: %d' % (resp.ack.size, self.current_pose))
     with FileIO(self.test_save_content_path, 'r') as outfile:
         self.assertEqual(str(test_data), str(outfile.readlines()), 'wrong content in file')
 def test_reload_launch(self):
     path = interpret_path(
         "$(find fkie_node_manager_daemon)/tests/resources/include_dummy.launch"
     )
     try:
         launch_file, _argv = self.ls.reload_launch(path)
         self.fail(
             "`load_launch` did not raises `exceptions.ResourceNotFoundt` on reload launch file"
         )
     except exceptions.ResourceNotFound as rnf:
         pass
     except Exception as err:
         self.fail(
             "`load_launch` raises wrong Exception on reload launch file, got: %s, expected: `exceptions.ResourceNotFoundt`: %s"
             % (type(err), err))
예제 #4
0
    def test_interpret_path(self):
        text_path = "$(find fkie_node_manager_daemon)/%s/include_dummy.launch" % self.res_dir
        path = interpret_path(text_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted path, expected: %s, got: %s" %
            (self.test_include_file, path))
        text_path = "resources/include_dummy.launch"
        path = interpret_path(text_path, self.nm_path)
        exp_path = os.path.join(self.nm_path, text_path)
        self.assertEqual(
            exp_path, path,
            "wrong interpreted relative path, expected: %s, got: %s" %
            (exp_path, path))
        text_path = "pkg://fkie_node_manager_daemon/%s/include_dummy.launch" % self.res_dir
        path = interpret_path(text_path, self.nm_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted pkg:// path, expected: %s, got: %s" %
            (self.test_include_file, path))
        text_path = "package://fkie_node_manager_daemon/%s/include_dummy.launch" % self.res_dir
        path = interpret_path(text_path, self.nm_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted package:// path, expected: %s, got: %s" %
            (self.test_include_file, path))
        text_path = "file://tests/resources/include_dummy.launch"
        path = interpret_path(text_path, self.nm_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted file:// path, expected: %s, got: %s" %
            (self.test_include_file, path))
        text_path = "pkg://fkie_node_manager_daemon///include_dummy.launch"
        path = interpret_path(text_path, self.nm_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted path with replace the subdirectory by `///`, expected: %s, got: %s"
            % (self.test_include_file, path))

        text_path = "$(find invalid_name)/%s/include_dummy.launch" % self.res_dir
        self.assertRaises(
            rospkg.ResourceNotFound, interpret_path, text_path,
            "No rospkg.ResourceNotFound raises on invalid pacakge name")

        text_path = "some other --args here '$(find fkie_node_manager_daemon)/%s/include_dummy.launch'" % self.res_dir
        path = interpret_path(text_path)
        self.assertEqual(
            self.test_include_file, path,
            "wrong interpreted path, expected: %s, got: %s" %
            (self.test_include_file, path))
예제 #5
0
 def _test_load_launch(self, unload=True):
     args = {}
     path = ''
     request_args = True
     nexttry = True
     ok = False
     launch_file = ''
     package = 'fkie_node_manager_daemon'
     launch = 'description_example.launch'
     try:
         launch_file, _argv = self.ls.load_launch(package, launch, path=path, args=args, request_args=request_args)
         self.fail("`load_launch` did not raises `exceptions.LaunchSelectionRequest` on multiple launch files")
     except exceptions.LaunchSelectionRequest as _lsr:
         path = interpret_path("$(find fkie_node_manager_daemon)/tests/resources/description_example.launch")
     except Exception as err:
         self.fail("`load_launch` raises wrong Exception on multiple launch files, got: %s, expected: `exceptions.LaunchSelectionRequest`: %s" % (type(err), err))
     try:
         launch_file, _argv = self.ls.load_launch(package, launch, path=path, args=args, request_args=request_args)
         self.fail("`load_launch` did not raises `exceptions.ParamSelectionRequest` on args requests")
     except exceptions.AlreadyOpenException as aoe:
         # it is already open from other tests
         return
     except exceptions.ParamSelectionRequest as psr:
         request_args = False
         args = psr.choices
     except Exception as err:
         import traceback
         self.fail("`load_launch` raises wrong Exception on args requests, got: %s, expected: `exceptions.ParamSelectionReques`: %s" % (type(err), traceback.format_exc()))
     request_args = False
     try:
         launch_file, _argv = self.ls.load_launch(package, launch, path=path, args=args, request_args=request_args)
     except Exception as err:
         self.fail("`load_launch` raises unexpected exception, got: %s, expected: no error" % type(err))
     try:
         launch_file, _argv = self.ls.load_launch(package, launch, path=path, args=args, request_args=request_args)
         self.fail("`load_launch` did not raises `exceptions.AlreadyOpenException` on load an already loaded file")
     except exceptions.AlreadyOpenException as aoe:
         request_args = False
         args = psr.choices
     except Exception as err:
         self.fail("`load_launch` raises wrong Exception on second reload, got: %s, expected: `exceptions.AlreadyOpenException`: %s" % (type(err), err))
     if unload:
         self.ls.unload_launch(launch_file)
예제 #6
0
 def setDescription(self, index, cfg, name, displayed_name, robot_type,
                    description, images):
     '''
     Sets the values of an existing item to the given items.
     '''
     if index < len(self._data):
         obj = self._data[index]
         if cfg not in obj['cfgs']:
             obj['cfgs'].append(cfg)
         obj['name'] = name
         if displayed_name:
             obj['displayed_name'] = displayed_name
             obj['type'] = robot_type
             obj['description'] = replace_paths(description)
             if images:
                 del obj['images'][:]
         for image_path in images:
             img = interpret_path(image_path)
             if img and img[0] != os.path.sep:
                 img = os.path.join(nm.settings().PACKAGE_DIR, image_path)
             if os.path.isfile(img):
                 obj['images'].append(QPixmap(img))
    def test_load_launch(self):
        ls = LaunchServicer()
        path = ''
        args = {}
        request_args = True
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='no_file.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
            "wrong status code if launch file not exists, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
               response.status.error_msg))
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='unknonwn_package',
                                   launch='no_file.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
            "wrong status code if package not exists, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('FILE_NOT_FOUND'),
               response.status.error_msg))
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('MULTIPLE_LAUNCHES'),
            "wrong status code for multiple launch files, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('MULTIPLE_LAUNCHES'),
               response.status.error_msg))
        self.assertEqual(
            len(response.path), 2,
            "wrong count of multiple launch files, result: %d, expected: %d" %
            (len(response.path), 2))
        path = interpret_path(
            "$(find fkie_node_manager_daemon)/tests/resources/description_example.launch"
        )
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('PARAMS_REQUIRED'),
            "wrong status code for request arguments, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('PARAMS_REQUIRED'),
               response.status.error_msg))
        args = {arg.name: arg.value for arg in response.args}
        request_args = False
        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
            "wrong status code on successful load, result: %d, expected: %d, reported error: %s"
            % (response.status.code, lmsg.ReturnStatus.StatusType.Value('OK'),
               response.status.error_msg))

        response = ls.LoadLaunch(
            lmsg.LoadLaunchRequest(package='fkie_node_manager_daemon',
                                   launch='description_example.launch',
                                   path=path,
                                   request_args=request_args), DummyContext())
        self.assertEqual(
            response.status.code,
            lmsg.ReturnStatus.StatusType.Value('ALREADY_OPEN'),
            "wrong status code if file is already open, result: %d, expected: %d, reported error: %s"
            % (response.status.code,
               lmsg.ReturnStatus.StatusType.Value('ALREADY_OPEN'),
               response.status.error_msg))
        self.assertEqual(
            response.path[0], path,
            "Wrong returned path in ALREADY_OPEN reply, expected: %s, got: %s"
            % (response.path[0], path))

        # test loaded file
        response_stream = ls.GetLoadedFiles(lmsg.Empty(), DummyContext())
        items = [response for response in response_stream]
        self.assertEqual(
            len(items), 1,
            "The count of loaded files after successful load is wrong")
        self.assertEqual(
            items[0].path, path,
            "Wrong reported loaded file path, got: %s, expected: %s" %
            (items[0].path, path))
        self.assertEqual(
            items[0].package, 'fkie_node_manager_daemon',
            "Wrong reported loaded package, got: %s, expected: %s" %
            (items[0].package, 'fkie_node_manager_daemon'))
        self.assertEqual(
            items[0].launch, 'description_example.launch',
            "Wrong reported loaded launch, got: %s, expected: %s" %
            (items[0].launch, 'description_example.launch'))