Skip to content

Commit

Permalink
Merge pull request #1420 from prakhar2b/index_cleanup
Browse files Browse the repository at this point in the history
 index and index.d data cleanup in AnnoyIndexer (test_similarities.py)
  • Loading branch information
menshikh-iv authored Jun 19, 2017
2 parents 5f9503c + 2c7f085 commit b252932
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions gensim/test/test_similarities.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,24 +515,25 @@ def assertApproxNeighborsMatchExact(self, model, wv, index):
self.assertEqual(approx_words, exact_words)

def assertIndexSaved(self, index):
index.save('index')
self.assertTrue(os.path.exists('index'))
self.assertTrue(os.path.exists('index.d'))
fname = testfile()
index.save(fname)
self.assertTrue(os.path.exists(fname))
self.assertTrue(os.path.exists(fname + '.d'))

def assertLoadedIndexEqual(self, index, model):
from gensim.similarities.index import AnnoyIndexer

index.save('index')
fname = testfile()
index.save(fname)

index2 = AnnoyIndexer()
index2.load('index')
index2.load(fname)
index2.model = model

self.assertEqual(index.index.f, index2.index.f)
self.assertEqual(index.labels, index2.labels)
self.assertEqual(index.num_trees, index2.num_trees)


class TestDoc2VecAnnoyIndexer(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -566,9 +567,10 @@ def testApproxNeighborsMatchExact(self):
self.assertEqual(approx_words, exact_words)

def testSave(self):
self.index.save('index')
self.assertTrue(os.path.exists('index'))
self.assertTrue(os.path.exists('index.d'))
fname = testfile()
self.index.save(fname)
self.assertTrue(os.path.exists(fname))
self.assertTrue(os.path.exists(fname + '.d'))

def testLoadNotExist(self):
from gensim.similarities.index import AnnoyIndexer
Expand All @@ -579,10 +581,11 @@ def testLoadNotExist(self):
def testSaveLoad(self):
from gensim.similarities.index import AnnoyIndexer

self.index.save('index')
fname = testfile()
self.index.save(fname)

self.index2 = AnnoyIndexer()
self.index2.load('index')
self.index2.load(fname)
self.index2.model = self.model

self.assertEqual(self.index.index.f, self.index2.index.f)
Expand Down

0 comments on commit b252932

Please sign in to comment.