@@ -92,6 +92,10 @@ combined_quoted_data = '''regular_double_quoted double_double_quoted escaped_dou
9292"this is a quoted value" "this is a quoted value with ""double double quotes""" "this is a quoted value with \\ "escaped double quotes\\ ""
9393'''
9494
95+ one_column_data = '''data without commas 1
96+ data without commas 2
97+ '''
98+
9599# Values with leading whitespace
96100sample_data_rows_with_spaces = ['a,1,0' , ' b, 2,0' , 'c,,0' ]
97101sample_data_with_spaces_no_header = "\n " .join (
@@ -1154,6 +1158,65 @@ class ParsingModeTests(AbstractQTestCase):
11541158
11551159 self .cleanup (tmpfile )
11561160
1161+ def test_1_column_warning_in_relaxed_mode (self ):
1162+ tmpfile = self .create_file_with_data (one_column_data )
1163+ cmd = '../bin/q -m relaxed "select c1 from %s" -d ,' % tmpfile .name
1164+ retcode , o , e = run_command (cmd )
1165+
1166+ self .assertEquals (retcode , 0 )
1167+ self .assertEquals (len (e ), 1 )
1168+ self .assertEquals (len (o ),2 )
1169+
1170+ self .assertEquals (e [0 ],"Warning: column count is one - did you provide the correct delimiter?" )
1171+ self .assertEquals (o [0 ],'data without commas 1' )
1172+ self .assertEquals (o [1 ],'data without commas 2' )
1173+
1174+ self .cleanup (tmpfile )
1175+
1176+ def test_1_column_warning_in_strict_mode (self ):
1177+ tmpfile = self .create_file_with_data (one_column_data )
1178+ cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m strict' % tmpfile .name
1179+ retcode , o , e = run_command (cmd )
1180+
1181+ self .assertEquals (retcode , 0 )
1182+ self .assertEquals (len (e ), 1 )
1183+ self .assertEquals (len (o ),2 )
1184+
1185+ self .assertEquals (e [0 ],"Warning: column count is one - did you provide the correct delimiter?" )
1186+ self .assertEquals (o [0 ],'data without commas 1' )
1187+ self .assertEquals (o [1 ],'data without commas 2' )
1188+
1189+ self .cleanup (tmpfile )
1190+
1191+
1192+ def test_1_column_warning_suppression_in_relaxed_mode_when_column_count_is_specific (self ):
1193+ tmpfile = self .create_file_with_data (one_column_data )
1194+ cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m relaxed -c 1' % tmpfile .name
1195+ retcode , o , e = run_command (cmd )
1196+
1197+ self .assertEquals (retcode , 0 )
1198+ self .assertEquals (len (e ), 0 )
1199+ self .assertEquals (len (o ),2 )
1200+
1201+ self .assertEquals (o [0 ],'data without commas 1' )
1202+ self .assertEquals (o [1 ],'data without commas 2' )
1203+
1204+ self .cleanup (tmpfile )
1205+
1206+ def test_1_column_warning_suppression_in_strict_mode_when_column_count_is_specific (self ):
1207+ tmpfile = self .create_file_with_data (one_column_data )
1208+ cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m strict -c 1' % tmpfile .name
1209+ retcode , o , e = run_command (cmd )
1210+
1211+ self .assertEquals (retcode , 0 )
1212+ self .assertEquals (len (e ), 0 )
1213+ self .assertEquals (len (o ),2 )
1214+
1215+ self .assertEquals (o [0 ],'data without commas 1' )
1216+ self .assertEquals (o [1 ],'data without commas 2' )
1217+
1218+ self .cleanup (tmpfile )
1219+
11571220 def test_fluffy_mode (self ):
11581221 tmpfile = self .create_file_with_data (uneven_ls_output )
11591222 cmd = '../bin/q -m fluffy "select c9 from %s"' % tmpfile .name
0 commit comments