MCPcopy Create free account
hub / github.com/dagger/dagger / TestInheritance

Method TestInheritance

core/integration/module_python_test.go:1512–1588  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

1510}
1511
1512func (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, `
1543from typing import Annotated, Self
1544
1545from dagger import Doc, function, object_type
1546
1547class 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
1561class 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

Callers

nothing calls this directly

Calls 8

pythonModInitFunction · 0.85
inspectModuleObjectsFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
GetMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected