def test_whenInstanciatedWithPath_thenShouldLoadFasttextModel(self): with patch( 'deepparse.embeddings_models.fasttext_embeddings_model.load_fasttext_embeddings', return_value=self.model) as loader: self.embeddings_model = FastTextEmbeddingsModel(self.a_path) loader.assert_called_with(self.a_path)
def test_whenCalledToEmbed_thenShouldCallLoadedModel(self): with patch("deepparse.embeddings_models.fasttext_embeddings_model.load_fasttext_embeddings", return_value=self.model): self.embeddings_model = FastTextEmbeddingsModel(self.a_path, verbose=self.verbose) self.embeddings_model(self.a_word) self.model.__getitem__.assert_called_with(self.a_word)
def test_whenInstantiatedWithPath_thenShouldLoadFasttextModel(self): with patch( "deepparse.embeddings_models.fasttext_embeddings_model.load_fasttext_embeddings", return_value=self.model, ) as loader: _ = FastTextEmbeddingsModel(self.a_path, verbose=self.verbose) loader.assert_called_with(self.a_path)
def test_givenADimOf9Windows_whenAskDimProperty_thenReturnProperDim(self): with patch( "deepparse.embeddings_models.fasttext_embeddings_model.load_facebook_vectors", return_value=self.model, ): embeddings_model = FastTextEmbeddingsModel(self.a_path, verbose=self.verbose) actual = embeddings_model.dim expected = self.dim self.assertEqual(actual, expected)
def test_whenInstantiatedOnMacOS_thenShouldLoadFasttextModel( self, platform_mock): platform_mock.system().__eq__.return_value = False with patch( "deepparse.embeddings_models.fasttext_embeddings_model.load_fasttext_embeddings", return_value=self.model, ) as loader: with platform_mock: self.embeddings_model = FastTextEmbeddingsModel( self.a_path, verbose=self.verbose) loader.assert_called_with(self.a_path)
def test_givenAWindowsOS_whenFasttextModelCollateFnInDataLoaderNumWorkers2_thenWorkProperly( self, ): model = FastTextEmbeddingsModel(self.a_fasttext_model_path, verbose=self.verbose) data_transform = MockedDataTransform(model) data_loader = DataLoader( self.training_container, collate_fn=data_transform.collate_fn, batch_size=32, num_workers=2, ) dataset = [] for data in data_loader: dataset.append(data) self.assertGreater(len(dataset), 0)
def test_givenAWindowsOS_whenFasttextModelCollateFnInDataLoaderForNotWindows_thenRaiseError(self, platform_mock): platform_mock.system().__eq__.return_value = True with platform_mock: model = FastTextEmbeddingsModel(self.a_fasttext_model_path, verbose=self.verbose) data_transform = MockedDataTransform(model) data_loader = DataLoader( self.training_container, collate_fn=data_transform.collate_fn, batch_size=32, num_workers=0, ) with self.assertRaises(TypeError): for _ in data_loader: pass
def test_givenAWindowsOS_whenFasttextModelCollateFnInDataLoaderEvenWithWindowsSetup_thenWorkProperly( self, platform_mock ): platform_mock.system().__eq__.return_value = True with platform_mock: model = FastTextEmbeddingsModel(self.a_fasttext_model_path, verbose=self.verbose) data_transform = MockedDataTransform(model) data_loader = DataLoader( self.training_container, collate_fn=data_transform.collate_fn, batch_size=32, num_workers=0, ) dataset = [] for data in data_loader: dataset.append(data) self.assertGreater(len(dataset), 0)
def test_givenANotWindowsOS_whenFasttextModelInit_thenLoadWithProperFunction(self): model = FastTextEmbeddingsModel(self.a_fasttext_model_path, verbose=self.verbose) self.assertIsInstance(model.model, _FastText)