MCPcopy
hub / github.com/pathwaycom/pathway / test_schemas_composition

Function test_schemas_composition

python/pathway/tests/test_schema.py:440–498  ·  view source on GitHub ↗
(option, tmp_path)

Source from the content-addressed store, hash-verified

438
439@pytest.mark.parametrize("option", ["inheritance_1", "inheritance_2", "disjunction"])
440def test_schemas_composition(option, tmp_path):
441 input_path = tmp_path / "input.jsonl"
442
443 class BaseSchema_1(pw.Schema):
444 key: int = pw.column_definition(primary_key=True)
445 value: str = pw.column_definition(
446 default_value="default_value",
447 description="test description",
448 example="some example",
449 )
450
451 class BaseSchema_2(pw.Schema):
452 value2: bool
453
454 if option == "inheritance_1":
455
456 class InputSchema(BaseSchema_1):
457 value2: bool
458
459 elif option == "inheritance_2":
460
461 class InputSchema(BaseSchema_1, BaseSchema_2):
462 pass
463
464 elif option == "disjunction":
465 InputSchema = BaseSchema_1 | BaseSchema_2
466 else:
467 raise ValueError("unexpected option: {option}")
468
469 class ExpectedSchema(pw.Schema):
470 key: int = pw.column_definition(primary_key=True)
471 value: str = pw.column_definition(
472 default_value="default_value",
473 description="test description",
474 example="some example",
475 )
476 value2: bool
477
478 InputSchema.assert_matches_schema(
479 ExpectedSchema,
480 allow_subtype=False,
481 allow_superset=False,
482 ignore_primary_keys=False,
483 ignore_properties=False,
484 )
485
486 input_data = """
487 {"key": 0, "value": "hello", "value2": true}
488 {"key": 1, "value2": false}
489 """
490 write_lines(input_path, input_data)
491
492 table = pw.io.jsonlines.read(input_path, mode="static", schema=InputSchema)
493
494 output_table = pw.debug.table_to_pandas(table)
495 row_0 = output_table.loc[output_table["key"] == 0, ["value", "value2"]].iloc[0]
496 assert (row_0 == pd.Series({"value": "hello", "value2": True})).all()
497 row_1 = output_table.loc[output_table["key"] == 1, ["value", "value2"]].iloc[0]

Callers

nothing calls this directly

Calls 2

write_linesFunction · 0.90
assert_matches_schemaMethod · 0.80

Tested by

no test coverage detected