Skip to content

talon

The community/test/stubs/talon directory provides stub implementations of various Talon modules and classes. These stubs are used in tests to simulate the Talon environment without needing a full Talon installation. This allows for isolated testing of Talon scripts.

The directory contains one subdirectory, experimental, and two files: __init__.py and grammar.py.

The experimental subdirectory contains stubs for experimental Talon features. As of now, it only includes textarea.py, which provides type hints for the TextArea related classes.

The __init__.py file is the main stub file. It defines classes that mimic key Talon components such as actions, Module, Context, ImgUI, UI, Settings, Registry, Resource, and App. These classes provide simplified implementations of their Talon counterparts, allowing tests to interact with them without relying on the actual Talon runtime.

Here is a breakdown of key components within __init__.py:

  • Actions: This class simulates the talon.actions module. It allows tests to register and call actions. It includes helper functions for module and test action registration, and provides an error if actions are called incorrectly.
  • Module: This class simulates the talon.Module class. It provides stub implementations for list, setting, capture, tag and action_class.
  • Context: This class simulates the talon.Context class, offering stub implementations of action_class and capture methods as well as a lists property.
  • ImgUI, UI, Settings, Registry, Resource, and App: These classes provide stubs for their respective Talon counterparts, preventing crashes and enabling basic interactions during testing.

The grammar.py file provides stub implementations of the Phrase class. This is used as a type hint in the community code, and this file prevents tests from incorrectly identifying actual objects as the stub Phrase type.

These stubs work together to create a mock Talon environment, allowing tests to run without a full Talon installation and without modifying the community codebase to suit testing needs. This enables better isolated and faster testing.