hanabhi/gridworld-env
0
1#!/usr/bin/env python32"""3Simple test showing how users will use EchoEnv.from_docker_image().4 5This is the simplest possible usage6"""7 8import sys9from pathlib import Path10 11from echo_env import EchoAction, EchoEnv12 13 14def main():15 """Test EchoEnv.from_docker_image()."""16 print("=" * 60)17 print("EchoEnv.from_docker_image() Test")18 print("=" * 60)19 print()20 21 try:22 # This is what users will do - just one line!23 print("Creating client from Docker image...")24 print(" EchoEnv.from_docker_image('echo-env:latest')")25 print()26 27 client = EchoEnv(base_url="http://localhost:8000")28 29 print("✓ Client created and container started!\n")30 31 # Now use it like any other client32 print("Testing the environment:")33 print("-" * 60)34 35 # Reset36 print("\n1. Reset:")37 result = client.reset()38 print(f" Message: {result.observation.echoed_message}")39 print(f" Reward: {result.reward}")40 print(f" Done: {result.done}")41 42 # Send some messages43 print("\n2. Send messages:")44 45 messages = [46 "Hello, World!",47 "Testing echo environment",48 "One more message",49 ]50 51 for i, msg in enumerate(messages, 1):52 result = client.step(EchoAction(message=msg))53 print(f" {i}. '{msg}'")54 print(f" → Echoed: '{result.observation.echoed_message}'")55 print(f" → Length: {result.observation.message_length}")56 print(f" → Reward: {result.reward}")57 58 print("\n" + "-" * 60)59 print("\n✓ All operations successful!")60 print()61 62 print("Cleaning up...")63 client.close()64 print("✓ Container stopped and removed")65 print()66 67 print("=" * 60)68 print("Test completed successfully! 🎉")69 print("=" * 60)70 71 return True72 73 except Exception as e:74 print(f"\n❌ Test failed: {e}")75 import traceback76 77 traceback.print_exc()78 return False79 80 81if __name__ == "__main__":82 success = main()83 exit(0 if success else 1)84 