How to use the pytablewriter.SqliteTableWriter function in pytablewriter

To help you get started, we’ve selected a few pytablewriter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pytablewriter / test / test_writer_factory.py View on Github external
            ["SQLite", ptw.SqliteTableWriter],
            ["tsv", ptw.TsvTableWriter],
            ["TSV", ptw.TsvTableWriter],
            ["toml", ptw.TomlTableWriter],
            ["TOML", ptw.TomlTableWriter],
            ["unicode", ptw.UnicodeTableWriter],
            ["Unicode", ptw.UnicodeTableWriter],
        ],
    )
    def test_normal(self, format_name, expected):
        writer = ptw.TableWriterFactory.create_from_format_name(format_name)

        assert isinstance(writer, expected)
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_normal_type_hints(self, tmpdir):
        test_file_path = str(tmpdir.join("test.sqlite"))

        writer = ptw.SqliteTableWriter()
        writer.open(test_file_path)
        writer.table_name = "hoge"
        writer.headers = ["a", "b"]
        writer.value_matrix = [[1, 2], [11, 12]]
        writer.type_hints = [ptw.String]
        writer.write_table()
        writer.close()

        schema = SQLiteSchemaExtractor(test_file_path).fetch_database_schema_as_dict()

        assert schema[writer.table_name] == [
            OrderedDict(
                [
                    ("Field", "a"),
                    ("Index", False),
                    ("Type", "TEXT"),
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_normal(self, tmpdir, table, header, value, expected):
        test_file_path = tmpdir.join("test.sqlite")

        writer = ptw.SqliteTableWriter()
        writer.open(str(test_file_path))
        writer.table_name = table
        writer.headers = header
        writer.value_matrix = value
        writer.iteration_length = len(value)
        writer.write_table_iter()

        writer.close()

        for table_data in SqliteFileLoader(str(test_file_path)).load():
            assert table_data == expected
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_normal_single_table(self, tmpdir):
        test_filepath = str(tmpdir.join("test.sqlite"))
        data = TableData(
            "tablename", ["ha", "hb", "hc"], [[1.0, 2.0, 3.0], [11.0, 12.0, 13.0], [1.0, 2.0, 3.0]]
        )

        writer = ptw.SqliteTableWriter()
        writer.from_tabledata(data)
        writer.dump(test_filepath)

        for expected in SqliteFileLoader(test_filepath).load():
            assert data == expected
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_exception(self, tmpdir, table, header, value, expected):
        writer = ptw.SqliteTableWriter()
        writer.open(":memory:")
        writer.table_name = table
        writer.headers = header
        writer.value_matrix = value

        with pytest.raises(expected):
            writer.write_table()
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_normal(self, tmpdir, table, header, value, expected):
        test_file_path = tmpdir.join("test.sqlite")

        writer = ptw.SqliteTableWriter()
        writer.open(str(test_file_path))
        writer.table_name = table
        writer.headers = header
        writer.value_matrix = value
        writer.write_table()
        writer.close()

        for table_data in SqliteFileLoader(str(test_file_path)).load():
            expected_dump = ptw.dumps_tabledata(expected)
            actual_dump = ptw.dumps_tabledata(table_data)

            print_test_result(expected=expected_dump, actual=actual_dump)

            assert actual_dump == expected_dump
github thombashi / pytablewriter / test / writer / binary / test_sqlite_writer.py View on Github external
def test_normal_multi_table(self, tmpdir):
        test_filepath = str(tmpdir.join("test.sqlite"))
        data_list = [
            TableData("first", ["ha1", "hb1", "hc1"], [[1.0, 2.0, 3.0], [11.0, 12.0, 13.0]]),
            TableData("second", ["ha2", "hb2", "hc2"], [[11.0, 12.0, 13.0], [1.0, 2.0, 3.0]]),
        ]

        writer = ptw.SqliteTableWriter()

        for data in data_list:
            writer.from_tabledata(data)
            writer.dump(test_filepath, close_after_write=False)

        writer.close()

        count = 0
        for data, expected in zip(data_list, SqliteFileLoader(test_filepath).load()):
            assert data == expected
            count += 1

        assert count == 2
github thombashi / pytablewriter / examples / py / sqlite_table.py View on Github external
#!/usr/bin/env python
# encoding: utf-8

"""
.. codeauthor:: Tsuyoshi Hombashi 
"""

import pytablewriter


writer = pytablewriter.SqliteTableWriter()

# create the first table
writer.table_name = "example"
writer.headers = ["int", "float", "str", "bool", "mix", "time"]
writer.value_matrix = [
    [0,   0.1,      "hoge", True,   0,      "2017-01-01 03:04:05+0900"],
    [2,   "-2.23",  "foo",  False,  None,   "2017-12-23 12:34:51+0900"],
    [3,   0,        "bar",  "true",  "inf", "2017-03-03 22:44:55+0900"],
    [-10, -9.9,     "",     "FALSE", "nan", "2017-01-01 00:00:00+0900"],
]
writer.dump("sample.sqlite", close_after_write=False)

# write the second table
writer.table_name = "Timezone"
writer.headers = [
    "zone_id", "abbreviation", "time_start", "gmt_offset", "dst",