OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Parser related functions and classes for testing.""" | 2 """Parser related functions and classes for testing.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 from dfvfs.lib import definitions as dfvfs_definitions | 6 from dfvfs.lib import definitions as dfvfs_definitions |
7 from dfvfs.path import factory as path_spec_factory | 7 from dfvfs.path import factory as path_spec_factory |
8 from dfvfs.resolver import resolver as path_spec_resolver | 8 from dfvfs.resolver import resolver as path_spec_resolver |
9 | 9 |
10 from plaso.containers import sessions | 10 from plaso.containers import sessions |
11 from plaso.engine import knowledge_base | 11 from plaso.engine import knowledge_base |
12 from plaso.formatters import manager as formatters_manager | 12 from plaso.formatters import manager as formatters_manager |
13 from plaso.formatters import mediator as formatters_mediator | 13 from plaso.formatters import mediator as formatters_mediator |
14 from plaso.parsers import interface | 14 from plaso.parsers import interface |
15 from plaso.parsers import mediator | 15 from plaso.parsers import mediator |
16 from plaso.storage import fake_storage | 16 from plaso.storage.fake import writer as fake_writer |
17 | 17 |
18 from tests import test_lib as shared_test_lib | 18 from tests import test_lib as shared_test_lib |
19 | 19 |
20 | 20 |
21 class ParserTestCase(shared_test_lib.BaseTestCase): | 21 class ParserTestCase(shared_test_lib.BaseTestCase): |
22 """Parser test case.""" | 22 """Parser test case.""" |
23 | 23 |
24 def _CreateParserMediator( | 24 def _CreateParserMediator( |
25 self, storage_writer, file_entry=None, knowledge_base_values=None, | 25 self, storage_writer, file_entry=None, knowledge_base_values=None, |
26 parser_chain=None, timezone='UTC'): | 26 parser_chain=None, timezone='UTC'): |
(...skipping 30 matching lines...) Expand all Loading... |
57 | 57 |
58 return parser_mediator | 58 return parser_mediator |
59 | 59 |
60 def _CreateStorageWriter(self): | 60 def _CreateStorageWriter(self): |
61 """Creates a storage writer object. | 61 """Creates a storage writer object. |
62 | 62 |
63 Returns: | 63 Returns: |
64 FakeStorageWriter: storage writer. | 64 FakeStorageWriter: storage writer. |
65 """ | 65 """ |
66 session = sessions.Session() | 66 session = sessions.Session() |
67 storage_writer = fake_storage.FakeStorageWriter(session) | 67 storage_writer = fake_writer.FakeStorageWriter(session) |
68 storage_writer.Open() | 68 storage_writer.Open() |
69 return storage_writer | 69 return storage_writer |
70 | 70 |
71 def _GetShortMessage(self, message_string): | 71 def _GetShortMessage(self, message_string): |
72 """Shortens a message string to a maximum of 80 character width. | 72 """Shortens a message string to a maximum of 80 character width. |
73 | 73 |
74 Args: | 74 Args: |
75 message_string (str): message string. | 75 message_string (str): message string. |
76 | 76 |
77 Returns: | 77 Returns: |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 expected_source (str): expected source string. | 173 expected_source (str): expected source string. |
174 expected_source_short (str): expected short source string. | 174 expected_source_short (str): expected short source string. |
175 """ | 175 """ |
176 # TODO: change this to return the long variant first so it is consistent | 176 # TODO: change this to return the long variant first so it is consistent |
177 # with GetMessageStrings. | 177 # with GetMessageStrings. |
178 source_short, source = ( | 178 source_short, source = ( |
179 formatters_manager.FormattersManager.GetSourceStrings(event)) | 179 formatters_manager.FormattersManager.GetSourceStrings(event)) |
180 self.assertEqual(source, expected_source) | 180 self.assertEqual(source, expected_source) |
181 self.assertEqual(source_short, expected_source_short) | 181 self.assertEqual(source_short, expected_source_short) |
182 | 182 |
183 def assertDictContains(self, received, expected): | 183 def AssertDictContains(self, received, expected): |
184 """Asserts if a dictionary contains every key-value pair as expected. | 184 """Asserts if a dictionary contains every key-value pair as expected. |
185 | 185 |
186 Recieved can contain new keys. If any value is a dict, this function is | 186 Received can contain new keys. If any value is a dict, this function is |
187 called recursively. | 187 called recursively. |
188 | 188 |
189 Args: | 189 Args: |
190 received (dict): received dictionary. | 190 received (dict): received dictionary. |
191 expected (dict): expected dictionary. | 191 expected (dict): expected dictionary. |
192 """ | 192 """ |
193 for key, value in expected.items(): | 193 for key, value in iter(expected.items()): |
194 self.assertIn(key, received) | 194 self.assertIn(key, received) |
195 | 195 |
196 if isinstance(value, dict): | 196 if isinstance(value, dict): |
197 self.assertDictEqual(received[key], expected[key]) | 197 self.assertDictEqual(received[key], expected[key]) |
198 else: | 198 else: |
199 self.assertEqual(value, expected[key]) | 199 self.assertEqual(value, expected[key]) |
OLD | NEW |