pybind11/tests/test_descr_src_loc.py
Ralf W. Grosse-Kunstleve a8bc5f7904 ruff automatic fixes: from __future__ import annotations
```
ruff.....................................................................Failed
- hook id: ruff
- files were modified by this hook

Fixed 44 errors:
- tests/test_class_sh_basic.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_disowning.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_disowning_mi.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_factory_constructors.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_inheritance.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_mi_thunks.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_module_local.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_property.py:
    1 × I002 (missing-required-import)
- tests/test_class_sh_property_non_owning.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_shared_ptr_copy_move.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_trampoline_basic.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_trampoline_self_life_support.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_trampoline_shared_from_this.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_trampoline_shared_ptr_cpp_arg.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_trampoline_unique_ptr.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_unique_ptr_custom_deleter.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_unique_ptr_member.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_class_sh_virtual_py_cpp_mix.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_classh_mock.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_descr_src_loc.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_exc_namespace_visibility.py:
    1 × I002 (missing-required-import)
- tests/test_type_caster_odr_guard_1.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)
- tests/test_type_caster_odr_guard_2.py:
    1 × I001 (unsorted-imports)
    1 × I002 (missing-required-import)

Found 44 errors (44 fixed, 0 remaining).
```
2024-06-21 23:00:13 -07:00

59 lines
1.7 KiB
Python

from __future__ import annotations
import pytest
from pybind11_tests import descr_src_loc as m
if m.block_descr_offset is None:
block_parametrize = (("all_blocks", None),)
else:
block_parametrize = (
("block_descr", (("", 1), ("Abc", 2), ("D", 3), ("Ef", 4))),
(
"block_const_name",
(
("G", 1),
("Hi", 2),
("0", 0),
("1", 0),
("23", 0),
("%", 6),
("J", 7),
("M", 8),
),
),
(
"block_underscore",
(
("G", 2),
("Hi", 3),
("0", 0),
("1", 0),
("23", 0),
("%", 7),
("J", 8),
("M", 9),
),
),
("block_plus", (("NO", 1), ("PQ", 4))),
("block_concat", (("R", 1), ("S, T", 2), ("U, V", 6))),
("block_type_descr", (("{W}", 1),)),
("block_int_to_str", (("", 0), ("4", 0), ("56", 0))),
)
@pytest.mark.skipif(m.block_descr_offset is None, reason="Not enabled.")
@pytest.mark.parametrize(("block_name", "expected_text_line"), block_parametrize)
def test_block(block_name, expected_text_line):
offset = getattr(m, f"{block_name}_offset")
for ix, (expected_text, expected_line) in enumerate(expected_text_line):
text, file, line = getattr(m, f"{block_name}_c{ix}")
assert text == expected_text
if expected_line:
assert file is not None, expected_text_line
assert file.endswith("test_descr_src_loc.cpp")
assert line == offset + expected_line
else:
assert file is None
assert line == 0