Skip to content

Commit 2af85c7

Browse files
committed
Update tests: for forbidden 'z' usage
Forbid '', 'd', and 'n' presentation types from using two's complements as per formatter_unicode::format_long_internal
1 parent 96a58ef commit 2af85c7

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Lib/test/test_format.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,19 @@ def test_specifier_z_error(self):
775775
with self.assertRaisesRegex(ValueError, error_msg):
776776
f"{0:fz}" # wrong position
777777

778-
error_msg = re.escape("Negative zero coercion (z) not allowed")
778+
error_msg = re.escape("Two's complement (z) requires precision (.) format specifier")
779+
with self.assertRaisesRegex(ValueError, error_msg):
780+
f"{0:zx}" # can't apply two's complement without precision
781+
782+
error_msg = re.escape("Two's complement (z) only allowed with integer presentation types 'b', 'o', 'x', and 'X'")
783+
with self.assertRaisesRegex(ValueError, error_msg):
784+
f"{0:z.8}" # can't apply to '' int presentation type
779785
with self.assertRaisesRegex(ValueError, error_msg):
780-
f"{0:zd}" # can't apply to int presentation type
786+
f"{0:z.8d}" # can't apply to 'd' int presentation type
787+
with self.assertRaisesRegex(ValueError, error_msg):
788+
f"{0:z.8n}" # can't apply to 'n' int presentation type
789+
790+
error_msg = re.escape("Negative zero coercion (z) not allowed")
781791
with self.assertRaisesRegex(ValueError, error_msg):
782792
f"{'x':zs}" # can't apply to string
783793

0 commit comments

Comments
 (0)