MCPcopy Create free account
hub / github.com/pathwaycom/pathway / test_python_connector_upsert_json

Function test_python_connector_upsert_json

python/pathway/tests/test_io.py:2494–2531  ·  view source on GitHub ↗
(tmp_path: pathlib.Path)

Source from the content-addressed store, hash-verified

2492
2493
2494def test_python_connector_upsert_json(tmp_path: pathlib.Path):
2495 output_path = tmp_path / "output.csv"
2496
2497 class TestSubject(pw.io.python.ConnectorSubject):
2498 @property
2499 def _session_type(self) -> SessionType:
2500 return SessionType.UPSERT
2501
2502 def run(self):
2503 self._add(
2504 api.ref_scalar(0),
2505 json.dumps({"word": "one", "digit": 1}).encode("utf-8"),
2506 )
2507 time.sleep(5e-2)
2508 self._add(
2509 api.ref_scalar(0),
2510 json.dumps({"word": "two", "digit": 2}).encode("utf-8"),
2511 )
2512 time.sleep(5e-2)
2513 self._add(
2514 api.ref_scalar(0),
2515 json.dumps({"word": "three", "digit": 3}).encode("utf-8"),
2516 )
2517 self.close()
2518
2519 class InputSchema(pw.Schema):
2520 word: str
2521 digit: int
2522
2523 table = pw.io.python.read(
2524 TestSubject(), format="json", schema=InputSchema, autocommit_duration_ms=10
2525 )
2526 pw.io.csv.write(table, output_path)
2527 run()
2528
2529 result = pd.read_csv(output_path)
2530 assert len(result) == 5
2531 assert_sets_equality_from_path(output_path, {"three,3,1"})
2532
2533
2534def test_python_connector_upsert_remove_json(tmp_path: pathlib.Path):

Callers

nothing calls this directly

Calls 4

runFunction · 0.90
writeMethod · 0.80
TestSubjectClass · 0.70

Tested by

no test coverage detected