diff --git a/src/hrepr/core.py b/src/hrepr/core.py index 668ad22..a2ed2da 100644 --- a/src/hrepr/core.py +++ b/src/hrepr/core.py @@ -3,6 +3,7 @@ from collections import Counter from dataclasses import fields as dataclass_fields from dataclasses import is_dataclass +from enum import Enum from pathlib import Path from typing import Union @@ -325,6 +326,12 @@ def hrepr(self, obj: Exception): layout="h", )["hrepr-error"] + # Enums + + def hrepr_short(self, e: Enum): + typ = type(e).__name__ + return H.span["hrepr-enum", f"hrepr-enum-{typ}"](f"{typ}.{e.name}") + # Functions and methods def hrepr_short(self, obj: types.FunctionType): diff --git a/tests/test_hrepr.py b/tests/test_hrepr.py index b9534e2..a5c29c3 100644 --- a/tests/test_hrepr.py +++ b/tests/test_hrepr.py @@ -2,6 +2,7 @@ import re import sys from dataclasses import dataclass +from enum import Enum import pytest from hrepr import H @@ -26,6 +27,12 @@ class Opaque: pass +class Size(Enum): + SMALL = "small" + MEDIUM = "medium" + BIG = "big" + + def hshort(x, **kw): return hrepr(x, max_depth=0, **kw) @@ -172,6 +179,7 @@ def _(obj, file_regression): factory.dict_keys({"a": 1, "b": 2, "c": 3}.keys(), standard, depth(0)) factory.dict_values({"a": 1, "b": 2, "c": 3}.values(), standard, depth(0)) factory.dataclass(Point(1, 2), standard, depth(0)) +factory.enum(Size.BIG, standard) factory.unknown(Opaque, standard) factory.list10( diff --git a/tests/test_hrepr/test_enum_standard_.html b/tests/test_hrepr/test_enum_standard_.html new file mode 100644 index 0000000..1781632 --- /dev/null +++ b/tests/test_hrepr/test_enum_standard_.html @@ -0,0 +1,232 @@ +
hrepr(obj)
<Size.BIG: 'big'>