本文整理汇总了Python中tests.utils.stdin_as_string函数的典型用法代码示例。如果您正苦于以下问题:Python stdin_as_string函数的具体用法?Python stdin_as_string怎么用?Python stdin_as_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stdin_as_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_geojson_no_inference
def test_geojson_no_inference(self):
input_file = six.StringIO(
'{"a": 1, "b": 2, "type": "FeatureCollection", "features": [{"geometry": {}, "properties": {"a": 1, "b": 2, "c": 3}}]}'
)
with stdin_as_string(input_file):
self.assertLines(["--no-inference", "-f", "geojson"], ["id,a,b,c,geojson", ",1,2,3,{}"])
示例2: test_ndjson_no_inference
def test_ndjson_no_inference(self):
input_file = six.StringIO('{"a": 1, "b": 2, "c": 3}')
with stdin_as_string(input_file):
self.assertLines(['--no-inference', '-f', 'ndjson'], [
'a,b,c',
'1,2,3',
])
示例3: test_stdin_and_filename
def test_stdin_and_filename(self):
input_file = six.StringIO("a,b,c\n1,2,3\n")
with stdin_as_string(input_file):
sql = self.get_output(['-', 'examples/dummy.csv'])
self.assertTrue('CREATE TABLE stdin' in sql)
self.assertTrue('CREATE TABLE dummy' in sql)
示例4: test_query_empty
def test_query_empty(self):
input_file = six.StringIO()
with stdin_as_string(input_file):
output = self.get_output(['--query', 'SELECT 1'])
self.assertEqual(output, '1\n1\n')
input_file.close()
示例5: test_csv_datetime_inference
def test_csv_datetime_inference(self):
input_file = six.StringIO('a\n2015-01-01T00:00:00Z')
with stdin_as_string(input_file):
self.assertLines(['-f', 'csv'], [
'a',
'2015-01-01T00:00:00+00:00',
])
示例6: test_fixed_no_inference
def test_fixed_no_inference(self):
input_file = six.StringIO(' 1 2 3')
with stdin_as_string(input_file):
self.assertLines(['--no-inference', '-f', 'fixed', '--schema', 'examples/testfixed_schema_no_inference.csv'], [
'a,b,c',
'1,2,3',
])
示例7: test_stdin_with_query
def test_stdin_with_query(self):
input_file = six.StringIO("select cast(3.1415 * 13.37 as integer) as answer")
with stdin_as_string(input_file):
csv = self.get_output(["--query", "select 6*9 as question"])
self.assertTrue("question" in csv)
self.assertTrue("42" not in csv)
示例8: test_escapechar
def test_escapechar(self):
input_file = six.StringIO('a,b,c\n1"2,3,4\n')
with stdin_as_string(input_file):
self.assertLines(['-P', '#', '-U', '3'], [
'a,b,c',
'1#"2,3,4',
])
示例9: test_quoting
def test_quoting(self):
input_file = six.StringIO('a,b,c\n1*2,3,4\n')
with stdin_as_string(input_file):
self.assertLines(['-Q', '*', '-U', '0', '-B'], [
'a,b,c',
'*1**2*,3,4',
])
示例10: test_stdin
def test_stdin(self):
input_file = six.StringIO('a,b,c\n4,5,6\n1,2,3\n')
with stdin_as_string(input_file):
self.assertLines([], [
'a,b,c',
'1,2,3',
'4,5,6',
])
示例11: test_empty_with_query
def test_empty_with_query(self):
input_file = six.StringIO()
with stdin_as_string(input_file):
output_file = six.StringIO()
utility = CSVSQL(['--query', 'select 1'], output_file)
utility.run()
output_file.close()
input_file.close()
示例12: test_doublequote
def test_doublequote(self):
input_file = six.StringIO('a\n"a ""quoted"" string"')
with stdin_as_string(input_file):
self.assertLines(['-P', '#', '-B'], [
'a',
'a #"quoted#" string',
])
input_file.close()
示例13: test_quotechar
def test_quotechar(self):
input_file = six.StringIO('a,b,c\n1*2,3,4\n')
with stdin_as_string(input_file):
self.assertLines(['-Q', '*'], [
'a,b,c',
'*1**2*,3,4',
])
input_file.close()
示例14: test_stdin
def test_stdin(self):
input_file = six.StringIO('a,b,c\n1,2,3\n')
with stdin_as_string(input_file):
sql = self.get_output(['--table', 'foo'])
self.assertTrue('CREATE TABLE foo' in sql)
self.assertTrue('a INTEGER NOT NULL' in sql)
self.assertTrue('b INTEGER NOT NULL' in sql)
self.assertTrue('c INTEGER NOT NULL' in sql)
示例15: test_stdin_with_file_and_query
def test_stdin_with_file_and_query(self):
input_file = six.StringIO('select cast(3.1415 * 13.37 as integer) as answer')
with stdin_as_string(input_file):
csv = self.get_output(['examples/test.sql', '--query', 'select 6*9 as question'])
self.assertTrue('question' in csv)
self.assertTrue('54' in csv)
input_file.close()