MCPcopy Index your code
hub / github.com/python/cpython / test_sequence_index

Method test_sequence_index

Lib/test/test_capi/test_abstract.py:958–976  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

956 # CRASHES contains(NULL, 'a')
957
958 def test_sequence_index(self):
959 index = _testlimitedcapi.sequence_index
960
961 lst = ['a', 'b', 'a']
962 self.assertEqual(index(lst, 'a'), 0)
963 self.assertEqual(index(lst, 'b'), 1)
964 self.assertRaises(ValueError, index, lst, 'c')
965 self.assertEqual(index(iter(lst), 'a'), 0)
966 self.assertEqual(index(iter(lst), 'b'), 1)
967 self.assertRaises(ValueError, index, iter(lst), 'c')
968 dct = {'a': 2, 'b': 3}
969 self.assertEqual(index(dct, 'a'), 0)
970 self.assertEqual(index(dct, 'b'), 1)
971 self.assertRaises(ValueError, index, dct, 'c')
972
973 self.assertRaises(TypeError, index, 42, 'a')
974 self.assertRaises(SystemError, index, [], NULL)
975 self.assertRaises(SystemError, index, [1], NULL)
976 self.assertRaises(SystemError, index, NULL, 'a')
977
978 def test_sequence_list(self):
979 xlist = _testlimitedcapi.sequence_list

Callers

nothing calls this directly

Calls 3

indexFunction · 0.85
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected