Skip to content

ctk3b/borderline

Repository files navigation

Borderline

Stop letting modules reach into other modules.


python-package PyPI version fury.io

This library provides one thing and one thing only: a test class called ModuleImports

To use the test, subclass it in the test suite of the module you want to isolate and define that module's borderlines. The test will fail if a module is not respecting those borderlines.

For example, a module called report_builder could have the following definition:

class TestReportBuilder(borderline.ModuleImports):
    module = "reporting.report_builder"
    
    # The public API of the module.
    # External modules should only import from here.
    public_submodules = (
        "reporting.report_builder.api",
    )
    # Modules that are considered outside of `module` and should not be imported
    # by `module` unless they are a legitimate dependency.
    external_modules = (
        "reporting",
    )
    # Modules outside of `module` that ARE legitimate dependencies.
    external_dependencies = (
        "reporting.review.api",
        "reporting.common",
    )

    # Directory to store imports that are currently allowed.
    # This is useful when you are trying to isolate an existing module
    # that is not respecting its borderlines.
    grandfather_filedir = Path(
        "reporting/report_builder/tests/data/borderline", parents=True, exist_ok=True
    )

About

Stop letting modules reach into other modules

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages