diff options
author | Harel Ben-Attia <harelba@gmail.com> | 2014-10-26 11:48:49 -0400 |
---|---|---|
committer | Harel Ben-Attia <harelba@gmail.com> | 2014-10-26 11:48:49 -0400 |
commit | 8d45a4aeb8cc47768368e6cfbed01ea0130dd277 (patch) | |
tree | 8745646487bdf9e3c6c869a59ff2f8a23c413839 | |
parent | ddf52cb04b2bc2afa530396097a2e89b29b94941 (diff) |
Suppressed column count warning when the user provides a specific column count of 1
-rwxr-xr-x | bin/q | 2 | ||||
-rwxr-xr-x | test/test-suite | 63 |
2 files changed, 64 insertions, 1 deletions
@@ -501,7 +501,7 @@ class TableColumnInferer(object): else: raise Exception('Unknown parsing mode %s' % self.mode) - if self.column_count == 1: + if self.column_count == 1 and self.expected_column_count != 1: print >>sys.stderr, "Warning: column count is one - did you provide the correct delimiter?" if self.column_count == 0: raise Exception("Detected a column count of zero... Failing") diff --git a/test/test-suite b/test/test-suite index 2212ff8..87692ae 100755 --- a/test/test-suite +++ b/test/test-suite @@ -92,6 +92,10 @@ combined_quoted_data = '''regular_double_quoted double_double_quoted escaped_dou "this is a quoted value" "this is a quoted value with ""double double quotes""" "this is a quoted value with \\"escaped double quotes\\"" ''' +one_column_data = '''data without commas 1 +data without commas 2 +''' + # Values with leading whitespace sample_data_rows_with_spaces = ['a,1,0', ' b, 2,0', 'c,,0'] sample_data_with_spaces_no_header = "\n".join( @@ -1154,6 +1158,65 @@ class ParsingModeTests(AbstractQTestCase): self.cleanup(tmpfile) + def test_1_column_warning_in_relaxed_mode(self): + tmpfile = self.create_file_with_data(one_column_data) + cmd = '../bin/q -m relaxed "select c1 from %s" -d ,' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(e), 1) + self.assertEquals(len(o),2) + + self.assertEquals(e[0],"Warning: column count is one - did you provide the correct delimiter?") + self.assertEquals(o[0],'data without commas 1') + self.assertEquals(o[1],'data without commas 2') + + self.cleanup(tmpfile) + + def test_1_column_warning_in_strict_mode(self): + tmpfile = self.create_file_with_data(one_column_data) + cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m strict' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(e), 1) + self.assertEquals(len(o),2) + + self.assertEquals(e[0],"Warning: column count is one - did you provide the correct delimiter?") + self.assertEquals(o[0],'data without commas 1') + self.assertEquals(o[1],'data without commas 2') + + self.cleanup(tmpfile) + + + def test_1_column_warning_suppression_in_relaxed_mode_when_column_count_is_specific(self): + tmpfile = self.create_file_with_data(one_column_data) + cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m relaxed -c 1' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(e), 0) + self.assertEquals(len(o),2) + + self.assertEquals(o[0],'data without commas 1') + self.assertEquals(o[1],'data without commas 2') + + self.cleanup(tmpfile) + + def test_1_column_warning_suppression_in_strict_mode_when_column_count_is_specific(self): + tmpfile = self.create_file_with_data(one_column_data) + cmd = '../bin/q -m relaxed "select c1 from %s" -d , -m strict -c 1' % tmpfile.name + retcode, o, e = run_command(cmd) + + self.assertEquals(retcode, 0) + self.assertEquals(len(e), 0) + self.assertEquals(len(o),2) + + self.assertEquals(o[0],'data without commas 1') + self.assertEquals(o[1],'data without commas 2') + + self.cleanup(tmpfile) + def test_fluffy_mode(self): tmpfile = self.create_file_with_data(uneven_ls_output) cmd = '../bin/q -m fluffy "select c9 from %s"' % tmpfile.name |