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/test/test_long.py | |
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/test/test_long.py')
-rw-r--r-- | Lib/test/test_long.py | 24 |
1 files changed, 22 insertions, 2 deletions
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), |