• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python simplesqlite.SimpleSQLite类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中simplesqlite.SimpleSQLite的典型用法代码示例。如果您正苦于以下问题:Python SimpleSQLite类的具体用法?Python SimpleSQLite怎么用?Python SimpleSQLite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SimpleSQLite类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)]
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:31,代码来源:test_url_subcommand.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:7,代码来源:fixture.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:7,代码来源:test_simplesqlite.py


示例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
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:34,代码来源:test_url_subcommand.py


示例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
开发者ID:yedan2010,项目名称:SimpleSQLite,代码行数:26,代码来源:test_from_file.py


示例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)]
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:28,代码来源:test_file_subcommand.py


示例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")]
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:27,代码来源:test_file_subcommand.py


示例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
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:28,代码来源:test_file_subcommand.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:7,代码来源:test_simplesqlite.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:8,代码来源:fixture.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:9,代码来源:fixture.py


示例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"
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:10,代码来源:test_simplesqlite.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:11,代码来源:test_simplesqlite.py


示例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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:11,代码来源:test_simplesqlite.py


示例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,
            )
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:12,代码来源:test_simplesqlite.py


示例16: test_normal_add_primary_key_column

    def test_normal_add_primary_key_column(self, tmpdir):
        p = tmpdir.join("tmp.db")
        con = SimpleSQLite(str(p), "w")

        table_name = "table1"
        con.create_table_from_data_matrix(
            table_name=table_name,
            attr_names=["AA", "BB"],
            data_matrix=[["a", 11], ["bb", 12]],
            add_primary_key_column=True,
        )
        assert con.select_as_tabledata(table_name) == TableData(
            table_name=table_name, headers=["id", "AA", "BB"], rows=[[1, "a", 11], [2, "bb", 12]]
        )
        assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "id"

        table_name = "table2"
        con.create_table_from_data_matrix(
            table_name=table_name,
            attr_names=["AA", "BB"],
            data_matrix=[["a", 11], ["bb", 12]],
            primary_key="pkey",
            add_primary_key_column=True,
        )
        assert con.select_as_tabledata(table_name) == TableData(
            table_name=table_name, headers=["pkey", "AA", "BB"], rows=[[1, "a", 11], [2, "bb", 12]]
        )
        assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "pkey"
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:28,代码来源:test_simplesqlite.py


示例17: test_normal_multi_file_same_table_same_structure

    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
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:45,代码来源:test_file_subcommand.py


示例18: con_ro

def con_ro(tmpdir):
    p = tmpdir.join("tmp_readonly.db")
    con = SimpleSQLite(str(p), "w")

    con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
    con.close()
    con.connect(str(p), "r")

    return con
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:9,代码来源:fixture.py


示例19: test_normal_format_ssv

    def test_normal_format_ssv(self):
        db_path = "test_ssv.sqlite"
        runner = CliRunner()

        with runner.isolated_filesystem():
            file_path = valid_ssv_file()
            result = runner.invoke(cmd, ["-o", db_path, "file", file_path, "--format", "ssv"])
            print_traceback(result)

            assert result.exit_code == ExitCode.SUCCESS

            con = SimpleSQLite(db_path, "r")
            data = con.select_as_tabledata(table_name="ssv")
            expected = (
                "table_name=ssv, "
                "headers=[USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND], "
                "cols=11, rows=5"
            )

            assert str(data) == expected
开发者ID:thombashi,项目名称:sqlitebiter,代码行数:20,代码来源:test_file_subcommand.py


示例20: test_normal_file

    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
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:26,代码来源:test_simplesqlite.py



注:本文中的simplesqlite.SimpleSQLite类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sqlquery.SqlQuery类代码示例发布时间:2022-05-27
下一篇:
Python simpleplot.plot_lines函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap