@@ -88,7 +88,43 @@ def test_parse_column_names(text, expected_column_names):
8888 ("('test'),('test')" , (("test" ,), ("test" ,))),
8989 ("(1,2),(3,4)," , ((1 , 2 ), (3 , 4 ))),
9090 ("(TRUE),(FALSE),(NULL)" , ((True ,), (False ,), (None ,))),
91+ ("(x')" , ()), # Invalid data
9192 ),
9293)
9394def test_parse_values (text , expected_values ):
9495 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