コード例 #1
0
    def test_save_and_load_automaton(self):
        import pickle

        A = self.add_words_and_make_automaton()

        A.save(self.path, pickle.dumps)
        B = ahocorasick.load(self.path, pickle.loads)

        self.compare_automatons(A, B)
コード例 #2
0
    def test_save_and_load_empty(self):
        import pickle

        A = ahocorasick.Automaton()

        A.save(self.path, pickle.dumps)
        B = ahocorasick.load(self.path, pickle.loads)

        self.compare_automatons(A, B)
コード例 #3
0
    def test_save_and_load_set(self):
        import pickle

        A = ahocorasick.Automaton(ahocorasick.STORE_ANY)
        for i, word in enumerate(conv("he she her cat car carriage zoo")):
            A.add_word(word, set([i, word]))

        A.save(self.path, pickle.dumps)
        B = ahocorasick.load(self.path, pickle.loads)

        self.compare_automatons(A, B)
コード例 #4
0
 def test_load__invalid_argument_2(self):
     with self.assertRaisesRegex(
             TypeError, "the second argument must be a callable object"):
         ahocorasick.load("/dev/shm/test.dump", None)
コード例 #5
0
 def test_load__invalid_argument_1(self):
     with self.assertRaisesRegex(TypeError,
                                 "the first argument must be a string"):
         ahocorasick.load(None, None)
コード例 #6
0
 def test_load__invalid_number_of_arguments(self):
     with self.assertRaisesRegex(ValueError,
                                 "expected exactly two arguments"):
         ahocorasick.load()
コード例 #7
0
    def load(self):
        path = self.options.picklepath

        print("Loading automaton from %s" % path)

        self.A = ahocorasick.load(path, pickle.loads)