| 116 | r[0] = 1 |
| 117 | |
| 118 | def test_record_repr(self): |
| 119 | self.assertEqual( |
| 120 | repr(Record(R_A, (42,))), |
| 121 | '<Record a=42>') |
| 122 | |
| 123 | self.assertEqual( |
| 124 | repr(Record(R_AB, (42, -1))), |
| 125 | '<Record a=42 b=-1>') |
| 126 | |
| 127 | # test invalid records just in case |
| 128 | with self.assertRaisesRegex(RuntimeError, 'invalid .* mapping'): |
| 129 | repr(Record(R_A, (42, 43))) |
| 130 | self.assertEqual(repr(Record(R_AB, (42,))), '<Record a=42>') |
| 131 | |
| 132 | class Key: |
| 133 | def __str__(self): |
| 134 | 1 / 0 |
| 135 | |
| 136 | def __repr__(self): |
| 137 | 1 / 0 |
| 138 | |
| 139 | with self.assertRaises(ZeroDivisionError): |
| 140 | repr(Record({Key(): 0}, (42,))) |
| 141 | with self.assertRaises(ZeroDivisionError): |
| 142 | repr(Record(R_A, (Key(),))) |
| 143 | |
| 144 | def test_record_iter(self): |
| 145 | r = Record(R_AB, (42, 43)) |