reference = "Unnamed record"
else:
reference = "Record '{}'".format(self.name)
- raise NameError("{} does not have a field '{}'. Did you mean one of: {}?"
- .format(reference, item, ", ".join(self.fields))) from None
+ raise AttributeError("{} does not have a field '{}'. Did you mean one of: {}?"
+ .format(reference, item, ", ".join(self.fields))) from None
else:
return super().__getitem__(item)
self.assertEqual(r.stb.name, "r__stb")
self.assertEqual(r["stb"].name, "r__stb")
+ self.assertTrue(hasattr(r, "stb"))
+ self.assertFalse(hasattr(r, "xxx"))
+
def test_unnamed(self):
r = [Record([
("stb", 1)
("stb", 1),
("ack", 1),
])
- with self.assertRaises(NameError,
+ with self.assertRaises(AttributeError,
+ msg="Record 'r' does not have a field 'en'. Did you mean one of: stb, ack?"):
+ r["en"]
+ with self.assertRaises(AttributeError,
msg="Record 'r' does not have a field 'en'. Did you mean one of: stb, ack?"):
r.en
("stb", 1),
("ack", 1),
])][0]
- with self.assertRaises(NameError,
+ with self.assertRaises(AttributeError,
msg="Unnamed record does not have a field 'en'. Did you mean one of: stb, ack?"):
r.en