Pārlūkot izejas kodu

Make the test suite collectable

The tests import `adapter` and `platform_config` as top-level modules,
but the plugin root is a package: adapter.py and __init__.py used
package-relative imports that fail in that context, so pytest could not
even collect the suite. Fall back to the absolute import when loaded
outside the package, the way platform_config.py already does.

Configure pytest accordingly: --import-mode=importlib (the default
"prepend" mode derives a package name from the checkout directory, which
is not a valid Python identifier), and restrict collection to our two
test files — vendor/ ships the upstream test suites of certifi and
others, which pytest happily collected too.

The suite now runs: 29 passed, 14 failed. All 14 failures predate this
branch — they reference an API the adapter never had (get_user,
set_presence, set_custom_status, clear_custom_status, supports_threads,
MAX_MESSAGE_LENGTH, edit_message, delete_message: absent on main too),
expect the platform name "chatto" where main already says
"chatto-platform", assert that _get_env_or_extra_str returns None where
main also returns "", or mock the client with MagicMock so awaiting it
raises. Fixing those is a separate change.
Paul Klumpp 1 nedēļu atpakaļ
vecāks
revīzija
823c47e264
3 mainītis faili ar 20 papildinājumiem un 2 dzēšanām
  1. 4 1
      __init__.py
  2. 6 1
      adapter.py
  3. 10 0
      pyproject.toml

+ 4 - 1
__init__.py

@@ -1,4 +1,7 @@
-from .adapter import register
+try:
+    from .adapter import register
+except ImportError:  # pragma: no cover - loaded outside a package (tests)
+    from adapter import register
 
 __all__ = ["register"]
 

+ 6 - 1
adapter.py

@@ -82,7 +82,12 @@ except ImportError as e:
     raise
 
 
-from .platform_config import (
+try:
+    from .platform_config import (
+        ChattoConfiguration, ChattoConstants,
+    )
+except ImportError:  # pragma: no cover - loaded as a top-level module (tests)
+    from platform_config import (
         ChattoConfiguration, ChattoConstants,
     )
 

+ 10 - 0
pyproject.toml

@@ -24,3 +24,13 @@ dev = [
 
 [tool.setuptools.packages.find]
 where = ["."]
+
+[tool.pytest.ini_options]
+# importlib mode: the plugin root is itself a package (__init__.py), so pytest's
+# default "prepend" mode tries to import the test modules as part of it, which
+# fails because the checkout directory name is not a valid Python identifier.
+addopts = "--import-mode=importlib"
+asyncio_mode = "auto"
+# Only our own tests — vendor/ ships the upstream test suites of some packages.
+testpaths = ["test_adapter.py", "test_platform_config.py"]
+norecursedirs = ["vendor", "myvenv", ".venv"]