class TestRuleBase(TestCase): def setUp(self): """ Creates teacher with sample Rule. """ test_files_dir = 'empty_config_files' path = os.path.join(*path_test_files + [test_files_dir]) parsers_path, rules_path, log_types_path = ConfigPathFactory.get_path_to_config_files( path, False ) self.test_files = [parsers_path, rules_path, log_types_path] self._clean_test_files() yaml_config = YamlConfig(parsers_path, rules_path, log_types_path) regex_assistant = RegexAssistant() self.teacher = Teacher(yaml_config, regex_assistant) self.effect_id = 0 self.effect_front_input = FrontInput( offset=42, line_content=r'2015-12-03 12:11:00 Error occurred in reading test', line_source=LineSource('sample_host', 'sample_path') ) self.cause1_id = 1 self.cause1_front_input = FrontInput( offset=30, line_content=r'2015-12-03 12:10:55 Data is missing on comp21', line_source=LineSource('sample_host1', 'sample_path1') ) self.cause2_id = 2 self.cause2_front_input = FrontInput( offset=21, line_content=r'2015-12-03 12:10:50 Data migration to comp21 failed in test 123', line_source=LineSource('sample_host2', 'sample_path2') ) self.identical_groups = [(self.cause1_id, 2), (self.cause2_id, 2)] self.date_groups = [(self.effect_id, 1), (self.effect_id, 1)] self._add_rule() def _add_rule(self): self.teacher.add_line(self.effect_id, self.effect_front_input, effect=True) self.teacher.add_line(self.cause1_id, self.cause1_front_input) self.cause1_pattern = r'^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) Data is missing on (.*)$' self.teacher.update_pattern(self.cause1_id, self.cause1_pattern) self.teacher.add_line(self.cause2_id, self.cause2_front_input) cause2_pattern = r'^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}) Data migration to (.*) failed in test (.*)$' self.teacher.update_pattern(self.cause2_id, cause2_pattern) def tearDown(self): self._clean_test_files() def _clean_test_files(self): for test_file in self.test_files: open(test_file, 'w').close()
def setUp(self): """ Creates teacher with sample Rule. """ test_files_dir = 'empty_config_files' path = os.path.join(*path_test_files + [test_files_dir]) parsers_path, rules_path, log_types_path = ConfigPathFactory.get_path_to_config_files( path, False ) self.test_files = [parsers_path, rules_path, log_types_path] self._clean_test_files() yaml_config = YamlConfig(parsers_path, rules_path, log_types_path) regex_assistant = RegexAssistant() self.teacher = Teacher(yaml_config, regex_assistant) self.effect_id = 0 self.effect_front_input = FrontInput( offset=42, line_content=r'2015-12-03 12:11:00 Error occurred in reading test', line_source=LineSource('sample_host', 'sample_path') ) self.cause1_id = 1 self.cause1_front_input = FrontInput( offset=30, line_content=r'2015-12-03 12:10:55 Data is missing on comp21', line_source=LineSource('sample_host1', 'sample_path1') ) self.cause2_id = 2 self.cause2_front_input = FrontInput( offset=21, line_content=r'2015-12-03 12:10:50 Data migration to comp21 failed in test 123', line_source=LineSource('sample_host2', 'sample_path2') ) self.identical_groups = [(self.cause1_id, 2), (self.cause2_id, 2)] self.date_groups = [(self.effect_id, 1), (self.effect_id, 1)] self._add_rule()