API_DEBUG_SOLVER / tests /test_env.py
Kavya988's picture
Upload 29 files
d416acc verified
raw
history blame
1.84 kB
# to run this file for checking please run this command : py -m pytest tests/test_env.py -v
# py -m pytest tests/test_env.py -v in the terminal
import pytest
from environment.api_triage_env import APITriageEnv
from environment.incident_generator import get_incident_by_type
def test_reset():
""" reset should return the initial state of the environment and with step 0 """
env = APITriageEnv(max_steps=10)
state = env.reset()
# btw here we used assert to check if the state is a string or not
assert state.step == 0
assert state.max_steps == 10
assert state.incident_summary is not None
assert state.logs is not None
assert state.response_code in [400, 404, 401, 429, 500, 408]
def test_action_is_valid():
""" valid action should return the float reward"""
env = APITriageEnv()
env.reset()
test_action_is_valid = ["add_field", "wait_retry", "refresh_token", "change_endpoint", "escalate"]
for action in test_action_is_valid:
state , reward , done , info = env.step(action)
# btw here we are checking if the reward is a float and if done is also a boolean ,if its not tthen test will catch it
assert isinstance(reward, float)
assert isinstance(done, bool)
def test_action_is_invalid():
""" invalid action should return a negative reward and done = true"""
env = APITriageEnv()
env.reset()
state, reward, done, info = env.step("fake_action_123")
assert reward == -2.0
assert done is False
def test_episode_successful():
env = APITriageEnv()
env.incident = get_incident_by_type("auth_error")
env.fix_applied = False
env.done = False
env.total_reward = 0.0
state, reward, done, info = env.step("inspect_logs")
state, reward, done, info = env.step("refresh_token")
assert done is False
state, reward, done, info = env.step("resolve")
assert done is True