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

Method test_bad_newobj_ex_args

Lib/test/pickletester.py:1917–1978  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1915 f'when serializing {REX.__module__}.REX object'])
1916
1917 def test_bad_newobj_ex_args(self):
1918 obj = REX((copyreg.__newobj_ex__, ()))
1919 for proto in protocols[2:]:
1920 with self.subTest(proto=proto):
1921 with self.assertRaises((ValueError, pickle.PicklingError)) as cm:
1922 self.dumps(obj, proto)
1923 self.assertIn(str(cm.exception), {
1924 'not enough values to unpack (expected 3, got 0)',
1925 '__newobj_ex__ expected 3 arguments, got 0'})
1926 self.assertEqual(cm.exception.__notes__, [
1927 f'when serializing {REX.__module__}.REX object'])
1928
1929 obj = REX((copyreg.__newobj_ex__, 42))
1930 for proto in protocols[2:]:
1931 with self.subTest(proto=proto):
1932 with self.assertRaises(pickle.PicklingError) as cm:
1933 self.dumps(obj, proto)
1934 self.assertEqual(str(cm.exception),
1935 'second item of the tuple returned by __reduce__ '
1936 'must be a tuple, not int')
1937 self.assertEqual(cm.exception.__notes__, [
1938 f'when serializing {REX.__module__}.REX object'])
1939
1940 obj = REX((copyreg.__newobj_ex__, (REX, 42, {})))
1941 if self.pickler is pickle._Pickler:
1942 for proto in protocols[2:4]:
1943 with self.subTest(proto=proto):
1944 with self.assertRaises(TypeError) as cm:
1945 self.dumps(obj, proto)
1946 self.assertEqual(str(cm.exception),
1947 'Value after * must be an iterable, not int')
1948 self.assertEqual(cm.exception.__notes__, [
1949 f'when serializing {REX.__module__}.REX object'])
1950 else:
1951 for proto in protocols[2:]:
1952 with self.subTest(proto=proto):
1953 with self.assertRaises(pickle.PicklingError) as cm:
1954 self.dumps(obj, proto)
1955 self.assertEqual(str(cm.exception),
1956 'second argument to __newobj_ex__() must be a tuple, not int')
1957 self.assertEqual(cm.exception.__notes__, [
1958 f'when serializing {REX.__module__}.REX object'])
1959
1960 obj = REX((copyreg.__newobj_ex__, (REX, (), [])))
1961 if self.pickler is pickle._Pickler:
1962 for proto in protocols[2:4]:
1963 with self.subTest(proto=proto):
1964 with self.assertRaises(TypeError) as cm:
1965 self.dumps(obj, proto)
1966 self.assertEqual(str(cm.exception),
1967 'Value after ** must be a mapping, not list')
1968 self.assertEqual(cm.exception.__notes__, [
1969 f'when serializing {REX.__module__}.REX object'])
1970 else:
1971 for proto in protocols[2:]:
1972 with self.subTest(proto=proto):
1973 with self.assertRaises(pickle.PicklingError) as cm:
1974 self.dumps(obj, proto)

Callers

nothing calls this directly

Calls 7

REXClass · 0.85
strFunction · 0.85
assertInMethod · 0.80
subTestMethod · 0.45
assertRaisesMethod · 0.45
dumpsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected