MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_cmp_to_key_arguments

Method test_cmp_to_key_arguments

Lib/test/test_functools.py:1108–1126  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1106 self.assertNotEqual(key(2), key('35'))
1107
1108 def test_cmp_to_key_arguments(self):
1109 def cmp1(x, y):
1110 return (x > y) - (x < y)
1111 key = self.cmp_to_key(mycmp=cmp1)
1112 self.assertEqual(key(obj=3), key(obj=3))
1113 self.assertGreater(key(obj=3), key(obj=1))
1114 with self.assertRaises((TypeError, AttributeError)):
1115 key(3) > 1 # rhs is not a K object
1116 with self.assertRaises((TypeError, AttributeError)):
1117 1 < key(3) # lhs is not a K object
1118 with self.assertRaises(TypeError):
1119 key = self.cmp_to_key() # too few args
1120 with self.assertRaises(TypeError):
1121 key = self.cmp_to_key(cmp1, None) # too many args
1122 key = self.cmp_to_key(cmp1)
1123 with self.assertRaises(TypeError):
1124 key() # too few args
1125 with self.assertRaises(TypeError):
1126 key(None, None) # too many args
1127
1128 def test_bad_cmp(self):
1129 def cmp1(x, y):

Callers 1

Calls 3

assertGreaterMethod · 0.80
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected