mirror of
https://github.com/mii443/tokenizers.git
synced 2025-12-18 06:19:14 +00:00
Feature: Handle invalid truncate direction (#858)
* refacto: TruncateDirection -> TruncationDirection * feat(node): invalid direction will throw * feat(python): invalid direction will throw * Update bindings/node/lib/bindings/raw-encoding.test.ts * Update bindings/python/tests/bindings/test_encoding.py Co-authored-by: Nicolas Patry <patry.nicolas@protonmail.com>
This commit is contained in:
@@ -106,3 +106,15 @@ class TestEncoding:
|
||||
assert pair.char_to_word(2, 0) == 1
|
||||
assert pair.char_to_word(2, 1) == None
|
||||
assert pair.char_to_word(3, 1) == 1
|
||||
|
||||
def test_truncation(self, encodings):
|
||||
single, _ = encodings
|
||||
single.truncate(2, 1, "right")
|
||||
assert single.tokens == ["[CLS]", "i"]
|
||||
assert single.overflowing[0].tokens == ["i", "love"]
|
||||
|
||||
def test_invalid_truncate_direction(self, encodings):
|
||||
single, _ = encodings
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
single.truncate(2, 1, "not_a_direction")
|
||||
assert "Invalid truncation direction value : not_a_direction" == str(excinfo.value)
|
||||
|
||||
Reference in New Issue
Block a user