本文整理汇总了Python中simplesqlite.SimpleSQLite.fetch_table_names方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleSQLite.fetch_table_names方法的具体用法?Python SimpleSQLite.fetch_table_names怎么用?Python SimpleSQLite.fetch_table_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simplesqlite.SimpleSQLite
的用法示例。
在下文中一共展示了SimpleSQLite.fetch_table_names方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_normal_json
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_json(self):
url = "https://example.com/complex_json.json"
responses.add(
responses.GET,
url,
body=complex_json,
content_type="text/plain; charset=utf-8",
status=200,
)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cmd, ["-o", self.db_path, "url", url])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(self.db_path, "r")
expected = set(
[
"ratings",
"screenshots_4",
"screenshots_3",
"screenshots_5",
"screenshots_1",
"screenshots_2",
"tags",
"versions",
"root",
SourceInfo.get_table_name(),
]
)
assert set(con.fetch_table_names()) == expected
示例2: test_normal_file
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_file(
self,
tmpdir,
json_text,
filename,
table_name,
expected_table_name,
expected_attr_names,
expected_data_matrix,
):
p_db = tmpdir.join("tmp.db")
p_json = tmpdir.join(filename)
with open(str(p_json), "w") as f:
f.write(json_text)
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_json(str(p_json), table_name)
assert con.fetch_table_names() == [expected_table_name]
assert expected_attr_names == con.fetch_attr_names(expected_table_name)
result = con.select(select="*", table_name=expected_table_name)
result_matrix = result.fetchall()
assert len(result_matrix) == 3
assert result_matrix == expected_data_matrix
示例3: test_normal_type_hint_header
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_type_hint_header(self):
url = "https://example.com/type_hint_header.csv"
responses.add(
responses.GET,
url,
body=dedent(
"""\
"a text","b integer","c real"
1,"1","1.1"
2,"2","1.2"
3,"3","1.3"
"""
),
content_type="text/plain; charset=utf-8",
status=200,
)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cmd, ["--type-hint-header", "-o", self.db_path, "url", url])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(self.db_path, "r")
table_names = list(set(con.fetch_table_names()) - set([SourceInfo.get_table_name()]))
# table name may change test execution order
tbldata = con.select_as_tabledata(table_names[0])
assert tbldata.headers == ["a text", "b integer", "c real"]
assert tbldata.rows == [("1", 1, 1.1), ("2", 2, 1.2), ("3", 3, 1.3)]
示例4: test_normal_complex_json
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_complex_json(self):
db_path = "test_complex_json.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
file_path = valid_complex_json_file()
result = runner.invoke(cmd, ["-o", db_path, "file", file_path])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
expected = set(
[
"ratings",
"screenshots_4",
"screenshots_3",
"screenshots_5",
"screenshots_1",
"screenshots_2",
"tags",
"versions",
"root",
SourceInfo.get_table_name(),
]
)
assert set(con.fetch_table_names()) == expected
示例5: test_normal_multi_file_same_table_same_structure
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_multi_file_same_table_same_structure(self):
db_path = "test.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
files = [valid_json_multi_file_2_1(), valid_json_multi_file_2_2()]
result = runner.invoke(cmd, ["-o", db_path, "file"] + files)
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
expected_tables = ["multij2", SourceInfo.get_table_name()]
actual_tables = con.fetch_table_names()
print_test_result(expected=expected_tables, actual=actual_tables)
assert set(actual_tables) == set(expected_tables)
expected_data_table = {
"multij2": [
(1, 4.0, "a"),
(2, 2.1, "bb"),
(3, 120.9, "ccc"),
(1, 4.0, "a"),
(2, 2.1, "bb"),
(3, 120.9, "ccc"),
]
}
for table in con.fetch_table_names():
if table == SourceInfo.get_table_name():
continue
expected_data = expected_data_table.get(table)
actual_data = con.select("*", table_name=table).fetchall()
message = "table={}, expected={}, actual={}".format(
table, expected_data, actual_data
)
print("--- table: {} ---".format(table))
print_test_result(expected=expected_data, actual=actual_data)
assert expected_data == actual_data, message
示例6: test_normal
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal(self, tmpdir, value, type_hints, expected):
p_db = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_tabledata(value)
assert con.fetch_table_names() == [value.table_name]
assert con.fetch_attr_names(value.table_name) == value.headers
actual = con.select_as_tabledata(
columns=value.headers, table_name=value.table_name, type_hints=type_hints
)
assert actual.value_matrix == expected
示例7: test_normal_text
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_text(
self,
tmpdir,
csv_text,
table_name,
attr_names,
expected_table_name,
expected_attr_names,
expected_data_matrix,
):
p_db = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_csv(csv_text, table_name, attr_names)
assert con.fetch_table_names() == [expected_table_name]
assert expected_attr_names == con.fetch_attr_names(expected_table_name)
result = con.select(select="*", table_name=expected_table_name)
result_matrix = result.fetchall()
assert len(result_matrix) == 3
assert result_matrix == expected_data_matrix
示例8: open
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
# create sample data file ---
with open(file_path, "w") as f:
f.write(
"""{
"table_a" : [
{"attr_b": 4, "attr_c": "a", "attr_a": 1},
{"attr_b": 2.1, "attr_c": "bb", "attr_a": 2},
{"attr_b": 120.9, "attr_c": "ccc", "attr_a": 3}
],
"table_b" : [
{"a": 1, "b": 4},
{"a": 2 },
{"a": 3, "b": 120.9}
]
}"""
)
# create table ---
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_json(file_path)
# output ---
for table_name in con.fetch_table_names():
print("table: " + table_name)
print(con.fetch_attr_names(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
print(record)
print()
示例9: test_normal_append
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_append(self):
db_path = "test.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
files = [valid_json_multi_file_2_1()]
table_name = "multij2"
expected_tables = [table_name, SourceInfo.get_table_name()]
# first execution without --append option (new) ---
result = runner.invoke(cmd, ["-o", db_path, "file"] + files)
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
actual_tables = con.fetch_table_names()
print_test_result(expected=expected_tables, actual=actual_tables)
assert set(actual_tables) == set(expected_tables)
actual_data = con.select("*", table_name=table_name).fetchall()
expected_data = [(1, 4.0, "a"), (2, 2.1, "bb"), (3, 120.9, "ccc")]
print_test_result(expected=expected_data, actual=actual_data)
assert expected_data == actual_data
# second execution with --append option ---
result = runner.invoke(cmd, ["-o", db_path, "--append", "file"] + files)
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
actual_tables = con.fetch_table_names()
print_test_result(expected=expected_tables, actual=actual_tables)
assert set(actual_tables) == set(expected_tables)
actual_data = con.select("*", table_name=table_name).fetchall()
expected_data = [
(1, 4.0, "a"),
(2, 2.1, "bb"),
(3, 120.9, "ccc"),
(1, 4.0, "a"),
(2, 2.1, "bb"),
(3, 120.9, "ccc"),
]
print_test_result(expected=expected_data, actual=actual_data)
assert expected_data == actual_data
# third execution without --append option (overwrite) ---
result = runner.invoke(cmd, ["-o", db_path, "file"] + files)
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
actual_tables = con.fetch_table_names()
print_test_result(expected=expected_tables, actual=actual_tables)
assert set(actual_tables) == set(expected_tables)
actual_data = con.select("*", table_name=table_name).fetchall()
expected_data = [(1, 4.0, "a"), (2, 2.1, "bb"), (3, 120.9, "ccc")]
print_test_result(expected=expected_data, actual=actual_data)
assert expected_data == actual_data
示例10: test_normal_multi_file_different_table
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
def test_normal_multi_file_different_table(self):
db_path = "test.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
files = [
valid_json_single_file(),
invalid_json_single_file(),
valid_json_multi_file_1(),
valid_json_kv_file(),
valid_csv_file_1_1(),
valid_csv_file_2_1(),
invalid_csv_file(),
valid_tsv_file(),
invalid_tsv_file(),
valid_excel_file(),
invalid_excel_file_1(),
invalid_excel_file_2(),
valid_html_file(),
invalid_html_file(),
valid_ltsv_file(),
invalid_ltsv_file(),
valid_markdown_file(),
not_supported_format_file(),
]
result = runner.invoke(cmd, ["-o", db_path, "file"] + files)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
expected_tables = [
"singlejson",
"multij1",
"multij2",
"valid_kv",
"csv_a",
"rename_insert",
"excel_sheet_a",
"excel_sheet_c",
"excel_sheet_d",
"valid_ltsv_a",
"testtitle_tablename",
"testtitle_html2",
"tsv_a",
"valid_mdtable_markdown1",
SourceInfo.get_table_name(),
]
actual_tables = con.fetch_table_names()
print_test_result(expected=expected_tables, actual=actual_tables)
assert set(actual_tables) == set(expected_tables)
expected_data_table = {
"singlejson": [(1, 4.0, "a"), (2, 2.1, "bb"), (3, 120.9, "ccc")],
"multij1": [(1, 4.0, "a"), (2, 2.1, "bb"), (3, 120.9, "ccc")],
"multij2": [(1, 4.0), (2, None), (3, 120.9)],
"valid_kv": [("json_b", "hoge"), ("json_c", "bar")],
"csv_a": [(1, 4.0, "a"), (2, 2.1, "bb"), (3, 120.9, "ccc")],
"rename_insert": [
(1, 55, "D Sam", 31, "Raven"),
(2, 36, "J Ifdgg", 30, "Raven"),
(3, 91, "K Wedfb", 28, "Raven"),
],
"excel_sheet_a": [(1.0, 1.1, "a"), (2.0, 2.2, "bb"), (3.0, 3.3, "cc")],
"excel_sheet_c": [(1, 1.1, "a"), (2, "", "bb"), (3, 3.3, "")],
"excel_sheet_d": [(1, 1.1, "a"), (2, "", "bb"), (3, 3.3, "")],
"testtitle_tablename": [(1, 123.1, "a"), (2, 2.2, "bb"), (3, 3.3, "ccc")],
"valid_ltsv_a": [
(1, 123.1, u'"ltsv0"', 1.0, u'"1"'),
(2, 2.2, u'"ltsv1"', 2.2, u'"2.2"'),
(3, 3.3, u'"ltsv2"', 3.0, u'"cccc"'),
],
"testtitle_html2": [(1, 123.1), (2, 2.2), (3, 3.3)],
"tsv_a": [(1, 4.0, "tsv0"), (2, 2.1, "tsv1"), (3, 120.9, "tsv2")],
"valid_mdtable_markdown1": [(1, 123.1, "a"), (2, 2.2, "bb"), (3, 3.3, "ccc")],
}
for table in con.fetch_table_names():
if table == SourceInfo.get_table_name():
continue
result = con.select("*", table_name=table)
expected_data = expected_data_table.get(table)
actual_data = result.fetchall()
message = "table={}, expected={}, actual={}".format(
table, expected_data, actual_data
)
print("--- table: {} ---".format(table))
print_test_result(expected=expected_data, actual=actual_data)
assert sorted(expected_data) == sorted(actual_data), message
示例11: SimpleSQLite
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import fetch_table_names [as 别名]
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
from simplesqlite import SimpleSQLite
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_data_matrix("hoge", ["attr_a", "attr_b"], [[1, "a"], [2, "b"]])
print(con.fetch_table_names())