|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# The MIT License (MIT) |
| 4 | +# |
| 5 | +# Copyright (c) typedef int GmbH |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in |
| 15 | +# all copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +# THE SOFTWARE. |
| 24 | +# |
| 25 | +############################################################################### |
| 26 | + |
| 27 | +# Import smoke test for the framework-agnostic core modules. |
| 28 | +# |
| 29 | +# This guards against import-time regressions that only surface on some Python |
| 30 | +# versions - in particular eager evaluation of annotations on CPython < 3.14 |
| 31 | +# (PEP 649 defers it on 3.14): a string forward-reference combined with |
| 32 | +# ``| None`` (e.g. ``"ISecurityModule" | None``) raises ``TypeError`` at |
| 33 | +# class-definition time. See issue #1878. |
| 34 | +# |
| 35 | +# We import an explicit, curated set rather than walking every submodule: a full |
| 36 | +# single-process walk is unreliable for autobahn because (a) Twisted and asyncio |
| 37 | +# bindings are mutually exclusive in one process (txaio backend selection) and |
| 38 | +# (b) several modules require optional extras (snappy, flatbuffers runtime). |
| 39 | +# These core modules are framework-agnostic and must always import with the |
| 40 | +# crypto extras installed. |
| 41 | +# |
| 42 | +# IMPORTANT: run with crypto extras (``autobahn[all]`` / ``[encryption]`` -> |
| 43 | +# PyNaCl) so the ``autobahn.wamp.cryptosign`` ``HAS_CRYPTOSIGN`` code paths |
| 44 | +# (where #1878 lived) are actually exercised - see ``test_crypto_extras_present``. |
| 45 | + |
| 46 | +from __future__ import annotations |
| 47 | + |
| 48 | +import importlib |
| 49 | + |
| 50 | +import pytest |
| 51 | + |
| 52 | +CORE_MODULES = [ |
| 53 | + "autobahn", |
| 54 | + "autobahn.util", |
| 55 | + "autobahn.wamp", |
| 56 | + "autobahn.wamp.cryptosign", # regressed in 26.6.1 -> see #1878 |
| 57 | + "autobahn.wamp.auth", |
| 58 | + "autobahn.wamp.interfaces", |
| 59 | + "autobahn.wamp.types", |
| 60 | + "autobahn.wamp.message", |
| 61 | + "autobahn.wamp.role", |
| 62 | + "autobahn.wamp.serializer", |
| 63 | + "autobahn.wamp.component", |
| 64 | + "autobahn.websocket.protocol", |
| 65 | + "autobahn.websocket.types", |
| 66 | + "autobahn.websocket.compress", |
| 67 | +] |
| 68 | + |
| 69 | + |
| 70 | +@pytest.mark.parametrize("modname", CORE_MODULES) |
| 71 | +def test_import(modname): |
| 72 | + """ |
| 73 | + Importing each core autobahn module must not raise. |
| 74 | + """ |
| 75 | + importlib.import_module(modname) |
| 76 | + |
| 77 | + |
| 78 | +def test_crypto_extras_present(): |
| 79 | + """ |
| 80 | + The cryptosign import guard is only meaningful when PyNaCl is installed, |
| 81 | + since the ``autobahn.wamp.cryptosign`` class bodies (and thus the #1878 |
| 82 | + regression) are gated behind ``HAS_CRYPTOSIGN``. |
| 83 | + """ |
| 84 | + import autobahn.wamp.cryptosign as cryptosign |
| 85 | + |
| 86 | + assert ( |
| 87 | + cryptosign.HAS_CRYPTOSIGN |
| 88 | + ), "install crypto extras (autobahn[all] / [encryption]) so this import guard is exercised" |
0 commit comments