本文整理汇总了Python中simplesqlite.SimpleSQLite类的典型用法代码示例。如果您正苦于以下问题:Python SimpleSQLite类的具体用法?Python SimpleSQLite怎么用?Python SimpleSQLite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleSQLite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_normal_type_hint_header
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)]
示例2: con
def con(tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
return con
示例3: test_normal
def test_normal(self, tmpdir, value, expected):
p_db = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_tabledata(value)
assert con.select_as_dict(table_name=value.table_name) == expected
示例4: test_normal_json
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
示例5: test_smoke
def test_smoke(self, tmpdir, filename):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
test_data_file_path = os.path.join(
os.path.dirname(__file__), "data", filename)
loader = ptr.TableFileLoader(test_data_file_path)
success_count = 0
for tabledata in loader.load():
if tabledata.is_empty():
continue
print(ptw.dump_tabledata(tabledata))
try:
con.create_table_from_tabledata(
ptr.SQLiteTableDataSanitizer(tabledata).sanitize())
success_count += 1
except ValueError as e:
print(e)
con.commit()
assert success_count > 0
示例6: test_normal_type_hint_header
def test_normal_type_hint_header(self):
runner = CliRunner()
basename = "type_hint_header"
file_path = "{}.csv".format(basename)
db_path = "{}.sqlite".format(basename)
with runner.isolated_filesystem():
with open(file_path, "w") as f:
f.write(
dedent(
"""\
"a text","b integer","c real"
1,"1","1.1"
2,"2","1.2"
3,"3","1.3"
"""
)
)
f.flush()
result = runner.invoke(cmd, ["--type-hint-header", "-o", db_path, "file", file_path])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
tbldata = con.select_as_tabledata(basename)
assert tbldata.headers == ["a text", "b integer", "c real"]
assert tbldata.rows == [("1", 1, 1.1), ("2", 2, 1.2), ("3", 3, 1.3)]
示例7: test_normal_no_type_inference
def test_normal_no_type_inference(self):
runner = CliRunner()
basename = "no_type_inference"
file_path = "{}.csv".format(basename)
db_path = "{}.sqlite".format(basename)
with runner.isolated_filesystem():
with open(file_path, "w") as f:
f.write(
dedent(
"""\
"a","b"
11,"xyz"
22,"abc"
"""
)
)
f.flush()
result = runner.invoke(cmd, ["--no-type-inference", "-o", db_path, "file", file_path])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
tbldata = con.select_as_tabledata(basename)
assert tbldata.headers == ["a", "b"]
assert tbldata.rows == [("11", "xyz"), ("22", "abc")]
示例8: test_normal_complex_json
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
示例9: test_normal_empty_header
def test_normal_empty_header(self, tmpdir, table_name, attr_names, data_matrix, expected):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例10: con_profile
def con_profile(tmpdir):
p = tmpdir.join("tmp_profile.db")
con = SimpleSQLite(str(p), "w", profile=True)
con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
con.commit()
return con
示例11: con_mix
def con_mix(tmpdir):
p = tmpdir.join("tmp_mixed_data.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(
TEST_TABLE_NAME, ["attr_i", "attr_f", "attr_s"], [[1, 2.2, "aa"], [3, 4.4, "bb"]]
)
return con
示例12: test_normal_primary_key
def test_normal_primary_key(self, tmpdir, table_name, attr_names, data_matrix, expected):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = TEST_TABLE_NAME
con.create_table_from_data_matrix(
table_name, attr_names, data_matrix, primary_key=attr_names[0]
)
assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "AA"
示例13: test_normal_symbol_header
def test_normal_symbol_header(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = "symbols"
attr_names = ["a!bc#d$e%f&gh(i)j", "[email protected][m]n{o}p;q:r_s.t/u"]
data_matrix = [{"ABCD>8.5": "aaa", "ABCD<8.5": 0}, {"ABCD>8.5": "bbb", "ABCD<8.5": 9}]
expected = ["a!bc#d$e%f&gh(i)j", "[email protected][m]n{o}p;q:r_s.t/u"]
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例14: test_normal_number_header
def test_normal_number_header(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = "numbers"
attr_names = [1, 123456789]
data_matrix = [[1, 2], [1, 2]]
expected = ["1", "123456789"]
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例15: test_except_add_primary_key_column
def test_except_add_primary_key_column(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
with pytest.raises(ValueError):
con.create_table_from_data_matrix(
table_name="specify existing attr as a primary key",
attr_names=["AA", "BB"],
data_matrix=[["a", 11], ["bb", 12]],
primary_key="AA",
add_primary_key_column=True,
)