MCPcopy Create free account
hub / github.com/pybind/pybind11 / TEST_SUBMODULE

Function TEST_SUBMODULE

tests/test_native_enum.cpp:80–262  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
79
80TEST_SUBMODULE(native_enum, m) {
81 using namespace test_native_enum;
82
83 py::native_enum<smallenum>(m, "smallenum", "enum.IntEnum", "doc smallenum")
84 .value("a", smallenum::a)
85 .value("b", smallenum::b)
86 .value("c", smallenum::c)
87 .finalize();
88
89 py::native_enum<color>(m, "color", "enum.IntEnum")
90 .value("red", color::red)
91 .value("yellow", color::yellow)
92 .value("green", color::green)
93 .value("blue", color::blue)
94 .finalize();
95
96 m.def("bind_altitude", [](const py::module_ &mod) {
97 py::native_enum<altitude>(mod, "altitude", "enum.Enum")
98 .value("high", altitude::high)
99 .value("low", altitude::low)
100 .finalize();
101 });
102 m.def("is_high_altitude", [](altitude alt) { return alt == altitude::high; });
103 m.def("get_altitude", []() -> altitude { return altitude::high; });
104
105 py::native_enum<flags_uchar>(m, "flags_uchar", "enum.Flag")
106 .value("bit0", flags_uchar::bit0)
107 .value("bit1", flags_uchar::bit1)
108 .value("bit2", flags_uchar::bit2)
109 .finalize();
110
111 py::native_enum<flags_uint>(m, "flags_uint", "enum.IntFlag")
112 .value("bit0", flags_uint::bit0)
113 .value("bit1", flags_uint::bit1)
114 .value("bit2", flags_uint::bit2)
115 .finalize();
116
117 py::native_enum<export_values>(m, "export_values", "enum.IntEnum")
118 .value("exv0", export_values::exv0)
119 .value("exv1", export_values::exv1)
120 .export_values()
121 .finalize();
122
123 py::native_enum<member_doc>(m, "member_doc", "enum.IntEnum")
124 .value("mem0", member_doc::mem0, "docA")
125 .value("mem1", member_doc::mem1)
126 .value("mem2", member_doc::mem2, "docC")
127 .finalize();
128
129 py::class_<class_with_enum> py_class_with_enum(m, "class_with_enum");
130 py::native_enum<class_with_enum::in_class>(py_class_with_enum, "in_class", "enum.IntEnum")
131 .value("one", class_with_enum::in_class::one)
132 .value("two", class_with_enum::in_class::two)
133 .finalize();
134
135 py_class_with_enum.def(py::init())
136 .def_readwrite("nested_value", &class_with_enum::nested_value);
137

Callers

nothing calls this directly

Calls 7

initFunction · 0.85
noneClass · 0.85
finalizeMethod · 0.80
attrMethod · 0.80
argClass · 0.50
valueMethod · 0.45

Tested by

no test coverage detected