mirror of
https://github.com/huggingface/lerobot.git
synced 2026-06-02 03:41:25 +00:00
refactor(tests): streamline transition creation in processor tests
- Replaced custom transition creation functions with a centralized `create_transition` function imported from converters across multiple test files. - Updated test cases to utilize keyword arguments for better readability and maintainability, ensuring consistent transition creation throughout the test suite.
This commit is contained in:
@@ -28,21 +28,7 @@ from lerobot.processor import (
|
||||
ProcessorStepRegistry,
|
||||
TransitionKey,
|
||||
)
|
||||
|
||||
|
||||
def create_transition(
|
||||
observation=None, action=None, reward=None, done=None, truncated=None, info=None, complementary_data=None
|
||||
):
|
||||
"""Helper to create an EnvTransition dictionary."""
|
||||
return {
|
||||
TransitionKey.OBSERVATION: observation,
|
||||
TransitionKey.ACTION: action,
|
||||
TransitionKey.REWARD: reward,
|
||||
TransitionKey.DONE: done,
|
||||
TransitionKey.TRUNCATED: truncated,
|
||||
TransitionKey.INFO: info,
|
||||
TransitionKey.COMPLEMENTARY_DATA: complementary_data,
|
||||
}
|
||||
from lerobot.processor.converters import create_transition
|
||||
|
||||
|
||||
def test_state_1d_to_2d():
|
||||
@@ -517,7 +503,7 @@ def test_action_non_tensor():
|
||||
assert np.array_equal(result[TransitionKey.ACTION], action_numpy)
|
||||
|
||||
# String action (edge case)
|
||||
action_string = "forward"
|
||||
action_string = "eef.pos.x"
|
||||
transition = create_transition(action=action_string)
|
||||
result = processor(transition)
|
||||
assert result[TransitionKey.ACTION] == action_string
|
||||
@@ -703,7 +689,7 @@ def test_complementary_data_none():
|
||||
transition = create_transition(complementary_data=None)
|
||||
result = processor(transition)
|
||||
|
||||
assert result[TransitionKey.COMPLEMENTARY_DATA] is None
|
||||
assert result[TransitionKey.COMPLEMENTARY_DATA] == {}
|
||||
|
||||
|
||||
def test_complementary_data_empty():
|
||||
|
||||
Reference in New Issue
Block a user