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

Method TestDocs

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

Source from the content-addressed store, hash-verified

1220}
1221
1222func (PythonSuite) TestDocs(ctx context.Context, t *testctx.T) {
1223 t.Run("basic", func(ctx context.Context, t *testctx.T) {
1224 c := connect(ctx, t)
1225
1226 modGen := pythonModInit(t, c, `
1227 from typing import Annotated
1228
1229 from dagger import Doc, function, object_type
1230
1231 @object_type
1232 class Test:
1233 """Object docstring.
1234
1235 Multiline.
1236 """
1237
1238 @function
1239 def undoc(self, msg: str) -> str:
1240 return msg
1241
1242 @function
1243 def echo(self, msg: Annotated[str, Doc("the message to echo")] = "marco") -> str:
1244 """Function docstring.
1245
1246 Multiline.
1247 """
1248 return msg
1249
1250 @function(doc="overridden description")
1251 def over(self) -> str:
1252 """Code-only docstring."""
1253 return ""
1254 `)
1255
1256 obj := inspectModuleObjects(ctx, t, modGen).Get("0")
1257
1258 // NB: Should not end in a new line.
1259 require.Equal(t, "Object docstring.\n\nMultiline.", obj.Get("description").String())
1260
1261 // test undocumented function
1262 undoc := obj.Get("functions.#(name=undoc)")
1263 require.Empty(t, undoc.Get("description").String())
1264 require.Empty(t, undoc.Get("args.0.description").String())
1265 require.Empty(t, undoc.Get("args.0.defaultValue").String())
1266
1267 // test documented function
1268 echo := obj.Get("functions.#(name=echo)")
1269 require.Equal(t, "Function docstring.\n\nMultiline.", echo.Get("description").String())
1270 require.Equal(t, "msg", echo.Get("args.0.name").String())
1271 require.Equal(t, "the message to echo", echo.Get("args.0.description").String())
1272 require.Equal(t, "marco", echo.Get("args.0.defaultValue.@fromstr").String())
1273
1274 // test function description override
1275 over := obj.Get("functions.#(name=over)")
1276 require.Equal(t, "overridden description", over.Get("description").String())
1277 })
1278
1279 t.Run("autogenerated constructor", func(ctx context.Context, t *testctx.T) {

Callers

nothing calls this directly

Calls 15

pythonModInitFunction · 0.85
inspectModuleObjectsFunction · 0.85
daggerCallFunction · 0.85
requireErrOutFunction · 0.85
inspectModuleInterfacesFunction · 0.85
connectFunction · 0.70
RunMethod · 0.65
GetMethod · 0.65
EqualMethod · 0.65
StringMethod · 0.65
ValueMethod · 0.65
BoolMethod · 0.65

Tested by

no test coverage detected