@@ -88,7 +88,43 @@ def test_parse_column_names(text, expected_column_names):
88
88
("('test'),('test')" , (("test" ,), ("test" ,))),
89
89
("(1,2),(3,4)," , ((1 , 2 ), (3 , 4 ))),
90
90
("(TRUE),(FALSE),(NULL)" , ((True ,), (False ,), (None ,))),
91
+ ("(x')" , ()), # Invalid data
91
92
),
92
93
)
93
94
def test_parse_values (text , expected_values ):
94
95
assert tuple (parse_values (text )) == expected_values
96
+
97
+
98
+ @pytest .mark .parametrize ('config_type' , [
99
+ 'no-config' , 'empty-config' , 'single-column-config' ])
100
+ @pytest .mark .parametrize ('data_label' , ['ok' , 'invalid' ])
101
+ def test_optimizations (config_type , data_label ):
102
+ if config_type == 'no-config' :
103
+ config = None
104
+ decoder_call_count = 0
105
+ else :
106
+ config = Configuration ()
107
+ if config_type == 'empty-config' :
108
+ decoder_call_count = 0
109
+ else :
110
+ assert config_type == 'single-column-config'
111
+ config .sanitizers ["test.notes" ] = (lambda x : x )
112
+ decoder_call_count = 3 # Number of rows in test table
113
+
114
+ data = {
115
+ 'ok' : MOCK_MYSQLDUMP_OUTPUT ,
116
+ 'invalid' : INVALID_MOCK_MYSQLDUMP_OUTPUT ,
117
+ }[data_label ]
118
+
119
+ should_raise = (
120
+ config_type == 'single-column-config'
121
+ and data_label == 'invalid' )
122
+
123
+ dump_stream = io .BytesIO (data )
124
+ if should_raise :
125
+ with pytest .raises (ValueError ):
126
+ list (sanitize_from_stream (dump_stream , config ))
127
+ else :
128
+ expected_output = data .decode ('utf-8' ).splitlines ()
129
+ result = list (sanitize_from_stream (dump_stream , config ))
130
+ assert result == expected_output
0 commit comments