コード例 #1
0
 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)
コード例 #2
0
 def test_record_contains(self):
     r = Record(["name", "age", "married"], ["Alice", 33, True])
     self.assertTrue("name" in r)
     self.assertTrue("age" in r)
     self.assertTrue("married" in r)
     self.assertFalse("shoe size" in r)
     self.assertTrue(0 in r)
     self.assertTrue(1 in r)
     self.assertTrue(2 in r)
     self.assertFalse(3 in r)
     with self.assertRaises(TypeError):
         _ = r.index(None)
コード例 #3
0
 def test_record_index(self):
     r = Record(["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)
コード例 #4
0
 def test_record_index(self):
     a_record = Record(["name", "empire"], ["Nigel", "The British Empire"])
     assert a_record.index("name") == 0
     assert a_record.index("empire") == 1
     with self.assertRaises(KeyError):
         a_record.index("crap")