Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index and index.d data cleanup in AnnoyIndexer (test_similarities.py) #1420

Merged
merged 3 commits into from
Jun 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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