Skip to content

Commit

Permalink
Added test to check exception in ensemble method for Python 2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolgulati committed Feb 1, 2017
1 parent 5777fe7 commit bf57058
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions gensim/test/test_varembed_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
Automated tests for VarEmbed wrapper.
"""


import logging
import unittest
import os

import sys
import numpy as np

if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

from gensim.models.wrappers import varembed

# needed because sample data files are located in the same folder
Expand All @@ -25,9 +28,8 @@
varembed_model_vector_file = datapath('varembed_leecorpus_vectors.pkl')
varembed_model_morfessor_file = datapath('varembed_leecorpus_morfessor.bin')

class TestVarembed(unittest.TestCase):


class TestVarembed(unittest.TestCase):
def testLoadVarembedFormat(self):
"""Test storing/loading the entire model."""
model = varembed.VarEmbed.load_varembed_format(vectors=varembed_model_vector_file)
Expand All @@ -43,6 +45,7 @@ def model_sanity(self, model):
self.assertEqual(model.syn0.shape, (model.vocab_size, model.vector_size))
self.assertTrue(model.syn0.shape[0] == len(model.vocab))

@unittest.skipIf(sys.version_info < (2, 7), 'Supported only on Python 2.7 and above')
def testEnsembleMorphemeEmbeddings(self):
"""Test ensembling of Morhpeme Embeddings"""
model = varembed.VarEmbed.load_varembed_format(vectors=varembed_model_vector_file)
Expand All @@ -53,6 +56,13 @@ def testEnsembleMorphemeEmbeddings(self):
# Check syn0 is different for both models.
self.assertFalse(np.allclose(model.syn0, model_with_morphemes.syn0))

@unittest.skipUnless(sys.version_info < (2, 7), 'Test to check throwing exception in Python 2.6 and earlier')
def testEnsembleEmbeddingsThrowsExceptionInPython26(self):
self.assertRaises(Exception,
varembed.VarEmbed.load_varembed_format,vectors=varembed_model_vector_file,
morfessor_model=varembed_model_morfessor_file,
use_morphemes=True)

def testLookup(self):
"""Test lookup of vector for a particular word and list"""
model = varembed.VarEmbed.load_varembed_format(vectors=varembed_model_vector_file)
Expand Down

0 comments on commit bf57058

Please sign in to comment.