1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the output manager."""
from __future__ import unicode_literals
import unittest
from plaso.output import interface
from plaso.output import manager
class TestOutput(interface.OutputModule):
"""Test output module."""
NAME = 'test_output'
DESCRIPTION = 'This is a test output module.'
# pylint: disable=unused-argument
def WriteEventBody(self, event, event_data, event_data_stream, event_tag):
"""Writes event values to the output.
Args:
event (EventObject): event.
event_data (EventData): event data.
event_data_stream (EventDataStream): event data stream.
event_tag (EventTag): event tag.
"""
return
class OutputManagerTest(unittest.TestCase):
"""Tests for the output manager."""
def testRegistration(self):
"""Tests the RegisterOutput and DeregisterOutput functions."""
# pylint: disable=protected-access
number_of_parsers = len(manager.OutputManager._output_classes)
manager.OutputManager.RegisterOutput(TestOutput)
with self.assertRaises(KeyError):
manager.OutputManager.RegisterOutput(TestOutput)
self.assertEqual(
len(manager.OutputManager._output_classes),
number_of_parsers + 1)
with self.assertRaises(KeyError):
manager.OutputManager.RegisterOutput(TestOutput)
manager.OutputManager.DeregisterOutput(TestOutput)
self.assertEqual(
len(manager.OutputManager._output_classes),
number_of_parsers)
def testGetOutputClass(self):
"""Tests the GetOutputClass function."""
manager.OutputManager.RegisterOutput(TestOutput)
output_class = manager.OutputManager.GetOutputClass('test_output')
self.assertEqual(output_class, TestOutput)
with self.assertRaises(ValueError):
_ = manager.OutputManager.GetOutputClass(1)
with self.assertRaises(KeyError):
_ = manager.OutputManager.GetOutputClass('bogus')
manager.OutputManager.DeregisterOutput(TestOutput)
def testGetDisabledOutputClasses(self):
"""Tests the GetDisabledOutputClasses function."""
manager.OutputManager.RegisterOutput(TestOutput, disabled=True)
names = []
output_classes = []
for name, output_class in manager.OutputManager.GetDisabledOutputClasses():
names.append(name)
output_classes.append(output_class)
self.assertIn('test_output', names)
self.assertIn(TestOutput, output_classes)
manager.OutputManager.DeregisterOutput(TestOutput)
def testGetOutputClasses(self):
"""Tests the GetOutputClasses function."""
manager.OutputManager.RegisterOutput(TestOutput)
names = []
output_classes = []
for name, output_class in manager.OutputManager.GetOutputClasses():
names.append(name)
output_classes.append(output_class)
self.assertIn('test_output', names)
self.assertIn(TestOutput, output_classes)
manager.OutputManager.DeregisterOutput(TestOutput)
def testHasOutputClass(self):
"""Tests the HasOutputClass function."""
manager.OutputManager.RegisterOutput(TestOutput)
self.assertTrue(manager.OutputManager.HasOutputClass('test_output'))
self.assertFalse(manager.OutputManager.HasOutputClass('bogus'))
self.assertFalse(manager.OutputManager.HasOutputClass(1))
manager.OutputManager.DeregisterOutput(TestOutput)
# TODO: add tests for IsLinearOutputModule.
def testNewOutputModule(self):
"""Tests the NewOutputModule function."""
manager.OutputManager.RegisterOutput(TestOutput)
output_module = manager.OutputManager.NewOutputModule('test_output', None)
self.assertIsInstance(output_module, TestOutput)
with self.assertRaises(ValueError):
_ = manager.OutputManager.NewOutputModule(1, None)
with self.assertRaises(KeyError):
_ = manager.OutputManager.NewOutputModule('bogus', None)
manager.OutputManager.DeregisterOutput(TestOutput)
if __name__ == '__main__':
unittest.main()
|