예제 #1
0
 def test_create_with_existing_file(self, tmp_path):
     path = tmp_path / 'existing'
     path.touch()
     data = [('blah', numpy.array([1, 2]))]
     with pytest.raises(FileExistsError):
         MockEmbFile.create(path, data, overwrite=False)
     MockEmbFile.create(path, data, overwrite=True)
예제 #2
0
 def test_create_warns_for_wrong_vocab_size(self, reference_pairs):
     wrong_vocab_size = REFERENCE_VOCAB_SIZE + 5
     with pytest.warns(UserWarning):
         MockEmbFile.create('fake_path',
                            reference_pairs,
                            vocab_size=wrong_vocab_size)
     _create_called_with = MockEmbFile._create_kwargs
     assert _create_called_with.vocab_size == REFERENCE_VOCAB_SIZE
예제 #3
0
 def test_create_with_iterator(self, reference_pairs):
     MockEmbFile.create('fake_path', iter(reference_pairs))
     _create_called_with = MockEmbFile._create_kwargs
     assert _create_called_with.vocab_size is None
     assert _create_called_with.vector_size == REFERENCE_VECTOR_SIZE
     assert list(_create_called_with.pairs) == reference_pairs
예제 #4
0
 def test_create_with_wrong_type(self):
     with pytest.raises(TypeError):
         # noinspection PyTypeChecker
         MockEmbFile.create('fake_path', word_vectors=5)
예제 #5
0
 def test_create_with_dict(self, reference_dict):
     MockEmbFile.create('fake_path', reference_dict)
     _create_called_with = MockEmbFile._create_kwargs
     assert _create_called_with.vocab_size == REFERENCE_VOCAB_SIZE
     assert _create_called_with.vector_size == REFERENCE_VECTOR_SIZE
     assert _create_called_with.pairs == reference_dict.items()