Skip to content

test

The community/test directory contains tests for the community repository. It includes subdirectories with stub implementations of Talon APIs and several test files.

The stubs subdirectory contains stub implementations of Talon APIs used for testing. This allows tests to run without a full Talon installation, providing a more isolated and faster testing environment. It contains the following subdirectories and files:

  • stubs/README.md: This file provides an overview of the purpose of the stubs directory and how it is used in tests. It explains that the stub implementations are mostly no-ops but have some functionality for introspection and changing within tests.
  • stubs/talon: This directory contains the primary Talon stubs. It has a subdirectory stubs/talon/experimental, and two files: stubs/talon/__init__.py and stubs/talon/grammar.py.
  • stubs/talon/experimental: This subdirectory contains stubs for experimental Talon features. Currently it contains only stubs/talon/experimental/textarea.py, which provides type hints for the TextArea related classes.
  • stubs/talon/__init__.py: This file defines classes that mimic key Talon components, such as actions, Module, Context, ImgUI, UI, Settings, Registry, Resource, and App. These stubs provide simplified implementations of their Talon counterparts, allowing tests to interact with them without relying on the actual Talon runtime. The Actions class simulates the talon.actions module, allowing tests to register and call actions. The Module class simulates the talon.Module class, providing stub implementations for list, setting, capture, tag and action_class. The Context class simulates the talon.Context class, offering stub implementations of action_class and capture methods as well as a lists property.
  • stubs/talon/grammar.py: This file provides a stub implementation of the Phrase class, used as a type hint in the community code.

The following test files are located in the community/test directory:

  • test_formatters.py: This file tests the text formatting actions provided by core.formatters. It checks various formatting options such as SNAKE_CASE, NO_SPACES, CAPITALIZE, CAPITALIZE_FIRST_WORD, and CAPITALIZE_ALL_WORDS on different input strings.
  • test_create_spoken_forms.py: This file tests the functionality of core.create_spoken_forms, which is used to generate different spoken forms of phrases. It tests various aspects of the function, including excluding words, handling empty input, handling minimum term lengths, expanding special characters, expanding abbreviations, handling upper case, handling small words, exploding packed words, and edge cases with random inputs. It also uses a mocked version of core.user_settings.track_csv_list to avoid external file access during tests.
  • test_dictation.py: This file tests the core.text.text_and_dictation module, which is responsible for formatting dictation. It includes tests for basic formatting, capitalization and spacing, and forcing capitalization and spacing behavior.
  • test_code_modified_function.py: This file tests the talon.actions.user.code_modified_function action defined in lang.tags.functions. It checks that the action calls the correct target function based on the modifiers provided. It uses unittest.mock.MagicMock to verify which action is called.

In summary, the community/test directory contains various tests for Talon functionality in the community repository, along with stubbed Talon implementations to enable isolated and faster testing. The test files cover functionality for text formatting, spoken forms generation, dictation, and code modification actions. The stubs ensure tests are not dependent on a full Talon install.