stubs
This directory contains mock implementations of the Talon Voice API. Since the native Talon Voice application runner is closed-source and only available within its active runtime environment, executing unit tests or static analysis tools (such as in a continuous integration pipeline or local terminal) would normally fail with a ModuleNotFoundError.
These stubs isolate the test environment by providing a safe, mock interface that mimics Talon's core and experimental APIs, allowing community scripts to be imported, analyzed, and tested without running the actual Talon application.
Integration and Core Configuration
The stubs are designed to seamlessly intercept Python's import system during testing:
README: Explains that the directory is injected into the Python import path (sys.path) viapytest'spythonpathconfiguration (defined inpyproject.toml). This ensures that when a test executesimport talon, Python loads these mock definitions rather than searching for the native runtime. While many of the stubs act as simple no-ops to prevent crashes, others (like the action system) provide functional behavior to enable unit testing and introspection.
Subdirectories and Components
talon
This is the primary mock entry point for the talon package. It stubs out the foundational components of the Talon API:
- Actions Management: Implements mock
ActionsandRegisteredActionsAccessorclasses to mimic Talon's action dispatching system. It provides basic built-in actions (e.g.,key,insert,sleep) and allows tests to register custom actions and reset them between runs. - Modules and Contexts: Provides dummy
ModuleandContextclasses. TheModule.action_classdecorator automatically registers user-defined action classes into the mockActionssystem. - UI, Settings, and Resources: Stubs out components like configuration registries, UI frameworks, and application environment parameters (e.g., defaulting the platform to
"mac"during tests). - Environment Flag: Exposes a
test_mode = Trueflag, which allows user scripts to detect if they are running inside a test runner and adjust their behavior dynamically. - Grammar Engine: Stubs out classes like
Phraseso that runtime type checks or annotations do not raise reference errors.
talon/experimental
This subdirectory provides mock representations for Talon's experimental APIs, ensuring that scripts leveraging newer or unstable features can still be tested:
- Experimental UI Components: Stubs out objects in the
talon.experimental.textareanamespace (such asTextArea,Span,DarkThemeLabels, andLightThemeLabels). By defining these complex graphical elements as safe defaults (likeNone), user scripts that import them can compile and initialize successfully in non-GUI (headless) test environments.
How the Stubs Work Together
When you run a test suite against your Talon scripts:
- Path Interception:
pytestprepends this directory to the Python import path. - Module Registration: When your scripts execute
from talon import Module, Context, the stubbed classes intalonare loaded. - Action Discovery: As your script defines custom actions using
@mod.action_class, the mockModuleclass intercepts these declarations and registers them into a central, in-memory actions registry. - Experimental Safeguards: If your script utilizes advanced user interface elements, the imports are resolved through
talon/experimentalwithout trying to spin up a graphical rendering engine. - Assertion and Introspection: Your unit tests can now safely call user-defined actions, mock specific behavior, and verify that the scripts execute the expected logical paths.