| 599 | ) |
| 600 | @pytest.mark.parametrize("use_str", [True, False]) |
| 601 | def test_py3_str_slicing(params, use_str): |
| 602 | # Note: much simpler in python because __repr__ is required to return str |
| 603 | safe_repr = SafeRepr() |
| 604 | safe_repr.locale_preferred_encoding = "ascii" |
| 605 | safe_repr.sys_stdout_encoding = params.get("sys_stdout_encoding", "ascii") |
| 606 | |
| 607 | safe_repr.maxother_outer = params["maxother_outer"] |
| 608 | |
| 609 | if not use_str: |
| 610 | |
| 611 | class MyObj(object): |
| 612 | def __repr__(self): |
| 613 | return params["input"] |
| 614 | |
| 615 | safe_repr_input = MyObj() |
| 616 | else: |
| 617 | safe_repr_input = params["input"] |
| 618 | expected_output = params["output"] |
| 619 | computed = safe_repr(safe_repr_input) |
| 620 | expected = repr(expected_output) |
| 621 | if use_str: |
| 622 | expected = repr(expected) |
| 623 | assert repr(computed) == expected |
| 624 | |
| 625 | # Check that we can json-encode the return. |
| 626 | assert json.dumps(computed) |
| 627 | |
| 628 | |
| 629 | def test_raw_bytes(): |