Skip to content

Commit

Permalink
Added simple test for pickling
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikP committed Aug 27, 2018
1 parent 80634f5 commit 7ad85b2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/ahocorapy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
from builtins import str
from io import open
from pickle import dumps, loads
import unittest


Expand Down Expand Up @@ -272,5 +273,27 @@ def test_search_all_issue_3_similar(self):
self.assertEqual(('foo/', 1), next(results))
self.assertEqual(('/bar', 4), next(results))

def test_pickling_simple(self):
words = ['peter', 'horst', 'gandalf', 'frodo']
tree = KeywordTree(case_insensitive=True)
for word in words:
tree.add(word)
tree.finalize()
as_bytes = dumps(tree)

self.assertIsNotNone(as_bytes)

deserialized = loads(as_bytes)

self.assertIsNotNone(deserialized)

text = 'Gollum did not like frodo. But gandalf did.'

results = deserialized.search_all(text)

self.assertEqual(('frodo', 20), next(results))
self.assertEqual(('gandalf', 31), next(results))


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

0 comments on commit 7ad85b2

Please sign in to comment.