Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test to verify package modules are accessible as symbols #422

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test_kcidb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""kcidb namespace tests"""

import pkgutil
import importlib
import re
import json
import textwrap
Expand Down Expand Up @@ -32,6 +34,25 @@ def test_json_output_options():
stdout_re="\\{\n \".*")


def test_package_symbols():
"""
Test that package modules are accessible as symbols after importing
the package's module (__init__.py).
"""

def check_package(package):
for _, module_name, is_pkg in pkgutil.iter_modules(package.__path__):
module_fullname = f"{package.__name__}.{module_name}"
module = importlib.import_module(module_fullname)
symbol = getattr(package, module_name, None)
assert symbol is module, \
f"{package.__name__} missing for submodule {module_name}. "\
f"Expected symbol is {module}, but actual symbol is {symbol}."
if is_pkg:
check_package(module)
check_package(kcidb)


def test_submit_main():
"""Check kcidb-submit works"""
driver_source = textwrap.dedent("""
Expand Down