CoolFace
Apppublic

hackless123/gmail_sys

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_env.py48 linesDownload Raw Back to tests
1import sys
2import os
3
4# Add the parent directory to sys.path so we can import the 'app' package
5sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
6
7from app.engine import GmailEnvironment
8from app.models import Action, ActionType
9
10def test_environment_flow():
11    print("๐Ÿงช Starting Environment Integration Test...")
12    
13    # 1. Initialize Env
14    env = GmailEnvironment()
15    
16    # 2. Test Reset
17    obs = env.reset()
18    print(f"โœ… Reset Successful. Inbox size: {len(obs.inbox)}")
19    assert len(obs.inbox) > 0, "Inbox should not be empty on reset"
20
21    # 3. Test Step (Simulate marking the first email as Priority)
22    test_email_id = obs.inbox[0].id
23    test_action = Action(
24        action_type=ActionType.MARK_PRIORITY,
25        email_id=test_email_id
26    )
27    
28    next_obs, reward, done = env.step(test_action)
29    
30    print(f"โœ… Step Successful.")
31    print(f"๐Ÿ“Š Action Taken: {test_action.action_type}")
32    print(f"๐Ÿ’ฐ Reward Received: {reward}")
33    print(f"โฑ๏ธ Steps Taken: {next_obs.steps_taken}/{next_obs.max_steps}")
34
35    # 4. Run until Done
36    print("๐Ÿ”„ Running until episode completion...")
37    while not done:
38        # Just keep archiving the first email for test purposes
39        _, reward, done = env.step(Action(action_type=ActionType.ARCHIVE, email_id="1"))
40    
41    print("๐Ÿ Test Passed: Environment reached 'done' state successfully.")
42
43if __name__ == "__main__":
44    try:
45        test_environment_flow()
46    except Exception as e:
47        print(f"โŒ Test Failed with error: {e}")
48        sys.exit(1)