def test_enum(self): class MyEnum(IntEnum): a = 1 b = 2 c = 3 v = Entry("v", enum=MyEnum) assert v.to_string(1) == "a (1)" assert v.to_string(2) == "b (2)" assert v.to_string(3) == "c (3)" assert v.to_string(MyEnum.a) == "a (1)" assert v.to_string(MyEnum.b) == "b (2)" assert v.to_string(MyEnum.c) == "c (3)" assert v.to_string(0) == "0" assert v.to_string("foo") == "foo" # Check can override formatter/friendly_formatter v = Entry("v", enum=MyEnum, formatter=hex) assert v.to_string(MyEnum.a) == "a (0x1)" assert v.to_string(MyEnum.b) == "b (0x2)" assert v.to_string(MyEnum.c) == "c (0x3)" v = Entry("v", enum=MyEnum, friendly_formatter=repr) assert v.to_string(MyEnum.a) == "<MyEnum.a: 1> (1)" assert v.to_string(MyEnum.b) == "<MyEnum.b: 2> (2)" assert v.to_string(MyEnum.c) == "<MyEnum.c: 3> (3)"
def test_to_string(self): v = Entry("v") assert v.to_string(123) == "123" assert v.to_string("abc") == "abc" v = Entry("v", formatter=bin) assert v.to_string(0b1010) == "0b1010" v = Entry("v", friendly_formatter=str.upper) assert v.to_string("foo") == "FOO (foo)" v = Entry("v", formatter=str.lower, friendly_formatter=str.upper) assert v.to_string("Foo") == "FOO (foo)"