@@ -59,15 +59,15 @@ def test_create_lookup_tables(create_lookup_tables):
59
59
vocab_to_int_word_set = set (vocab_to_int .keys ())
60
60
int_to_vocab_word_set = set (int_to_vocab .values ())
61
61
62
- assert not (vocab_to_int_word_set - int_to_vocab_word_set ),\
62
+ assert not (vocab_to_int_word_set - int_to_vocab_word_set ),\
63
63
'vocab_to_int and int_to_vocab don\' t have the same words.' \
64
64
'{} found in vocab_to_int, but not in int_to_vocab' .format (vocab_to_int_word_set - int_to_vocab_word_set )
65
65
assert not (int_to_vocab_word_set - vocab_to_int_word_set ),\
66
66
'vocab_to_int and int_to_vocab don\' t have the same words.' \
67
67
'{} found in int_to_vocab, but not in vocab_to_int' .format (int_to_vocab_word_set - vocab_to_int_word_set )
68
-
69
- # Make sure the dicts have the same word ids
70
- vocab_to_int_word_id_set = set (vocab_to_int .values ())
68
+
69
+ # Make sure the dicts have the same word ids
70
+ vocab_to_int_word_id_set = set (vocab_to_int .values ())
71
71
int_to_vocab_word_id_set = set (int_to_vocab .keys ())
72
72
73
73
assert not (vocab_to_int_word_id_set - int_to_vocab_word_id_set ),\
@@ -76,13 +76,12 @@ def test_create_lookup_tables(create_lookup_tables):
76
76
assert not (int_to_vocab_word_id_set - vocab_to_int_word_id_set ),\
77
77
'vocab_to_int and int_to_vocab don\' t contain the same word ids.' \
78
78
'{} found in int_to_vocab, but not in vocab_to_int' .format (int_to_vocab_word_id_set - vocab_to_int_word_id_set )
79
-
80
- # Make sure the dicts make the same lookup
81
- missmatches = [(word , id , id , int_to_vocab [id ]) for word , id in vocab_to_int .items () if int_to_vocab [id ] != word ]
79
+
80
+ # Make sure the dicts make the same lookup
81
+ missmatches = [(word , id , id , int_to_vocab [id ]) for word , id in vocab_to_int .items () if int_to_vocab [id ] != word ]
82
82
83
83
assert not missmatches ,\
84
- 'Found {} missmatche(s). First missmatch: vocab_to_int[{}] = {} and int_to_vocab[{}] = {}' .format (
85
- len (missmatches ),
84
+ 'Found {} missmatche(s). First missmatch: vocab_to_int[{}] = {} and int_to_vocab[{}] = {}' .format (len (missmatches ),
86
85
* missmatches [0 ])
87
86
88
87
assert len (vocab_to_int ) > len (set (test_text ))/ 2 ,\
@@ -103,24 +102,24 @@ def test_tokenize(token_lookup):
103
102
missing_symbols = symbols - set (token_dict .keys ())
104
103
unknown_symbols = set (token_dict .keys ()) - symbols
105
104
106
- assert not missing_symbols , \
105
+ assert not missing_symbols , \
107
106
'Missing symbols: {}' .format (missing_symbols )
108
107
assert not unknown_symbols , \
109
108
'Unknown symbols: {}' .format (unknown_symbols )
110
109
111
- # Check values type
112
- bad_value_type = [type (val ) for val in token_dict .values () if not isinstance (val , str )]
110
+ # Check values type
111
+ bad_value_type = [type (val ) for val in token_dict .values () if not isinstance (val , str )]
113
112
114
113
assert not bad_value_type ,\
115
114
'Found token as {} type.' .format (bad_value_type [0 ])
116
115
117
- # Check for spaces
118
- key_has_spaces = [k for k in token_dict .keys () if ' ' in k ]
116
+ # Check for spaces
117
+ key_has_spaces = [k for k in token_dict .keys () if ' ' in k ]
119
118
val_has_spaces = [val for val in token_dict .values () if ' ' in val ]
120
119
121
120
assert not key_has_spaces ,\
122
121
'The key "{}" includes spaces. Remove spaces from keys and values' .format (key_has_spaces [0 ])
123
- assert not val_has_spaces ,\
122
+ assert not val_has_spaces ,\
124
123
'The value "{}" includes spaces. Remove spaces from keys and values' .format (val_has_spaces [0 ])
125
124
126
125
# Check for symbols in values
@@ -130,7 +129,7 @@ def test_tokenize(token_lookup):
130
129
if symbol in val :
131
130
symbol_val = (symbol , val )
132
131
133
- assert not symbol_val ,\
132
+ assert not symbol_val ,\
134
133
'Don\' t use a symbol that will be replaced in your tokens. Found the symbol {} in value {}' .format (* symbol_val )
135
134
136
135
_print_success_message ()
@@ -170,9 +169,9 @@ def test_rnn(RNN, train_on_gpu):
170
169
'Batch Size' : batch_size ,
171
170
'Sequence Length' : sequence_length ,
172
171
'Input' : b })
173
-
174
- # initialization
175
- correct_hidden_size = (n_layers , batch_size , hidden_dim )
172
+
173
+ # initialization
174
+ correct_hidden_size = (n_layers , batch_size , hidden_dim )
176
175
assert_condition = hidden [0 ].size () == correct_hidden_size
177
176
assert_message = 'Wrong hidden state size. Expected type {}. Got type {}' .format (correct_hidden_size , hidden [0 ].size ())
178
177
assert_test .test (assert_condition , assert_message )
@@ -225,6 +224,6 @@ def test_forward_back_prop(RNN, forward_back_prop, train_on_gpu):
225
224
assert mock_decoder .forward_called , 'Forward propagation not called.'
226
225
assert mock_autograd_backward .called , 'Backward propagation not called'
227
226
assert mock_decoder_optimizer .step .called , 'Optimization step not performed'
228
- assert type (loss ) == float , 'Wrong return type. Exptected {}, got {}' .format (float , type (loss ))
227
+ assert type (loss ) == float , 'Wrong return type. Expected {}, got {}' .format (float , type (loss ))
229
228
230
229
_print_success_message ()
0 commit comments