| 191 | example.color = "BAD_VALUE" |
| 192 | |
| 193 | def test_info(self): |
| 194 | choices = color_choices |
| 195 | |
| 196 | class Example(HasTraits): |
| 197 | enum1 = Enum(choices, allow_none=False) |
| 198 | enum2 = CaselessStrEnum(choices, allow_none=False) |
| 199 | enum3 = FuzzyEnum(choices, allow_none=False) |
| 200 | enum4 = UseEnum(CSColor, allow_none=False) |
| 201 | |
| 202 | for i in range(1, 5): |
| 203 | attr = "enum%s" % i |
| 204 | enum = getattr(Example, attr) |
| 205 | |
| 206 | enum.allow_none = True |
| 207 | |
| 208 | info = enum.info() |
| 209 | self.assertEqual(len(info.split(", ")), len(choices), info.split(", ")) |
| 210 | self.assertIn("or None", info) |
| 211 | |
| 212 | info = enum.info_rst() |
| 213 | self.assertEqual(len(info.split("|")), len(choices), info.split("|")) |
| 214 | self.assertIn("or `None`", info) |
| 215 | # Check no single `\` exists. |
| 216 | self.assertNotRegex(info, r"\b\\\b") |
| 217 | |
| 218 | enum.allow_none = False |
| 219 | |
| 220 | info = enum.info() |
| 221 | self.assertEqual(len(info.split(", ")), len(choices), info.split(", ")) |
| 222 | self.assertNotIn("None", info) |
| 223 | |
| 224 | info = enum.info_rst() |
| 225 | self.assertEqual(len(info.split("|")), len(choices), info.split("|")) |
| 226 | self.assertNotIn("None", info) |
| 227 | # Check no single `\` exists. |
| 228 | self.assertNotRegex(info, r"\b\\\b") |
| 229 | |
| 230 | |
| 231 | # ----------------------------------------------------------------------------- |