Skip to content

Commit 9c832e9

Browse files
committed
update test syntax
1 parent 3309597 commit 9c832e9

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

project-tv-script-generation/problem_unittests.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ def test_create_lookup_tables(create_lookup_tables):
5959
vocab_to_int_word_set = set(vocab_to_int.keys())
6060
int_to_vocab_word_set = set(int_to_vocab.values())
6161

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),\
6363
'vocab_to_int and int_to_vocab don\'t have the same words.' \
6464
'{} found in vocab_to_int, but not in int_to_vocab'.format(vocab_to_int_word_set - int_to_vocab_word_set)
6565
assert not (int_to_vocab_word_set - vocab_to_int_word_set),\
6666
'vocab_to_int and int_to_vocab don\'t have the same words.' \
6767
'{} 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())
7171
int_to_vocab_word_id_set = set(int_to_vocab.keys())
7272

7373
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):
7676
assert not (int_to_vocab_word_id_set - vocab_to_int_word_id_set),\
7777
'vocab_to_int and int_to_vocab don\'t contain the same word ids.' \
7878
'{} 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]
8282

8383
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),
8685
*missmatches[0])
8786

8887
assert len(vocab_to_int) > len(set(test_text))/2,\
@@ -103,24 +102,24 @@ def test_tokenize(token_lookup):
103102
missing_symbols = symbols - set(token_dict.keys())
104103
unknown_symbols = set(token_dict.keys()) - symbols
105104

106-
assert not missing_symbols, \
105+
assert not missing_symbols, \
107106
'Missing symbols: {}'.format(missing_symbols)
108107
assert not unknown_symbols, \
109108
'Unknown symbols: {}'.format(unknown_symbols)
110109

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)]
113112

114113
assert not bad_value_type,\
115114
'Found token as {} type.'.format(bad_value_type[0])
116115

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]
119118
val_has_spaces = [val for val in token_dict.values() if ' ' in val]
120119

121120
assert not key_has_spaces,\
122121
'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,\
124123
'The value "{}" includes spaces. Remove spaces from keys and values'.format(val_has_spaces[0])
125124

126125
# Check for symbols in values
@@ -130,7 +129,7 @@ def test_tokenize(token_lookup):
130129
if symbol in val:
131130
symbol_val = (symbol, val)
132131

133-
assert not symbol_val,\
132+
assert not symbol_val,\
134133
'Don\'t use a symbol that will be replaced in your tokens. Found the symbol {} in value {}'.format(*symbol_val)
135134

136135
_print_success_message()
@@ -170,9 +169,9 @@ def test_rnn(RNN, train_on_gpu):
170169
'Batch Size': batch_size,
171170
'Sequence Length': sequence_length,
172171
'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)
176175
assert_condition = hidden[0].size() == correct_hidden_size
177176
assert_message = 'Wrong hidden state size. Expected type {}. Got type {}'.format(correct_hidden_size, hidden[0].size())
178177
assert_test.test(assert_condition, assert_message)
@@ -225,6 +224,6 @@ def test_forward_back_prop(RNN, forward_back_prop, train_on_gpu):
225224
assert mock_decoder.forward_called, 'Forward propagation not called.'
226225
assert mock_autograd_backward.called, 'Backward propagation not called'
227226
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))
229228

230229
_print_success_message()

0 commit comments

Comments
 (0)