Kaya Module SDK.
Project description
KayaModuleSDK
[ KIT ]: Kaya Integration Testing Framework
Overview
The Kaya Integration Testing (KIT) Framework is a lightweight, Python-based framework built on top of pytest to automate API integration tests. KIT extracts test method parameters, dynamically determines API endpoints based on test class names, executes HTTP requests via curl, and injects the response back into the test function. The framework is designed with low coupling and high cohesion in mind, where each component has a clear, focused responsibility.
Architecture and Design Principles
Low Coupling
- Modular Responsibilities: Each method in the KIT class handles a distinct task (e.g., precondition checks, constructing HTTP requests, executing shell commands). This minimizes dependencies between different parts of the code.
- Explicit Interfaces: The KIT class methods accept parameters and return structured data (e.g., a response dictionary) so that changes in one area (such as shell command execution) have minimal impact on other areas (like response parsing).
High Cohesion
- Single Responsibility: Methods like
check_preconditions(),module_request(), andshell_cmd()each encapsulate a single, well-defined behavior. - Clear Separation of Concerns: The KIT framework separates:
- Precondition checks: Verifying that the necessary environment and module dependencies are present.
- HTTP request execution: Building and executing a
curlcommand to send requests. - Response processing: Parsing and packaging the server’s response for use in tests.
- Test decoration: The
requestdecorator extracts method parameters and injects the HTTP response into test methods.
Key Components
1. KIT Class Configuration
- Web Server Settings:
_webserver_protocol,_webserver_host,_webserver_port, and_webserver_methodare defined as class attributes for easy configuration.
- Run-Time Execution:
- The
runclass method wraps test functions to execute integration tests. It extracts arguments from anArgsobject, checks preconditions, sends a request, processes the response, and passes the results to the test.
- The
2. Decorators and Request Handling
@KIT.runDecorator:- Responsibility:
- Extracts named arguments from the test method.
- Constructs a JSON payload from these arguments.
- Dynamically builds the API endpoint URL using the test class name.
- Executes a
curlcommand and processes the response. - Injects the response as a
responsekeyword argument into the test method.
- Design Decisions:
- Uses
functools.wrapsto preserve metadata. - Keeps the HTTP request logic separated from test assertions.
- Uses
- Responsibility:
3. Preconditions and Module Validation
- Precondition Checks:
check_preconditions()aggregates general checks (e.g., webserver availability) and module-specific checks (e.g., package installation, module existence).- Individual helper methods such as
check_webserver_running(),check_package_installed(), andcheck_module_exists()handle specific validations.
- Benefits:
- The separation of these concerns makes it easier to modify or extend precondition checks without affecting other parts of the system.
4. Module Request and Shell Command Execution
module_request():- Converts a given request body to JSON.
- Constructs the curl command with proper headers.
- Invokes
shell_cmd()to execute the command and then parses the response.
shell_cmd():- Encapsulates the logic to execute a shell command (using
subprocess.Popen) and return decoded output. - Handles user context and ensures proper cleanup of subprocess resources.
- Encapsulates the logic to execute a shell command (using
- Cohesion Aspect:
- Both methods are focused on the execution and handling of external processes, thereby keeping their functionality isolated from higher-level test logic.
5. Utility Methods
_get_method_kwargs():- Uses the
inspectmodule to extract default keyword arguments from test functions. - This supports the dynamic configuration of test parameters without hard-coding them in multiple places.
- Uses the
Workflow
- Pre-Test Phase:
- The test method is decorated with
@KIT.run. - When the test method is invoked, the
wrapper()function extracts any provided keyword arguments.
- The test method is decorated with
- Request Phase:
- The API endpoint URL is constructed based on specified data or on the module Args class name (e.g.,
ADDArgsmaps to/ADD). - A JSON payload is built from the test method’s named parameters.
- A
curlcommand is constructed and executed.
- The API endpoint URL is constructed based on specified data or on the module Args class name (e.g.,
- Response Phase:
- The output from the curl command is parsed.
- The parsed JSON (or raw text if JSON parsing fails) along with status information is packaged into a response dictionary.
- Injection Phase:
- The original test function is called with the response injected as a keyword argument (
response), along with the original parameters.
- The original test function is called with the response injected as a keyword argument (
- Test Assertions:
- The test function then performs assertions on both its input parameters and the injected response.
Error Handling and Exceptions
- Preconditions:
- If preconditions are not met, a
KITFailureExceptionis raised.
- If preconditions are not met, a
- Module Not Found:
- Specific exceptions such as
ModuleNotFoundExceptionare raised when expected modules or packages are missing.
- Specific exceptions such as
- Shell Command Execution:
- The exit code and error output from shell commands are captured and used to determine if an error occurred during the HTTP request.
Example KIT usage
from kaya_core_modules.module import ADDArgs, ADDRets
from kaya_module_sdk.sdk import setup_kit_framework
KIT = setup_kit_framework(legacy=False)
@KIT.run(
ADDArgs(first_value=[1], second_value=[2]),
# NOTE: Optionally, you can specify:
# package='kaya_core_modules',
# module='ADD'
)
def test_add_module(result = ADDRets):
assert result.sum == ['3.0']
[ KVL ]: Kaya Validation Framework
Overview
The Kaya Integration Testing (KIT/KVL) Framework is a modular, Python‑based testing solution built on top of pytest. The framework is designed with low coupling and high cohesion in mind, where each module has a single, focused responsibility:
-
KVL (Harness): Coordinates file and module loading, and delegates validation tasks.
-
KVLE (Executer): Executes various validations including linters (flake8), type checkers (mypy), and module metadata/rule checks. It also dynamically loads metadata constraint rules.
-
KVLR (Reporter): Formats, validates, and optionally dumps the aggregated validation results into a JSON report.
Design Principles
-
Low Coupling: Each component interacts with others via well‑defined interfaces and minimal dependencies. For instance, file loading, module importation, validation execution, and reporting are handled by separate modules.
-
High Cohesion: Each module is focused on a single aspect of the overall process:
- KVL (Harness) is responsible for locating and loading source files and modules.
- KVLE (Executer) handles executing various validation checks.
- KVLR (Reporter) focuses on formatting and outputting test reports.
-
Extensibility: The design makes it straightforward to extend functionality:
- Adding new validation checks in KVLE.
- Supporting additional report formats in KVLR.
- Adjusting file/module search strategies in KVL.
Modules
1. KVL (Harness)
- Location:
kaya_module_sdk/src/testing/kvl_harness.py - Responsibilities:
- Search for Python files in directories.
- Load Python files and module packages.
- Delegate validation actions to KVLE and reporting to KVLR.
- Key Methods:
search_python_files_in_dir(dir_path): Recursively finds all Python source files.load_python_files(target_files): Reads the content of each file.load_module_package(module_name): Imports and instantiates a module package.check_rules(),check_meta(), andcheck_source(): Entry points for different validation types.check(*targets, **kwargs): Main entry point that selects and runs one or more validations based on provided targets.
2. KVLE (Executer)
- Location:
kaya_module_sdk/src/testing/kvl_executer.py - Responsibilities:
- Execute various validations (e.g., linting, type-checking, metadata rules).
- Load constraint rules dynamically from a set of metadata constraint classes.
- Aggregate validation results for rules, metadata, and source code.
- Key Methods:
check_package_installed(test): Verifies that the required package is installed.load_constraint_rules(*rules): Loads and validates constraint rules.check_rules(): Aggregates rule validation results.check_meta(module_data, report=True): Aggregates metadata validation results.check_source(loaded_files, report=True): Runs source code validations using external tools like flake8 and mypy.
3. KVLR (Reporter)
- Location:
kaya_module_sdk/src/testing/kvl_reporter.py - Responsibilities:
- Format the aggregated validation results from KVLE.
- Generate a human‑readable report and optionally dump it as a JSON file.
- Key Methods:
_check_dump_file_path(): Validates that the report file’s parent directory exists and is writable._check_kvle_results(*results): Verifies that results are in a valid format._dump_test_results_report_json(formatted_results, file_path): Dumps the formatted results to a file._format_validation_result(result): Formats individual validation result groups._format_validation_report(*results): Merges and formats multiple result dictionaries.generate_report(*results, dump=False): Main method to produce and optionally dump the final report.
Usage
Running Validations
The main entry point for executing validations is through the KVL class. A user may create an instance of KVL, provide file paths or a module package name, and then invoke one or more of the check methods:
from kaya_module_sdk.src.testing.kvl_harness import KVL
# Example: Validate module rules
kvl = KVL("path/to/source", module_name="dummy_module")
rules_report = kvl.check_rules(module="dummy_module", dump_report=True)
# Example: Validate module metadata
meta_report = kvl.check_meta(module="dummy_module", dump_report=False)
# Example: Validate source code files
source_report = kvl.check_source(file_path="path/to/file.py", dump_report=False)
# Example: Run multiple validations
overall_report = kvl.check("meta", "source", "rules", module="dummy_module", file_path="path/to/file.py", dump_report=True)
# OR
overall_report = kvl.check("all", module="dummy_module", file_path="path/to/file.py", dump_report=True)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kaya_module_sdk-2.1.10.tar.gz.
File metadata
- Download URL: kaya_module_sdk-2.1.10.tar.gz
- Upload date:
- Size: 59.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29e84ed5abbd8193ee0ceb4cb5dff29d6bfdcf84971a17c9cfa534b710dc0e2b
|
|
| MD5 |
d65e0fc15f8fa5cede0fa43ff2501314
|
|
| BLAKE2b-256 |
14d2d97cdca005106194c54a86422013fefe7a5c8c4b00fdcb8859c52a4c05c3
|
Provenance
The following attestation bundles were made for kaya_module_sdk-2.1.10.tar.gz:
Publisher:
kmpv2_publish.yaml on WanoLabs/KayaModulePackerV2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaya_module_sdk-2.1.10.tar.gz -
Subject digest:
29e84ed5abbd8193ee0ceb4cb5dff29d6bfdcf84971a17c9cfa534b710dc0e2b - Sigstore transparency entry: 207624030
- Sigstore integration time:
-
Permalink:
WanoLabs/KayaModulePackerV2@8d4ff58ae2423b70bcd4ac79ea03e39fe8ec8c4f -
Branch / Tag:
refs/heads/feature/classifier_module - Owner: https://github.com/WanoLabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
kmpv2_publish.yaml@8d4ff58ae2423b70bcd4ac79ea03e39fe8ec8c4f -
Trigger Event:
push
-
Statement type:
File details
Details for the file kaya_module_sdk-2.1.10-py3-none-any.whl.
File metadata
- Download URL: kaya_module_sdk-2.1.10-py3-none-any.whl
- Upload date:
- Size: 105.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1dfe7e512f078b1ec550a1c8ccc05566d97b9d60615ed8e1c09092889412bb6e
|
|
| MD5 |
216f3bc56233f495276903c2cb7dacaf
|
|
| BLAKE2b-256 |
beb2baf761a186d46f48ad902322ac64c5a810b3c5b08b1e6ac83f4b6b4da0fc
|
Provenance
The following attestation bundles were made for kaya_module_sdk-2.1.10-py3-none-any.whl:
Publisher:
kmpv2_publish.yaml on WanoLabs/KayaModulePackerV2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kaya_module_sdk-2.1.10-py3-none-any.whl -
Subject digest:
1dfe7e512f078b1ec550a1c8ccc05566d97b9d60615ed8e1c09092889412bb6e - Sigstore transparency entry: 207624032
- Sigstore integration time:
-
Permalink:
WanoLabs/KayaModulePackerV2@8d4ff58ae2423b70bcd4ac79ea03e39fe8ec8c4f -
Branch / Tag:
refs/heads/feature/classifier_module - Owner: https://github.com/WanoLabs
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
kmpv2_publish.yaml@8d4ff58ae2423b70bcd4ac79ea03e39fe8ec8c4f -
Trigger Event:
push
-
Statement type: