|
12 | 12 | import random |
13 | 13 | import re |
14 | 14 | import socket |
15 | | -import sqlite3 |
16 | 15 | import sys |
17 | 16 | import threading |
18 | 17 | import time |
@@ -2688,81 +2687,6 @@ class InputSchema(pw.Schema): |
2688 | 2687 | assert_table_equality_wo_index(result, expected) |
2689 | 2688 |
|
2690 | 2689 |
|
2691 | | -@needs_multiprocessing_fork |
2692 | | -def test_sqlite(tmp_path: pathlib.Path): |
2693 | | - database_name = tmp_path / "test.db" |
2694 | | - output_path = tmp_path / "output.csv" |
2695 | | - |
2696 | | - connection = sqlite3.connect(database_name) |
2697 | | - cursor = connection.cursor() |
2698 | | - cursor.execute( |
2699 | | - """ |
2700 | | - CREATE TABLE users ( |
2701 | | - id INTEGER, |
2702 | | - login TEXT, |
2703 | | - name TEXT |
2704 | | - ) |
2705 | | - """ |
2706 | | - ) |
2707 | | - cursor.execute("INSERT INTO users (id, login, name) VALUES (1, 'alice', 'Alice')") |
2708 | | - cursor.execute("INSERT INTO users (id, login, name) VALUES (2, 'bob1999', 'Bob')") |
2709 | | - connection.commit() |
2710 | | - |
2711 | | - def stream_target(): |
2712 | | - wait_result_with_checker(FileLinesNumberChecker(output_path, 2), 5, target=None) |
2713 | | - connection = sqlite3.connect(database_name) |
2714 | | - cursor = connection.cursor() |
2715 | | - cursor.execute( |
2716 | | - """ |
2717 | | - INSERT INTO users (id, login, name) VALUES (3, 'ch123', 'Charlie')""" |
2718 | | - ) |
2719 | | - connection.commit() |
2720 | | - |
2721 | | - wait_result_with_checker(FileLinesNumberChecker(output_path, 3), 2, target=None) |
2722 | | - cursor = connection.cursor() |
2723 | | - cursor.execute("UPDATE users SET name = 'Bob Smith' WHERE id = 2") |
2724 | | - connection.commit() |
2725 | | - |
2726 | | - wait_result_with_checker(FileLinesNumberChecker(output_path, 5), 2, target=None) |
2727 | | - cursor = connection.cursor() |
2728 | | - cursor.execute("DELETE FROM users WHERE id = 3") |
2729 | | - connection.commit() |
2730 | | - |
2731 | | - class InputSchema(pw.Schema): |
2732 | | - id: int |
2733 | | - login: str |
2734 | | - name: str |
2735 | | - |
2736 | | - table = pw.io.sqlite.read( |
2737 | | - database_name, "users", InputSchema, autocommit_duration_ms=1 |
2738 | | - ) |
2739 | | - pw.io.jsonlines.write(table, output_path) |
2740 | | - |
2741 | | - inputs_thread = threading.Thread(target=stream_target, daemon=True) |
2742 | | - inputs_thread.start() |
2743 | | - |
2744 | | - wait_result_with_checker(FileLinesNumberChecker(output_path, 6), 30) |
2745 | | - |
2746 | | - events = [] |
2747 | | - with open(output_path) as f: |
2748 | | - for row in f: |
2749 | | - events.append(json.loads(row)) |
2750 | | - |
2751 | | - events.sort(key=lambda event: (event["time"], event["diff"], event["name"])) |
2752 | | - events_truncated = [] |
2753 | | - for event in events: |
2754 | | - events_truncated.append([event["name"], event["diff"]]) |
2755 | | - |
2756 | | - assert events_truncated == [ |
2757 | | - ["Alice", 1], |
2758 | | - ["Bob", 1], |
2759 | | - ["Charlie", 1], |
2760 | | - ["Bob", -1], |
2761 | | - ["Bob Smith", 1], |
2762 | | - ["Charlie", -1], |
2763 | | - ] |
2764 | | - |
2765 | | - |
2766 | 2690 | def test_apply_bytes_full_cycle(tmp_path: pathlib.Path): |
2767 | 2691 | input_path = tmp_path / "input.txt" |
2768 | 2692 | input_full_contents = "abc\n\ndef\nghi" |
|
0 commit comments