|
1 | | -from easypy.humanize import from_hexdump, hexdump, IndentableTextBuffer, format_table |
| 1 | +from easypy.humanize import from_hexdump, hexdump, IndentableTextBuffer, format_table, easy_repr |
2 | 2 |
|
3 | 3 |
|
4 | 4 | _SAMPLE_DATA = b'J\x9c\xe8Z!\xc2\xe6\x8b\xa0\x01\xcb\xc3.x]\x11\x9bsC\x1c\xb2\xcd\xb3\x9eM\xf7\x13`\xc8\xce\xf8g1H&\xe2\x9b' \ |
@@ -88,3 +88,40 @@ def test_format_table_without_titles(): |
88 | 88 | "{'x': 'x'}|b'bytes'|string\n") |
89 | 89 |
|
90 | 90 | assert output == format_table(table, titles=False) |
| 91 | + |
| 92 | + |
| 93 | +def test_easy_repr(): |
| 94 | + @easy_repr('a', 'b', 'c') |
| 95 | + class Class1: |
| 96 | + def __init__(self, a, b, c, d): |
| 97 | + self.a = a |
| 98 | + self.b = b |
| 99 | + self.c = c |
| 100 | + self.d = d |
| 101 | + a = Class1('a', 'b', 1, 2) |
| 102 | + assert repr(a) == "<Class1: a='a', b='b', c=1>" |
| 103 | + |
| 104 | + # change order |
| 105 | + @easy_repr('c', 'a', 'd') |
| 106 | + class Class2: |
| 107 | + def __init__(self, a, b, c, d): |
| 108 | + self.a = a |
| 109 | + self.b = b |
| 110 | + self.c = c |
| 111 | + self.d = d |
| 112 | + a = Class2('a', 'b', 1, 2) |
| 113 | + assert repr(a) == "<Class2: c=1, a='a', d=2>" |
| 114 | + |
| 115 | + try: |
| 116 | + @easy_repr() |
| 117 | + class Class3: |
| 118 | + def __init__(self, a, b, c, d): |
| 119 | + self.a = a |
| 120 | + self.b = b |
| 121 | + self.c = c |
| 122 | + self.d = d |
| 123 | + except AssertionError: |
| 124 | + pass |
| 125 | + else: |
| 126 | + assert False, 'easy_repr with no attributes should not be allowed' |
| 127 | + |
0 commit comments