(ctx context.Context, t *testctx.T)
| 1510 | } |
| 1511 | |
| 1512 | func (PythonSuite) TestInheritance(ctx context.Context, t *testctx.T) { |
| 1513 | t.Run("inherited create constructor", func(ctx context.Context, t *testctx.T) { |
| 1514 | c := connect(ctx, t) |
| 1515 | |
| 1516 | modGen := pythonModInit(t, c, ` |
| 1517 | from typing import Annotated, Self |
| 1518 | |
| 1519 | from dagger import Doc, function, object_type |
| 1520 | |
| 1521 | class Base: |
| 1522 | """What's the object-oriented way to become wealthy?""" |
| 1523 | |
| 1524 | @classmethod |
| 1525 | def create(cls) -> Self: |
| 1526 | """Inheritance.""" |
| 1527 | return cls() |
| 1528 | |
| 1529 | @object_type |
| 1530 | class Test(Base): |
| 1531 | ... |
| 1532 | `) |
| 1533 | |
| 1534 | obj := inspectModuleObjects(ctx, t, modGen).Get("#(name=Test)") |
| 1535 | |
| 1536 | require.Equal(t, "Inheritance.", obj.Get("constructor.description").String()) |
| 1537 | }) |
| 1538 | |
| 1539 | t.Run("inherited functions", func(ctx context.Context, t *testctx.T) { |
| 1540 | c := connect(ctx, t) |
| 1541 | |
| 1542 | modGen := pythonModInit(t, c, ` |
| 1543 | from typing import Annotated, Self |
| 1544 | |
| 1545 | from dagger import Doc, function, object_type |
| 1546 | |
| 1547 | class Base: |
| 1548 | """Base class with inherited @function methods.""" |
| 1549 | |
| 1550 | @function |
| 1551 | def with_component(self, name: Annotated[str, Doc("component name")]) -> Self: |
| 1552 | """Inherited function that should be visible.""" |
| 1553 | return self |
| 1554 | |
| 1555 | @function |
| 1556 | async def with_context(self) -> Self: |
| 1557 | """Another inherited function that should be visible.""" |
| 1558 | return self |
| 1559 | |
| 1560 | @object_type |
| 1561 | class Test(Base): |
| 1562 | @function |
| 1563 | def my_own_function(self) -> str: |
| 1564 | """This function IS visible.""" |
| 1565 | return "ok" |
| 1566 | `) |
| 1567 | |
| 1568 | obj := inspectModuleObjects(ctx, t, modGen).Get("#(name=Test)") |
| 1569 |
nothing calls this directly
no test coverage detected