This repository was archived by the owner on Jan 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 304
tests for tokenizer #231
Merged
Merged
tests for tokenizer #231
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
libraries/botbuilder-dialogs/tests/choices/test_choice_tokenizer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import aiounittest | ||
| from botbuilder.dialogs.choices import Tokenizer | ||
|
|
||
|
|
||
| def _assert_token(token, start, end, text, normalized=None): | ||
| assert token.start == start, f"Invalid token.start of '{token.start}' for '{text}' token." | ||
| assert token.end == end, f"Invalid token.end of '{token.end}' for '{text}' token." | ||
| assert token.text == text, f"Invalid token.text of '{token.text}' for '{text}' token." | ||
| assert token.normalized == normalized or text, f"Invalid token.normalized of '{token.normalized}' for '{text}' token." | ||
|
|
||
|
|
||
| class AttachmentPromptTests(aiounittest.AsyncTestCase): | ||
| def test_should_break_on_spaces(self): | ||
| tokens = Tokenizer.default_tokenizer('how now brown cow') | ||
| assert len(tokens) == 4 | ||
| _assert_token(tokens[0], 0, 2, 'how') | ||
| _assert_token(tokens[1], 4, 6, 'now') | ||
| _assert_token(tokens[2], 8, 12, 'brown') | ||
| _assert_token(tokens[3], 14, 16, 'cow') | ||
|
|
||
| def test_should_break_on_punctuation(self): | ||
| tokens = Tokenizer.default_tokenizer('how-now.brown:cow?') | ||
| assert len(tokens) == 4 | ||
| _assert_token(tokens[0], 0, 2, 'how') | ||
| _assert_token(tokens[1], 4, 6, 'now') | ||
| _assert_token(tokens[2], 8, 12, 'brown') | ||
| _assert_token(tokens[3], 14, 16, 'cow') | ||
|
|
||
| def test_should_tokenize_single_character_tokens(self): | ||
| tokens = Tokenizer.default_tokenizer('a b c d') | ||
| assert len(tokens) == 4 | ||
| _assert_token(tokens[0], 0, 0, 'a') | ||
| _assert_token(tokens[1], 2, 2, 'b') | ||
| _assert_token(tokens[2], 4, 4, 'c') | ||
| _assert_token(tokens[3], 6, 6, 'd') | ||
|
|
||
| def test_should_return_a_single_token(self): | ||
| tokens = Tokenizer.default_tokenizer('food') | ||
| assert len(tokens) == 1 | ||
| _assert_token(tokens[0], 0, 3, 'food') | ||
|
|
||
| def test_should_return_no_tokens(self): | ||
| tokens = Tokenizer.default_tokenizer('.?-()') | ||
| assert len(tokens) == 0 | ||
|
|
||
| def test_should_return_a_the_normalized_and_original_text_for_a_token(self): | ||
| tokens = Tokenizer.default_tokenizer('fOoD') | ||
| assert len(tokens) == 1 | ||
| _assert_token(tokens[0], 0, 3, 'fOoD', 'food') | ||
|
|
||
| def test_should_break_on_emojis(self): | ||
| tokens = Tokenizer.default_tokenizer('food 💥👍😀') | ||
| assert len(tokens) == 4 | ||
| _assert_token(tokens[0], 0, 3, 'food') | ||
| _assert_token(tokens[1], 5, 5, '💥') | ||
| _assert_token(tokens[2], 6, 6, '👍') | ||
| _assert_token(tokens[3], 7, 7, '😀') | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.