-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added option to add output header to the output + Tests
- Loading branch information
Showing
2 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -330,6 +330,20 @@ class BasicTests(AbstractQTestCase): | |
|
||
self.cleanup(tmpfile) | ||
|
||
def test_output_header_when_input_header_exists(self): | ||
tmpfile = self.create_file_with_data(sample_data_with_header) | ||
cmd = '../bin/q -d , "select name from %s" -H -O' % tmpfile.name | ||
retcode, o, e = run_command(cmd) | ||
|
||
self.assertEquals(retcode, 0) | ||
self.assertEquals(len(o), 4) | ||
self.assertEquals(o[0],'name') | ||
self.assertEquals(o[1],'a') | ||
self.assertEquals(o[2],'b') | ||
self.assertEquals(o[3],'c') | ||
|
||
self.cleanup(tmpfile) | ||
|
||
def test_generated_column_name_warning_when_header_line_exists(self): | ||
tmpfile = self.create_file_with_data(sample_data_with_header) | ||
cmd = '../bin/q -d , "select c3 from %s" -H' % tmpfile.name | ||
|
@@ -558,6 +572,25 @@ class BasicTests(AbstractQTestCase): | |
self.cleanup(tmp_data_file) | ||
self.cleanup(tmp_query_file) | ||
|
||
def test_output_header_with_non_ascii_names(self): | ||
tmp_data_file = self.create_file_with_data(sample_data_with_header) | ||
tmp_query_file = self.create_file_with_data("select name,'Hr\xc3\xa1\xc4\x8d' Hr\xc3\xa1\xc4\x8d from %s" % tmp_data_file.name,encoding=None) | ||
|
||
cmd = '../bin/q -d , -q %s -H -Q utf-8 -O' % tmp_query_file.name | ||
retcode, o, e = run_command(cmd) | ||
|
||
self.assertEquals(retcode,0) | ||
self.assertEquals(len(o),4) | ||
self.assertEquals(len(e),0) | ||
|
||
self.assertEquals(o[0].decode(SYSTEM_ENCODING), u'name,Hr\xe1\u010d') | ||
self.assertEquals(o[1].decode(SYSTEM_ENCODING), u'a,Hr\xe1\u010d') | ||
self.assertEquals(o[2].decode(SYSTEM_ENCODING), u'b,Hr\xe1\u010d') | ||
self.assertEquals(o[3].decode(SYSTEM_ENCODING), u'c,Hr\xe1\u010d') | ||
|
||
self.cleanup(tmp_data_file) | ||
self.cleanup(tmp_query_file) | ||
|
||
def test_use_query_file_with_query_encoding(self): | ||
tmp_data_file = self.create_file_with_data(sample_data_with_header) | ||
tmp_query_file = self.create_file_with_data("select name,'Hr\xc3\xa1\xc4\x8d' from %s" % tmp_data_file.name,encoding=None) | ||
|
@@ -907,6 +940,16 @@ class SqlTests(AbstractQTestCase): | |
self.assertEquals(o[0], 'ppp [email protected]') | ||
self.assertEquals(o[1], 'ppp [email protected]') | ||
|
||
def test_join_example_with_output_header(self): | ||
cmd = '../bin/q -O "select myfiles.c8 aaa,emails.c2 bbb from ../examples/exampledatafile myfiles join ../examples/group-emails-example emails on (myfiles.c4 = emails.c1) where myfiles.c8 = \'ppp\'"' | ||
retcode, o, e = run_command(cmd) | ||
|
||
self.assertEquals(retcode, 0) | ||
self.assertEquals(len(o), 3) | ||
|
||
self.assertEquals(o[0], 'aaa bbb') | ||
self.assertEquals(o[1], 'ppp [email protected]') | ||
self.assertEquals(o[2], 'ppp [email protected]') | ||
|
||
def suite(): | ||
tl = unittest.TestLoader() | ||
|