aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_node_source_scope.py
blob: e5a86ff2ac6f749d0b84b54b1ffc2551cef74c6e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
The file set `node_source` hands to the source-reading tests has to contain
the code those tests are about.

It is derived from the tree — `webrtc_server.py` and everything under
`transport/webrtc/` — so that a module split out later is read without anybody
adding it to a list. That only holds while the code actually lives there: a
class the session is built from, put anywhere else, would leave every
"nothing here does X" test in this suite silently not reading it.
"""

import inspect
from pathlib import Path

from meshbay_node.transport.webrtc_server import WebRTCPeerSession, WebRTCTransport
from node_source import TRANSPORT, webrtc_files


def test_every_class_the_transport_is_built_from_is_in_scope():
    scope = {p.resolve() for p in webrtc_files()}
    for cls in (WebRTCPeerSession, WebRTCTransport):
        for klass in cls.__mro__:
            if not klass.__module__.startswith("meshbay_node."):
                continue
            where = Path(inspect.getsourcefile(klass)).resolve()
            assert where in scope, (
                f"{klass.__qualname__} ({cls.__name__}) is defined in "
                f"{where.relative_to(TRANSPORT.parent)}, which the source-reading "
                f"tests do not read — move it under transport/webrtc/")


def test_the_scope_is_not_empty():
    files = webrtc_files()
    assert TRANSPORT / "webrtc_server.py" in files
    assert all(p.exists() for p in files)