# Path: dsenser/word2vec.py
# class Word2Vec(object):
#     """Class for cached retrieval of word embeddings.
# 
#     """
# 
#     def __init__(self, a_w2v=W2V):
#         """Class cosntructor.
# 
#         Args:
#           a_w2v (gensim.Word2Vec):
#             dictionary with original word embeddings
# 
#         """
#         self._w2v = a_w2v
#         self._cache = {}
#         self.ndim = -1
# 
#     def __contains__(self, a_word):
#         """Proxy method for looking up a word in the resource.
# 
#         Args:
#         a_word (str): word to look up in the resource
# 
#         Returns:
#         (bool):
#         true if the word is present in the underlying resource
# 
#         """
#         if a_word in self._cache:
#             return True
#         elif a_word in self._w2v:
#             self._cache[a_word] = self._w2v[a_word]
#             return True
#         return False
# 
#     def __getitem__(self, a_word):
#         """Proxy method for looking up a word in the resource.
# 
#         Args:
#         a_word (str): word to look up in the resource
# 
#         Returns:
#         (bool):
#         true if the word is present in the underlying resource
# 
#         """
#         if a_word in self._cache:
#             return self._cache[a_word]
#         elif a_word in self._w2v:
#             emb = self._cache[a_word] = self._w2v[a_word]
#             return emb
#         raise KeyError
# 
#     def load(self):
#         """Load the word2vec resource.
# 
#         Args:
#         (void):
# 
#         Returns:
#         (void):
#         load the resource in place
# 
#         """
#         self._w2v.load()
#         self.ndim = self._w2v.resource.vector_size
# 
#     def unload(self):
#         """Unload the word2vec resource.
# 
#         Args:
#         (void):
# 
#         Returns:
#         (void):
#         load the resource in place
# 
#         """
#         self._cache.clear()
#         self._w2v.unload()


from dsenser.word2vec import Word2Vec
from mock import patch, MagicMock
from pytest import fixture
from unittest import TestCase
import pytest
        with patch.object(self.w2v, "_cache", {"tables": 1}):
            assert "tables" in self.w2v

    def test_contains_2(self):
        with patch.object(self.w2v, "_w2v", {"tablez": 1}):
            assert "tablez" in self.w2v
            assert self.w2v["tablez"] == 1

    def test_getitem_0(self):
        with patch.object(self.w2v, "_cache", {"tablex": 0}):
            assert self.w2v["tablex"] == 0

    def test_getitem_1(self):
        with patch.object(self.w2v, "_w2v", {"tabley": 1}):
            assert self.w2v["tabley"] == 1
            assert "tabley" in self.w2v._cache

    def test_getitem_2(self):
        with pytest.raises(KeyError):
            self.w2v["gable"]

    def test_load(self):
        with patch.object(self.w2v, "_w2v"):
            self.w2v._w2v.load = MagicMock()
            self.w2v._w2v.resource = MagicMock()
            self.w2v._w2v.resource.vector_size = DFLT_VEC_SIZE
            self.w2v.load()
            self.w2v._w2v.load.assert_called_once_with()
            assert self.w2v.ndim == DFLT_VEC_SIZE


# Path: dsenser/word2vec.py
# class Word2Vec(object):
#     """Class for cached retrieval of word embeddings.
# 
#     """
# 
#     def __init__(self, a_w2v=W2V):
#         """Class cosntructor.
# 
#         Args:
#           a_w2v (gensim.Word2Vec):
#             dictionary with original word embeddings
# 
#         """
#         self._w2v = a_w2v
#         self._cache = {}
#         self.ndim = -1
# 
#     def __contains__(self, a_word):
#         """Proxy method for looking up a word in the resource.
# 
#         Args:
#         a_word (str): word to look up in the resource
# 
#         Returns:
#         (bool):
#         true if the word is present in the underlying resource
# 
#         """
#         if a_word in self._cache:
#             return True
#         elif a_word in self._w2v:
#             self._cache[a_word] = self._w2v[a_word]
#             return True
#         return False
# 
#     def __getitem__(self, a_word):
#         """Proxy method for looking up a word in the resource.
# 
#         Args:
#         a_word (str): word to look up in the resource
# 
#         Returns:
#         (bool):
#         true if the word is present in the underlying resource
# 
#         """
#         if a_word in self._cache:
#             return self._cache[a_word]
#         elif a_word in self._w2v:
#             emb = self._cache[a_word] = self._w2v[a_word]
#             return emb
#         raise KeyError
# 
#     def load(self):
#         """Load the word2vec resource.
# 
#         Args:
#         (void):
# 
#         Returns:
#         (void):
#         load the resource in place
# 
#         """
#         self._w2v.load()
#         self.ndim = self._w2v.resource.vector_size
# 
#     def unload(self):
#         """Unload the word2vec resource.
# 
#         Args:
#         (void):
# 
#         Returns:
#         (void):
#         load the resource in place
# 
#         """
#         self._cache.clear()
#         self._w2v.unload()


# Path: tests/test_word2vec.py
from dsenser.word2vec import Word2Vec
from mock import patch, MagicMock
from pytest import fixture
from unittest import TestCase
import pytest

        with patch.object(self.w2v, "_cache", {"tables": 1}):
            assert "tables" in self.w2v

    def test_contains_2(self):
        with patch.object(self.w2v, "_w2v", {"tablez": 1}):
            assert "tablez" in self.w2v
            assert self.w2v["tablez"] == 1

    def test_getitem_0(self):
        with patch.object(self.w2v, "_cache", {"tablex": 0}):
            assert self.w2v["tablex"] == 0

    def test_getitem_1(self):
        with patch.object(self.w2v, "_w2v", {"tabley": 1}):
            assert self.w2v["tabley"] == 1
            assert "tabley" in self.w2v._cache

    def test_getitem_2(self):
        with pytest.raises(KeyError):
            self.w2v["gable"]

    def test_load(self):
        with patch.object(self.w2v, "_w2v"):
            self.w2v._w2v.load = MagicMock()
            self.w2v._w2v.resource = MagicMock()
            self.w2v._w2v.resource.vector_size = DFLT_VEC_SIZE
            self.w2v.load()
            self.w2v._w2v.load.assert_called_once_with()
            assert self.w2v.ndim == DFLT_VEC_SIZE


    def test_unload(self):