File: filter_file.py

package info (click to toggle)
plaso 20201007-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 519,924 kB
  • sloc: python: 79,002; sh: 629; xml: 72; sql: 14; vhdl: 11; makefile: 10
file content (46 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Tests for the filter file."""

from __future__ import unicode_literals

import io
import unittest

from plaso.engine import filter_file

from tests import test_lib as shared_test_lib


class FilterFileTestCase(shared_test_lib.BaseTestCase):
  """Tests for the filter file."""

  # pylint: disable=protected-access

  def testReadFromFileObject(self):
    """Tests the _ReadFromFileObject function."""
    test_file_path = self._GetTestFilePath(['filter_files', 'format_test.txt'])
    self._SkipIfPathNotExists(test_file_path)

    test_filter_file = filter_file.FilterFile()
    with io.open(test_file_path, 'r', encoding='utf-8') as file_object:
      path_filters = list(test_filter_file._ReadFromFileObject(file_object))

    self.assertEqual(len(path_filters), 1)

  def testReadFromFile(self):
    """Tests the ReadFromFile function."""
    test_file_path = self._GetTestFilePath(['filter_files', 'format_test.txt'])
    self._SkipIfPathNotExists(test_file_path)

    test_filter_file = filter_file.FilterFile()
    path_filters = test_filter_file.ReadFromFile(test_file_path)

    self.assertEqual(len(path_filters), 1)

    self.assertEqual(path_filters[0].path_separator, '/')
    self.assertEqual(path_filters[0].paths, ['/usr/bin', '/Windows/System32'])


if __name__ == '__main__':
  unittest.main()