How to use the pytablewriter.dumps_tabledata 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 / SimpleSQLite / test / test_from_file.py View on Github external
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 table_data in loader.load():
            if table_data.is_empty():
                continue

            try:
                from pytablewriter import dumps_tabledata

                print(dumps_tabledata(table_data))
            except ImportError:
                pass

            try:
                con.create_table_from_tabledata(SQLiteTableDataSanitizer(table_data).normalize())
                success_count += 1
            except ValueError as e:
                print(e)

        con.commit()

        assert success_count > 0
github thombashi / pytablereader / test / loader / test_fileloader.py View on Github external
)

        expected_list = [
            TableData(
                filename,
                ["attr_a", "attr_b", "attr_c"],
                [[1, 4, "a"], [2, "2.1", "bb"], [3, "120.9", "ccc"]],
            )
        ]
        loader = ptr.TableFileLoader(p_file_path, format_name=format_name)

        assert loader.format_name == "csv"

        for tabledata, expected in zip(loader.load(), expected_list):
            print(dumps_tabledata(expected))
            print(dumps_tabledata(tabledata))

            assert tabledata.equals(expected)
github thombashi / pytablereader / test / test_jsonlines_reader.py View on Github external
def test_normal(self, table_text, table_name, expected_tabletuple_list):
        self.LOADER_CLASS.clear_table_count()
        loader = self.LOADER_CLASS(table_text)
        loader.table_name = table_name

        load = False
        for tabledata in loader.load():
            print("[actual]\n{}".format(dumps_tabledata(tabledata)))
            print("[expected]")
            for expected in expected_tabletuple_list:
                print("{}".format(dumps_tabledata(tabledata)))

            assert tabledata.in_tabledata_list(expected_tabletuple_list)
            load = True

        assert load
github thombashi / pytablewriter / test / test_function.py View on Github external
def test_normal_format_name(self, value, format_name, expected):
        out = dumps_tabledata(value, format_name=format_name)
        print_test_result(expected=expected, actual=out)

        assert out == expected
github thombashi / pytablereader / test / test_markdown_reader.py View on Github external
def test_normal(
        self, tmpdir, test_id, table_text, filename, table_name, expected_tabledata_list
    ):
        file_path = Path(str(tmpdir.join(filename)))
        file_path.parent.makedirs_p()

        with open(file_path, "w") as f:
            f.write(table_text)

        loader = ptr.MarkdownTableFileLoader(file_path)
        loader.table_name = table_name

        load = False
        for table_data in loader.load():
            print("--- test {} ---".format(test_id))
            print("\n[actual]\n{}".format(dumps_tabledata(table_data)))
            assert table_data.in_tabledata_list(expected_tabledata_list)
            load = True

        assert load
github thombashi / pytablereader / test / loader / test_fileloader.py View on Github external
[
                    ["root", 1, 0, 0.4, 77664, 8784, "?", "Ss", "May11", "0:02", "/sbin/init"],
                    ["root", 2, 0, 0, 0, 0, "?", "S", "May11", "0:00", "[kthreadd]"],
                    ["root", 4, 0, 0, 0, 0, "?", "I<", "May11", "0:00", "[kworker/0:0H]"],
                    ["root", 6, 0, 0, 0, 0, "?", "I<", "May11", "0:00", "[mm_percpu_wq]"],
                    ["root", 7, 0, 0, 0, 0, "?", "S", "May11", "0:01", "[ksoftirqd/0]"],
                ],
            )
        ]
        loader = ptr.TableFileLoader(p_file_path, format_name="ssv")

        assert loader.format_name == "csv"

        for tabledata, expected in zip(loader.load(), expected_list):
            print(dumps_tabledata(expected))
            print(dumps_tabledata(tabledata))

            assert tabledata.equals(expected)
github thombashi / pytablereader / test / loader / test_fileloader.py View on Github external
),
        ]

        writer = ExcelXlsxTableWriter()
        writer.open(p_file_path)
        for tabledata in tabledata_list:
            writer.from_tabledata(tabledata)
        writer.write_table()
        writer.close()

        loader = ptr.TableFileLoader(p_file_path)

        assert loader.format_name == "excel"

        for tabledata in loader.load():
            print(dumps_tabledata(tabledata))

            assert tabledata in tabledata_list
github thombashi / pytablereader / test / loader / test_urlloader.py View on Github external
)
        expected_list = [
            TableData(
                "url_loader",
                ["attr_a", "attr_b", "attr_c"],
                [{"attr_a": 1}, {"attr_b": 2.1, "attr_c": "bb"}],
            )
        ]

        loader = ptr.TableUrlLoader(url, format_name)
        assert loader.format_name == "json"

        loader.table_name = "url_loader"

        for table_data in loader.load():
            print("{} {}".format(table_data, dumps_tabledata(table_data)))
            print(table_data.rows)
            print("[expected]")
            for expected in expected_list:
                print(dumps_tabledata(expected))

            assert table_data.in_tabledata_list(expected_list)
github thombashi / pytablereader / test / loader / test_fileloader.py View on Github external
],
                [
                    ["root", 1, 0, 0.4, 77664, 8784, "?", "Ss", "May11", "0:02", "/sbin/init"],
                    ["root", 2, 0, 0, 0, 0, "?", "S", "May11", "0:00", "[kthreadd]"],
                    ["root", 4, 0, 0, 0, 0, "?", "I<", "May11", "0:00", "[kworker/0:0H]"],
                    ["root", 6, 0, 0, 0, 0, "?", "I<", "May11", "0:00", "[mm_percpu_wq]"],
                    ["root", 7, 0, 0, 0, 0, "?", "S", "May11", "0:01", "[ksoftirqd/0]"],
                ],
            )
        ]
        loader = ptr.TableFileLoader(p_file_path, format_name="ssv")

        assert loader.format_name == "csv"

        for tabledata, expected in zip(loader.load(), expected_list):
            print(dumps_tabledata(expected))
            print(dumps_tabledata(tabledata))

            assert tabledata.equals(expected)
github thombashi / tblfaker / test / test_tblfaker.py View on Github external
def test_normal_locale(self):
        faker = TableFaker(locale="ja_JP", seed=1)
        out = faker.generate(("name", "address"), rows=2)
        expected = TableData(
            None,
            ("name", "address"),
            [("山岸 裕樹", "三重県荒川区明石町14丁目4番16号"), ("村山 拓真", "北海道荒川区白金台15丁目19番4号 コート所野806")],
        )
        out_table = dumps_tabledata(out, **dump_opts)
        expected_table = dumps_tabledata(expected, **dump_opts)

        print_test_result(expected=expected_table, actual=out_table)

        assert expected_table == out_table
        assert out == expected
        assert out != faker.generate(("name", "address"), rows=2)