MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_check_encoding_errors

Method test_check_encoding_errors

Lib/test/test_str.py:2625–2683  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2623
2624 @unittest.expectedFailure # TODO: RUSTPYTHON; AssertionError: 22 != 10 : _PythonRunResult(rc=22, out=b'', err=b'')
2625 def test_check_encoding_errors(self):
2626 # bpo-37388: str(bytes) and str.decode() must check encoding and errors
2627 # arguments in dev mode
2628 encodings = ('ascii', 'utf8', 'latin1')
2629 invalid = 'Boom, Shaka Laka, Boom!'
2630 code = textwrap.dedent(f'''
2631 import sys
2632 encodings = {encodings!r}
2633
2634 for data in (b'', b'short string'):
2635 try:
2636 str(data, encoding={invalid!r})
2637 except LookupError:
2638 pass
2639 else:
2640 sys.exit(21)
2641
2642 try:
2643 str(data, errors={invalid!r})
2644 except LookupError:
2645 pass
2646 else:
2647 sys.exit(22)
2648
2649 for encoding in encodings:
2650 try:
2651 str(data, encoding, errors={invalid!r})
2652 except LookupError:
2653 pass
2654 else:
2655 sys.exit(22)
2656
2657 for data in ('', 'short string'):
2658 try:
2659 data.encode(encoding={invalid!r})
2660 except LookupError:
2661 pass
2662 else:
2663 sys.exit(23)
2664
2665 try:
2666 data.encode(errors={invalid!r})
2667 except LookupError:
2668 pass
2669 else:
2670 sys.exit(24)
2671
2672 for encoding in encodings:
2673 try:
2674 data.encode(encoding, errors={invalid!r})
2675 except LookupError:
2676 pass
2677 else:
2678 sys.exit(24)
2679
2680 sys.exit(10)
2681 ''')
2682 proc = assert_python_failure('-X', 'dev', '-c', code)

Callers

nothing calls this directly

Calls 3

assert_python_failureFunction · 0.90
dedentMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected