Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 """Tests that all parsers and plugins are imported correctly.""" | |
4 | |
5 from __future__ import unicode_literals | |
6 | |
7 import codecs | |
8 import os | |
9 import re | |
10 import unittest | |
11 | |
12 from tests import test_lib | |
13 | |
14 | |
15 class ParserImportTest(test_lib.BaseTestCase): | |
16 """Tests that parser classes are imported correctly.""" | |
17 | |
18 _PARSERS_PATH = os.path.join(os.getcwd(), 'plaso', 'parsers') | |
19 _FILENAME_REGEXP = re.compile(r'^[^_]*\.py$') | |
20 _IGNORABLE_FILES = frozenset( | |
21 ['manager', 'presets', 'mediator', 'interface', 'plugins']) | |
22 | |
23 def _testFilesImportedInInit(self, path, ignorable_files): | |
Joachim Metz
2018/03/09 00:46:42
Maybe rename to _Check or _Assert seeing this seem
Joachim Metz
2018/03/09 00:46:42
+ nit: docstring
onager
2018/03/09 14:30:53
Done.
onager
2018/03/09 14:30:53
Done.
| |
24 init_path = '{0:s}/__init__.py'.format(path) | |
25 with codecs.open(init_path, mode='r', encoding='utf-8') as init_file: | |
Joachim Metz
2018/03/09 00:46:42
maybe use io.open() instead, which should be porta
onager
2018/03/09 14:30:53
Done.
| |
26 init_content = init_file.read() | |
27 | |
28 for file_path in os.listdir(path): | |
29 filename = os.path.basename(file_path) | |
30 if self._FILENAME_REGEXP.search(filename): | |
31 import_name, _, _ = filename.partition('.') | |
32 import_expression = re.compile(r' import {0:s}\b'.format(import_name)) | |
33 if import_name in ignorable_files: | |
34 continue | |
35 self.assertRegexpMatches( | |
36 init_content, import_expression, | |
37 '{0:s} not imported in {1:s}'.format(import_name, init_path)) | |
38 | |
39 def testParsersImported(self): | |
40 """Tests that all parsers are imported.""" | |
41 self._testFilesImportedInInit(self._PARSERS_PATH, self._IGNORABLE_FILES) | |
42 | |
43 def testPluginsImported(self): | |
44 """Tests that all plugins are imported.""" | |
45 plugin_directories = [ | |
Joachim Metz
2018/03/09 00:46:42
maybe move this to a class constant or glob.glob('
onager
2018/03/09 14:30:53
Done.
| |
46 'bencode_plugins', 'cookie_plugins', 'esedb_plugins', | |
47 'esedb_plugins', 'olecf_plugins', 'plist_plugins', 'sqlite_plugins', | |
48 'syslog_plugins', 'winreg_plugins'] | |
49 for plugin_directory in plugin_directories: | |
50 plugin_directory_path = os.path.join( | |
51 self._PARSERS_PATH, plugin_directory) | |
52 self._testFilesImportedInInit( | |
53 plugin_directory_path, self._IGNORABLE_FILES) | |
54 | |
55 | |
56 if __name__ == '__main__': | |
57 unittest.main() | |
OLD | NEW |