예제 #1
0
    def test_normal_same_table(self, con_a0, con_a1):
        out_db_path = "test.sqlite"
        runner = CliRunner()

        with runner.isolated_filesystem():
            result = runner.invoke(
                cmd,
                [
                    "file", con_a0.database_path, con_a1.database_path,
                    "-o", out_db_path,
                ])
            print_traceback(result)
            assert result.exit_code == ExitCode.SUCCESS

            expected = TableData(
                table_name=TEST_TABLE_NAME_A,
                header_list=["attr_a", "attr_b"],
                record_list=[
                    [1, 2],
                    [3, 4],
                    [11, 12],
                    [13, 14],
                ])
            for tabledata in SqliteFileLoader(out_db_path).load():
                assert tabledata == expected
예제 #2
0
    def test_normal_multi_table(self, con_a0, con_b0):
        out_db_path = "test.sqlite"
        runner = CliRunner()

        with runner.isolated_filesystem():
            result = runner.invoke(
                cmd,
                [
                    "file", con_a0.database_path, con_b0.database_path,
                    "-o", out_db_path,
                ])
            print_traceback(result)
            assert result.exit_code == ExitCode.SUCCESS

            expected_list = [
                TableData(
                    table_name=TEST_TABLE_NAME_A,
                    header_list=["attr_a", "attr_b"],
                    record_list=[
                        [1, 2],
                        [3, 4],
                    ]),
                TableData(
                    table_name=TEST_TABLE_NAME_B,
                    header_list=["ba", "bb"],
                    record_list=[
                        [101, 102],
                        [103, 104],
                    ]),
            ]
            for tabledata in SqliteFileLoader(out_db_path).load():
                print("[actual]   {}".format(tabledata))

                assert tabledata in expected_list
예제 #3
0
    def test_normal_multi_table(self, con_a0, con_b0):
        out_db_path = "test.sqlite"
        runner = CliRunner()

        with runner.isolated_filesystem():
            result = runner.invoke(cmd, [
                "-o", out_db_path, "file", con_a0.database_path,
                con_b0.database_path
            ])
            print_traceback(result)
            assert result.exit_code == ExitCode.SUCCESS

            expected_list = [
                TableData(TEST_TABLE_NAME_A, ["attr_a", "attr_b"],
                          [[1, 2], [3, 4]]),
                TableData(TEST_TABLE_NAME_B, ["ba", "bb"],
                          [[101, 102], [103, 104]]),
            ]
            for tabledata in SqliteFileLoader(out_db_path).load():
                if tabledata.table_name == SourceInfo.get_table_name():
                    continue

                print("[actual]\n{}".format(tabledata))
                for record in tabledata.value_matrix:
                    print("  {}".format(record))

                assert tabledata in expected_list
예제 #4
0
    def test_normal_multi_table(self, tmpdir):
        test_filepath = str(tmpdir.join("test.sqlite"))
        data_list = [
            TableData(
                table_name="first",
                header_list=["ha1", "hb1", "hc1"],
                row_list=[[1.0, 2.0, 3.0], [11.0, 12.0, 13.0]],
            ),
            TableData(
                table_name="second",
                header_list=["ha2", "hb2", "hc2"],
                row_list=[[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
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
    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.dump_tabledata(expected)
            actual_dump = ptw.dump_tabledata(table_data)

            print_test_result(expected=expected_dump, actual=actual_dump)

            assert actual_dump == expected_dump