Example #1
0
 def test_record_hashing(self):
     record1 = Record(zip(["name", "empire"], ["Nigel", "The British Empire"]))
     record2 = Record(zip(["name", "empire"], ["Nigel", "The British Empire"]))
     record3 = Record(zip(["name", "empire"], ["Stefan", "Das Deutschland"]))
     assert hash(record1) == hash(record2)
     assert hash(record1) != hash(record3)
     assert hash(record2) != hash(record3)
Example #2
0
 def test_record_equality(self):
     record1 = Record(zip(["name", "empire"], ["Nigel", "The British Empire"]))
     record2 = Record(zip(["name", "empire"], ["Nigel", "The British Empire"]))
     record3 = Record(zip(["name", "empire"], ["Stefan", "Das Deutschland"]))
     assert record1 == record2
     assert record1 != record3
     assert record2 != record3
 def test_record_contains(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertTrue("Alice" in r)
     self.assertTrue(33 in r)
     self.assertTrue(True in r)
     self.assertFalse(7.5 in r)
     with self.assertRaises(TypeError):
         _ = r.index(None)
Example #4
0
 def test_record_items(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(r.items(), [("name", "Alice"), ("age", 33), ("married", True)])
     self.assertEqual(r.items("name"), [("name", "Alice")])
     self.assertEqual(r.items("age", "name"), [("age", 33), ("name", "Alice")])
     self.assertEqual(r.items("age", "name", "shoe size"), [("age", 33), ("name", "Alice"), ("shoe size", None)])
     self.assertEqual(r.items(0, "name"), [("name", "Alice"), ("name", "Alice")])
     self.assertEqual(r.items(0), [("name", "Alice")])
     self.assertEqual(r.items(1, 0), [("age", 33), ("name", "Alice")])
     with self.assertRaises(IndexError):
         _ = r.items(1, 0, 999)
Example #5
0
 def test_record_data(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(r.data(), {"name": "Alice", "age": 33, "married": True})
     self.assertEqual(r.data("name"), {"name": "Alice"})
     self.assertEqual(r.data("age", "name"), {"age": 33, "name": "Alice"})
     self.assertEqual(r.data("age", "name", "shoe size"), {"age": 33, "name": "Alice", "shoe size": None})
     self.assertEqual(r.data(0, "name"), {"name": "Alice"})
     self.assertEqual(r.data(0), {"name": "Alice"})
     self.assertEqual(r.data(1, 0), {"age": 33, "name": "Alice"})
     with self.assertRaises(IndexError):
         _ = r.data(1, 0, 999)
 def test_record_index(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(r.index("name"), 0)
     self.assertEqual(r.index("age"), 1)
     self.assertEqual(r.index("married"), 2)
     with self.assertRaises(KeyError):
         _ = r.index("shoe size")
     self.assertEqual(r.index(0), 0)
     self.assertEqual(r.index(1), 1)
     self.assertEqual(r.index(2), 2)
     with self.assertRaises(IndexError):
         _ = r.index(3)
     with self.assertRaises(TypeError):
         _ = r.index(None)
 def test_record_as_dict(self):
     a_record = Record(
         zip(["name", "empire"], ["Nigel", "The British Empire"]))
     assert dict(a_record) == {
         "name": "Nigel",
         "empire": "The British Empire"
     }
 def test_record_len(self):
     a_record = Record(
         zip(["name", "empire"], ["Nigel", "The British Empire"]))
     assert len(a_record) == 2
 def test_record_as_list(self):
     a_record = Record(
         zip(["name", "empire"], ["Nigel", "The British Empire"]))
     assert list(a_record) == ["Nigel", "The British Empire"]
 def test_record_iter(self):
     a_record = Record(
         zip(["name", "empire"], ["Nigel", "The British Empire"]))
     assert list(a_record.__iter__()) == ["Nigel", "The British Empire"]
 def test_record_get_by_out_of_bounds_index(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertIsNone(r[9])
 def test_record_get_by_name(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual("Alice", r["name"])
 def test_record_from_dict(self):
     r = Record({"name": "Alice", "age": 33})
     self.assertEqual("Alice", r["name"])
     self.assertEqual(33, r["age"])
 def test_record_value(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(r.value(), "Alice")
     self.assertEqual(r.value("name"), "Alice")
     self.assertEqual(r.value("age"), 33)
     self.assertEqual(r.value("married"), True)
     self.assertEqual(r.value("shoe size"), None)
     self.assertEqual(r.value("shoe size", 6), 6)
     self.assertEqual(r.value(0), "Alice")
     self.assertEqual(r.value(1), 33)
     self.assertEqual(r.value(2), True)
     self.assertEqual(r.value(3), None)
     self.assertEqual(r.value(3, 6), 6)
     with self.assertRaises(TypeError):
         _ = r.value(None)
Example #15
0
 def hydrate_records(self, keys, record_values):
     for values in record_values:
         yield Record(zip(keys, self.hydrate(values)))
 def test_record_repr(self):
     a_record = Record(
         zip(["name", "empire"], ["Nigel", "The British Empire"]))
     assert repr(
         a_record) == "<Record name='Nigel' empire='The British Empire'>"
 def test_record_keys(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(r.keys(), ["name", "age", "married"])
 def test_record_get_slice(self):
     r = Record(zip(["name", "age", "married"], ["Alice", 33, True]))
     self.assertEqual(Record(zip(["name", "age"], ["Alice", 33])), r[0:2])