Beispiel #1
0
 def test_regexp(self):
     SPEC = {
         'to_dict':
         ["My name is (?P<name>\w*) and I'm (?P<age>\d*) years old."]
     }
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("My name is Valerian and I'm 3 years old.")
     self.assertDictEqual(dicted, {'name': 'Valerian', 'age': '3'})
Beispiel #2
0
 def test_formatted(self):
     SPEC = {
         'to_format': {
             SAMPLE_PARSE: dict(name_and_age="{name}_{age:d}")
         }
     }
     processor = LineProcessor(SPEC)
     formatted = processor.for_line("My name is Jacob and I'm 3 years old.")
     self.assertDictEqual(formatted, {'name_and_age': 'Jacob_3'})
Beispiel #3
0
 def test_no_parse(self):
     SPEC = {'to_dict': [SAMPLE_PARSE]}
     processor = LineProcessor(SPEC)
     indexer = MockIndexer()
     handler = stashpy.handler.ConnectionHandler(MockStream(), None,
                                                 indexer, processor)
     resp = yield handler.process_line(b"A random line")
     self.assertEqual(len(indexer.indexed), 1)
     self.assertDictEqualWithTimestamp(indexer.indexed[0], {
         'message': 'A random line',
         '@version': 1
     })
 def test_regexp(self):
     SPEC = {'to_dict':["My name is (?P<name>\w*) and I'm (?P<age>\d*) years old."]}
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("My name is Valerian and I'm 3 years old.")
     self.assertDictEqual(dicted, {'name': 'Valerian', 'age': '3'})
 def test_formatted(self):
     SPEC = {'to_format': {SAMPLE_PARSE: dict(name_and_age="{name}_{age:d}")}}
     processor = LineProcessor(SPEC)
     formatted = processor.for_line("My name is Jacob and I'm 3 years old.")
     self.assertDictEqual(formatted, {'name_and_age':'Jacob_3'})
 def test_none_on_no_match(self):
     SPEC = {'to_dict':[SAMPLE_PARSE]}
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("I'm not talking to you")
     self.assertIsNone(dicted)
 def test_to_dict(self):
     SPEC = {'to_dict':[SAMPLE_PARSE]}
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("My name is Valerian and I'm 3 years old.")
     self.assertDictEqual(dicted, {'name': 'Valerian', 'age': 3})
Beispiel #8
0
 def process_to_format(self, to_format, logline):
     return LineProcessor(specs=dict(to_format=to_format)).for_line(logline)
Beispiel #9
0
 def process_spec(self, spec, logline):
     return LineProcessor(specs=spec).for_line(logline)
Beispiel #10
0
 def test_none_on_no_match(self):
     SPEC = {'to_dict': [SAMPLE_PARSE]}
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("I'm not talking to you")
     self.assertIsNone(dicted)
Beispiel #11
0
 def test_to_dict(self):
     SPEC = {'to_dict': [SAMPLE_PARSE]}
     processor = LineProcessor(SPEC)
     dicted = processor.for_line("My name is Valerian and I'm 3 years old.")
     self.assertDictEqual(dicted, {'name': 'Valerian', 'age': 3})