mirror of
https://github.com/huggingface/lerobot.git
synced 2026-05-21 11:39:50 +00:00
test(processor): update tests to handle missing or invalid task keys
- Modified tests to assert that the processor raises appropriate exceptions when the task key is missing or has an invalid value in the complementary data. - Ensured that the tests cover cases for None, integer, and mixed list task values, improving robustness against invalid inputs.
This commit is contained in:
@@ -205,8 +205,9 @@ def test_none_complementary_data(mock_auto_tokenizer):
|
|||||||
|
|
||||||
transition = create_transition(observation={}, complementary_data=None)
|
transition = create_transition(observation={}, complementary_data=None)
|
||||||
|
|
||||||
result = processor(transition)
|
# create_transition converts None complementary_data to empty dict, so task key is missing
|
||||||
assert result == transition # Should return unchanged
|
with pytest.raises(KeyError, match="task"):
|
||||||
|
processor(transition)
|
||||||
|
|
||||||
|
|
||||||
@require_package("transformers")
|
@require_package("transformers")
|
||||||
@@ -220,8 +221,8 @@ def test_missing_task_key(mock_auto_tokenizer):
|
|||||||
|
|
||||||
transition = create_transition(observation={}, complementary_data={"other_field": "some value"})
|
transition = create_transition(observation={}, complementary_data={"other_field": "some value"})
|
||||||
|
|
||||||
result = processor(transition)
|
with pytest.raises(KeyError, match="task"):
|
||||||
assert result == transition # Should return unchanged
|
processor(transition)
|
||||||
|
|
||||||
|
|
||||||
@require_package("transformers")
|
@require_package("transformers")
|
||||||
@@ -235,8 +236,8 @@ def test_none_task_value(mock_auto_tokenizer):
|
|||||||
|
|
||||||
transition = create_transition(observation={}, complementary_data={"task": None})
|
transition = create_transition(observation={}, complementary_data={"task": None})
|
||||||
|
|
||||||
result = processor(transition)
|
with pytest.raises(ValueError, match="Task extracted from Complementary data is None"):
|
||||||
assert result == transition # Should return unchanged
|
processor(transition)
|
||||||
|
|
||||||
|
|
||||||
@require_package("transformers")
|
@require_package("transformers")
|
||||||
@@ -248,17 +249,17 @@ def test_unsupported_task_type(mock_auto_tokenizer):
|
|||||||
|
|
||||||
processor = TokenizerProcessorStep(tokenizer_name="test-tokenizer")
|
processor = TokenizerProcessorStep(tokenizer_name="test-tokenizer")
|
||||||
|
|
||||||
# Test with integer task
|
# Test with integer task - get_task returns None, observation raises ValueError
|
||||||
transition = create_transition(observation={}, complementary_data={"task": 123})
|
transition = create_transition(observation={}, complementary_data={"task": 123})
|
||||||
|
|
||||||
result = processor(transition)
|
with pytest.raises(ValueError, match="Task cannot be None"):
|
||||||
assert result == transition # Should return unchanged
|
processor(transition)
|
||||||
|
|
||||||
# Test with mixed list
|
# Test with mixed list - get_task returns None, observation raises ValueError
|
||||||
transition = create_transition(observation={}, complementary_data={"task": ["text", 123, "more text"]})
|
transition = create_transition(observation={}, complementary_data={"task": ["text", 123, "more text"]})
|
||||||
|
|
||||||
result = processor(transition)
|
with pytest.raises(ValueError, match="Task cannot be None"):
|
||||||
assert result == transition # Should return unchanged
|
processor(transition)
|
||||||
|
|
||||||
|
|
||||||
@require_package("transformers")
|
@require_package("transformers")
|
||||||
|
|||||||
Reference in New Issue
Block a user