def test_download_eval_file(self): WHOIS.get_registrar_certification_list.return_value = self._get_registrar_certs( ) FILE_MANAGER.info.return_value = FileInfo( id=2, name='test.html', path='2015/12/9/1', mimetype='text/html', filetype=6, crdate='2015-12-09 16:16:28.598757', size=5) content = "<html><body>The content.</body></html>" FILE_MANAGER.load.return_value.download.return_value = content response = self.client.get( reverse("webwhois:download_evaluation_file", kwargs={"handle": "REG-MOJEID"})) self.assertEqual(response.content, content.encode()) self.assertEqual(response['Content-Type'], 'text/html') self.assertEqual(response['Content-Disposition'], 'attachment; filename="test.html"') self.assertEqual(WHOIS.mock_calls, [call.get_registrar_certification_list()]) self.assertEqual(FILE_MANAGER.mock_calls, [ call.info(2), call.load(2), call.load().download(5), call.load().finalize_download() ])
def test_givenSeq2SeqModelRetrained_whenLoadRetrainedWeights_thenLoadProperly( self, torch_nn_mock, torch_mock): all_layers_params_mock = MagicMock() all_layers_params_mock.__getitem__( ).__len__.return_value = self.decoder_output_size torch_mock.load.return_value = all_layers_params_mock seq2seq_model = Seq2SeqModel( self.a_cpu_device, input_size=self.encoder_input_size_dim, encoder_hidden_size=self.encoder_hidden_size, encoder_num_layers=self.encoder_num_layers, decoder_hidden_size=self.decoder_hidden_size, decoder_num_layers=self.decoder_num_layers, output_size=self.decoder_output_size, verbose=True, ) seq2seq_model._load_weights(self.a_fake_retrain_path) torch_mock.assert_has_calls([ call.load(self.a_fake_retrain_path, map_location=self.a_cpu_device) ]) torch_nn_mock.assert_called() torch_nn_mock.asser_has_calls([call(all_layers_params_mock)])
def test_givenRetrainedWeights_whenInstantiatingAFastTextSeq2SeqModel_thenShouldUseRetrainedWeights( self, load_state_dict_mock, torch_mock): all_layers_params = MagicMock() torch_mock.load.return_value = all_layers_params self.seq2seq_model = FastTextSeq2SeqModel(self.a_torch_device, self.verbose, path_to_retrained_model=self.a_path_to_retrained_model) torch_load_call = [call.load(self.a_path_to_retrained_model, map_location=self.a_torch_device)] torch_mock.assert_has_calls(torch_load_call) load_state_dict_call = [call(all_layers_params)] load_state_dict_mock.assert_has_calls(load_state_dict_call)
def it_adds_a_load_method(utilities, mixed_instance): mixed_instance.load() expect(utilities.mock_calls) == [call.load(mixed_instance)]
def it_adds_a_load_method(utilities, mixed_instance): mixed_instance.load() expect(utilities.mock_calls) == [ call.load(mixed_instance) ]