|
| 1 | +# This is not really a unit test, but probing environment/toolchain/platform-specific |
| 2 | +# behavior under the exact same conditions as normal tests. |
| 3 | +# The results are useful to understanding the effects of, e.g., removing |
| 4 | +# `-fvisibility=hidden` or `__attribute__((visibility("hidden")))`, or linking |
| 5 | +# extensions statically with the core Python interpreter. |
| 6 | + |
| 7 | +import itertools |
| 8 | + |
| 9 | +import namespace_visibility_1 |
| 10 | +import namespace_visibility_2 |
| 11 | +import pytest |
| 12 | + |
| 13 | + |
| 14 | +def test_namespace_visibility(): |
| 15 | + modules = ( |
| 16 | + namespace_visibility_1, |
| 17 | + namespace_visibility_1.submodule, |
| 18 | + namespace_visibility_2, |
| 19 | + ) |
| 20 | + unique_pointer_labels = "ABC" |
| 21 | + unique_pointers_observed = [] |
| 22 | + # u = visibility unspecified |
| 23 | + # h = visibility hidden |
| 24 | + for visibility in itertools.product(*([("u", "h")] * len(modules))): |
| 25 | + # See functions in namespace_visibility_*.cpp |
| 26 | + func = "ns_vis_" + "".join(visibility) + "_func" |
| 27 | + ptrs = [] |
| 28 | + uq_ptrs_obs = "" |
| 29 | + for vis, m in zip(visibility, modules): |
| 30 | + ptr = getattr(m, func)() |
| 31 | + ptrs.append(ptr) |
| 32 | + lbl = unique_pointer_labels[ptrs.index(ptr)] |
| 33 | + if vis == "h": |
| 34 | + # Encode u/h info as upper/lower case to make the final result |
| 35 | + # as compact as possible. |
| 36 | + lbl = lbl.lower() |
| 37 | + uq_ptrs_obs += lbl |
| 38 | + unique_pointers_observed.append(uq_ptrs_obs) |
| 39 | + all_unique_pointers_observed = ":".join(unique_pointers_observed) |
| 40 | + if all_unique_pointers_observed != "AAC:AAc:AaC:Aac:aAC:aAc:aaC:aac": |
| 41 | + pytest.skip( |
| 42 | + f"UNUSUAL all_unique_pointers_observed: {all_unique_pointers_observed}" |
| 43 | + ) |
0 commit comments