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

Function test_enum_conversion

sdk/python/tests/mod/test_results.py:401–470  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

399
400
401async def test_enum_conversion():
402 mod = Module()
403
404 @mod.enum_type
405 class Custom(enum.Enum):
406 ONE = "1"
407 TWO = "2"
408
409 @mod.enum_type
410 class Primitive(str, enum.Enum):
411 THREE = "3"
412 FOUR = "4"
413
414 with pytest.warns(DeprecationWarning, match="enum.Enum"):
415
416 @mod.enum_type
417 class Compat(dagger.Enum):
418 FIVE = "5"
419 SIX = "6"
420
421 @mod.object_type
422 class Test:
423 custom: Custom = mod.field(default=Custom.ONE)
424
425 @mod.function
426 def unstruct_custom(self) -> Custom:
427 return Custom.ONE
428
429 @mod.function
430 def struct_custom(self, val: Custom) -> str:
431 return str(val)
432
433 @mod.function
434 def unstruct_primitive(self) -> Primitive:
435 return Primitive.THREE
436
437 @mod.function
438 def struct_primitive(self, val: Primitive) -> str:
439 return str(val)
440
441 @mod.function
442 def unstruct_compat(self) -> Compat:
443 return Compat.FIVE
444
445 @mod.function
446 def struct_compat(self, val: Compat) -> str:
447 return repr(val)
448
449 obj, _ = await mod.get_structured_result("Test", {}, "", {})
450 assert obj.custom == Custom.ONE
451
452 obj, _ = await mod.get_structured_result("Test", {}, "", {"custom": "TWO"})
453 assert obj.custom == Custom.TWO
454
455 assert await mod.get_result("Test", {}, "unstruct_custom", {}) == "ONE"
456 assert (
457 await mod.get_result("Test", {}, "struct_custom", {"val": "TWO"})
458 == "Custom.TWO"

Callers

nothing calls this directly

Calls 3

get_structured_resultMethod · 0.95
get_resultMethod · 0.95
ModuleClass · 0.90

Tested by

no test coverage detected