def test_handler_wrong_signature(self) -> None: handler = WrongHandler() mock_event = { '_name': 'myeventname', '_timestamp': 0, 'cpu_id': 0, } processor = Processor(handler) with self.assertRaises(TypeError): processor.process([mock_event])
def test_handler_method_with_merge(self) -> None: handler1 = StubHandler1() handler2 = StubHandler2() mock_event = { '_name': 'myeventname', '_timestamp': 0, 'cpu_id': 0, } processor = Processor(handler1, handler2) processor.process([mock_event]) self.assertTrue(handler1.handler_called, 'event handler not called') self.assertTrue(handler2.handler_called, 'event handler not called')
def test_processor_quiet(self) -> None: handler1 = StubHandler1() mock_event = { '_name': 'myeventname', '_timestamp': 0, 'cpu_id': 0, } temp_stdout = StringIO() with contextlib.redirect_stdout(temp_stdout): processor = Processor(handler1, quiet=True) processor.process([mock_event]) # Shouldn't be any output output = temp_stdout.getvalue() self.assertEqual(0, len(output), f'Processor was not quiet: "{output}"')
def process( input_path: str, force_conversion: bool = False, hide_results: bool = False, convert_only: bool = False, ) -> int: """ Process ROS 2 trace data and output model data. The trace data will be automatically converted into an internal intermediate representation if needed. :param input_path: the path to a converted file or trace directory :param force_conversion: whether to re-creating converted file even if it is found :param hide_results: whether to hide results and not print them :param convert_only: whether to only convert the file into our internal intermediate representation, without processing it. This should usually not be necessary since conversion is done automatically only when needed or when explicitly requested with force_conversion; conversion is mostly just an implementation detail """ input_path = os.path.expanduser(input_path) if not os.path.exists(input_path): print(f'input path does not exist: {input_path}', file=sys.stderr) return 1 start_time = time.time() events = load_file(input_path, do_convert_if_needed=True, force_conversion=force_conversion) # Return now if we only need to convert the file if convert_only: return 0 processor = Processor(Ros2Handler()) processor.process(events) time_diff = time.time() - start_time if not hide_results: processor.print_data() print(f'processed {len(events)} events in {time_diff_to_str(time_diff)}') return 0