summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_long.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2021-09-16 02:55:24 (GMT)
committerGitHub <noreply@github.com>2021-09-16 02:55:24 (GMT)
commit07e737d002cdbf0bfee53248a652a86c9f93f02b (patch)
treee7c371587a38da2e4e095e603d86fcaf8bc9b1a5 /Lib/test/test_long.py
parenta9757bf34d8b4cb3c24bbb70d50a06c815e2e8f3 (diff)
downloadcpython-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.py24
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),