diff options
author | Barry Warsaw <barry@python.org> | 2021-09-16 02:55:24 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 02:55:24 (GMT) |
commit | 07e737d002cdbf0bfee53248a652a86c9f93f02b (patch) | |
tree | e7c371587a38da2e4e095e603d86fcaf8bc9b1a5 /Lib | |
parent | a9757bf34d8b4cb3c24bbb70d50a06c815e2e8f3 (diff) | |
download | cpython-07e737d002cdbf0bfee53248a652a86c9f93f02b.zip cpython-07e737d002cdbf0bfee53248a652a86c9f93f02b.tar.gz cpython-07e737d002cdbf0bfee53248a652a86c9f93f02b.tar.bz2 |
bpo-45155 : Default arguments for int.to_bytes(length=1, byteorder=sys.byteorder) (#28265)
Add default arguments for int.to_bytes() and int.from_bytes()
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_call.py | 2 | ||||
-rw-r--r-- | Lib/test/test_long.py | 24 |
2 files changed, 23 insertions, 3 deletions
diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index 1d27452..6936f09 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -39,7 +39,7 @@ class CFunctionCallsErrorMessages(unittest.TestCase): self.assertRaisesRegex(TypeError, msg, {}.__contains__, 0, 1) def test_varargs3(self): - msg = r"^from_bytes\(\) takes exactly 2 positional arguments \(3 given\)" + msg = r"^from_bytes\(\) takes at most 2 positional arguments \(3 given\)" self.assertRaisesRegex(TypeError, msg, int.from_bytes, b'a', 'little', False) def test_varargs1min(self): diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py index 1de75bf..e15bf8b 100644 --- a/Lib/test/test_long.py +++ b/Lib/test/test_long.py @@ -1117,9 +1117,18 @@ class LongTest(unittest.TestCase): expected) except Exception as err: raise AssertionError( - "failed to convert {0} with byteorder={1} and signed={2}" + "failed to convert {} with byteorder={} and signed={}" .format(test, byteorder, signed)) from err + # Test for all default arguments. + if len(expected) == 1 and byteorder == 'big' and not signed: + try: + self.assertEqual(test.to_bytes(), expected) + except Exception as err: + raise AssertionError( + "failed to convert {} with default arguments" + .format(test)) from err + try: self.assertEqual( equivalent_python( @@ -1240,9 +1249,20 @@ class LongTest(unittest.TestCase): expected) except Exception as err: raise AssertionError( - "failed to convert {0} with byteorder={1!r} and signed={2}" + "failed to convert {} with byteorder={!r} and signed={}" .format(test, byteorder, signed)) from err + # Test for all default arguments. + if byteorder == 'big' and not signed: + try: + self.assertEqual( + int.from_bytes(test), + expected) + except Exception as err: + raise AssertionError( + "failed to convert {} with default arugments" + .format(test)) from err + try: self.assertEqual( equivalent_python(test, byteorder, signed=signed), |