Esempio n. 1
0
  def testNoHits(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foo bar quux")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_literal_match.literal = "baz"
    params.contents_literal_match.mode = "ALL_HITS"
    condition = client_file_finder.LiteralMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertFalse(results)
Esempio n. 2
0
  def testFirstHit(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("bar foo baz foo")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_literal_match.literal = "foo"
    params.contents_literal_match.mode = "FIRST_HIT"
    condition = client_file_finder.LiteralMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 1)
    self.assertEqual(results[0].data, "foo")
    self.assertEqual(results[0].offset, 4)
    self.assertEqual(results[0].length, 3)
Esempio n. 3
0
  def testSomeHits(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foo bar foo")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_literal_match.literal = "foo"
    params.contents_literal_match.mode = "ALL_HITS"
    condition = client_file_finder.LiteralMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 2)
    self.assertEqual(results[0].data, "foo")
    self.assertEqual(results[0].offset, 0)
    self.assertEqual(results[0].length, 3)
    self.assertEqual(results[1].data, "foo")
    self.assertEqual(results[1].offset, 8)
    self.assertEqual(results[1].length, 3)
Esempio n. 4
0
  def testContext(self):
    with open(self.temp_filepath, "wb") as fd:
      fd.write("foo foo foo")

    params = rdf_file_finder.FileFinderCondition()
    params.contents_literal_match.literal = "foo"
    params.contents_literal_match.mode = "ALL_HITS"
    params.contents_literal_match.bytes_before = 3
    params.contents_literal_match.bytes_after = 2
    condition = client_file_finder.LiteralMatchCondition(params)

    results = list(condition.Search(self.temp_filepath))
    self.assertEqual(len(results), 3)
    self.assertEqual(results[0].data, "foo f")
    self.assertEqual(results[0].offset, 0)
    self.assertEqual(results[0].length, 5)
    self.assertEqual(results[1].data, "oo foo f")
    self.assertEqual(results[1].offset, 1)
    self.assertEqual(results[1].length, 8)
    self.assertEqual(results[2].data, "oo foo")
    self.assertEqual(results[2].offset, 5)
    self.assertEqual(results[2].length, 6)