MCPcopy Index your code
hub / github.com/pathwaycom/pathway / test_json_serde

Function test_json_serde

python/pathway/tests/test_json.py:952–1002  ·  view source on GitHub ↗
(tmp_path: pathlib.Path)

Source from the content-addressed store, hash-verified

950
951
952def test_json_serde(tmp_path: pathlib.Path):
953 class ObjectSchema(pw.Schema):
954 dtn: pw.DateTimeNaive
955 dt: pw.DateTimeUtc
956 pdn: pw.DateTimeNaive
957 pd: pw.DateTimeUtc
958 pwn: pw.DateTimeNaive
959 pw: pw.DateTimeUtc
960 dur: pw.Duration
961 text: str
962
963 class TableSchema(ObjectSchema):
964 nested: pw.Json
965
966 obj = {
967 "dtn": datetime.datetime(2025, 3, 14, 10, 13),
968 "dt": datetime.datetime(
969 2025, 3, 14, 10, 13, microsecond=123456, tzinfo=datetime.timezone.utc
970 ),
971 "pdn": pd.Timestamp("2025-03-14"),
972 "pd": pd.Timestamp("2025-03-14T00:00+00:00"),
973 "pwn": pw.DateTimeNaive("2025-03-14T10:13:00.123456789"),
974 "pw": pw.DateTimeUtc("2025-03-14T10:13:00.123456000+00:00"),
975 "dur": pd.Timedelta("4 days 2 microseconds"),
976 "text": "2025-03-14T00:00+00:00",
977 }
978
979 obj["nested"] = obj.copy()
980
981 def prepare():
982 G.clear()
983 table = pw.debug.table_from_rows(
984 TableSchema,
985 [(*(obj.values()), obj)],
986 )
987 pw.io.jsonlines.write(table, tmp_path / "input.jsonl")
988 run()
989
990 def read():
991 G.clear()
992 table = pw.io.jsonlines.read(
993 tmp_path / "input.jsonl", schema=TableSchema, mode="static"
994 )
995 expected = pw.debug.table_from_rows(
996 TableSchema,
997 [(*(obj.values()), obj)],
998 )
999 assert_table_equality_wo_index(table, expected)
1000
1001 prepare()
1002 read()
1003
1004
1005def test_json_unpack_col_dict(tmp_path):

Callers

nothing calls this directly

Calls 3

prepareFunction · 0.85
readFunction · 0.70
copyMethod · 0.45

Tested by

no test coverage detected