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 subdirectorystubs/talon/experimental, and two files:stubs/talon/__init__.pyandstubs/talon/grammar.py.stubs/talon/experimental: This subdirectory contains stubs for experimental Talon features. Currently it contains onlystubs/talon/experimental/textarea.py, which provides type hints for theTextArearelated classes.stubs/talon/__init__.py: This file defines classes that mimic key Talon components, such asactions,Module,Context,ImgUI,UI,Settings,Registry,Resource, andApp. These stubs provide simplified implementations of their Talon counterparts, allowing tests to interact with them without relying on the actual Talon runtime. TheActionsclass simulates thetalon.actionsmodule, allowing tests to register and call actions. TheModuleclass simulates thetalon.Moduleclass, providing stub implementations forlist,setting,capture,tagandaction_class. TheContextclass simulates thetalon.Contextclass, offering stub implementations ofaction_classandcapturemethods as well as alistsproperty.stubs/talon/grammar.py: This file provides a stub implementation of thePhraseclass, 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 bycore.formatters. It checks various formatting options such asSNAKE_CASE,NO_SPACES,CAPITALIZE,CAPITALIZE_FIRST_WORD, andCAPITALIZE_ALL_WORDSon different input strings.test_create_spoken_forms.py: This file tests the functionality ofcore.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 ofcore.user_settings.track_csv_listto avoid external file access during tests.test_dictation.py: This file tests thecore.text.text_and_dictationmodule, 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 thetalon.actions.user.code_modified_functionaction defined inlang.tags.functions. It checks that the action calls the correct target function based on the modifiers provided. It usesunittest.mock.MagicMockto 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.