def test_mixed_types(self): table = Table([ ["Alice", 33], ["Bob", 44], ["Carol", 55.5], ["Dave", 66.6], ], keys=["name", "age"]) self.assertEqual(table.keys(), ["name", "age"]) name_field = table.field(0) self.assertEqual(name_field["type"], str) self.assertEqual(name_field["optional"], False) age_field = table.field(1) self.assertEqual(set(age_field["type"]), {int, float}) self.assertEqual(age_field["optional"], False)
def test_simple_usage(self): table = Table([ ["Alice", 33], ["Bob", 44], ["Carol", 55], ["Dave", 66], ], keys=["name", "age"]) self.assertEqual(table.keys(), ["name", "age"]) name_field = table.field(0) self.assertEqual(name_field["type"], str) self.assertEqual(name_field["optional"], False) age_field = table.field(1) self.assertEqual(age_field["type"], int) self.assertEqual(age_field["optional"], False)
def test_optional_fields(self): table = Table([ ["Alice", 33], ["Bob", 44], ["Carol", None], [None, 66], ], keys=["name", "age"]) self.assertEqual(table.keys(), ["name", "age"]) name_field = table.field(0) self.assertEqual(name_field["type"], str) self.assertEqual(name_field["optional"], True) age_field = table.field(1) self.assertEqual(age_field["type"], int) self.assertEqual(age_field["optional"], True)
def test_fields_by_name_usage(self): table = Table([ ["Alice", 33], ["Bob", 44], ["Carol", 55], ["Dave", 66], ], keys=["name", "age"]) self.assertEqual(table.keys(), ["name", "age"]) name_field = table.field("name") self.assertEqual(name_field["type"], str) self.assertEqual(name_field["optional"], False) age_field = table.field("age") self.assertEqual(age_field["type"], int) self.assertEqual(age_field["optional"], False) with self.assertRaises(KeyError): _ = table.field("gender")