Fix hardcoded paths in test files and improve YAML error handling
- Replace hardcoded absolute paths with relative paths using Path(__file__).parent - Update test_activity_flows.py, test_guarded_ai.py, and test_battleship_pre_script.py to use dynamic path construction - Import yaml module and catch yaml.YAMLError instead of broad Exception in test_activity_processing.py - Ensures tests work across different environments and CI systems - Makes YAML error handling more specific and prevents masking other exceptions
This commit is contained in:
parent
092ebd0ee0
commit
6b876d488c
6 changed files with 22 additions and 19 deletions
BIN
.coverage
BIN
.coverage
Binary file not shown.
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -7,3 +7,5 @@ __pycache__/
|
|||
.aws-sam/
|
||||
samconfig.toml
|
||||
vars.sh
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
|
|
|||
|
|
@ -379,8 +379,8 @@ class TestRealActivityFiles(unittest.TestCase):
|
|||
mock_get_client.return_value = (self.mock_client, "test-model")
|
||||
|
||||
# Load actual activity3.yaml
|
||||
activity_file = "/home/fox/git/opencompletion/research/activity3.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity_file = Path(__file__).parent.parent.parent / "research" / "activity3.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Should have section_5 as the terminal section
|
||||
section_5 = None
|
||||
|
|
@ -408,9 +408,9 @@ class TestRealActivityFiles(unittest.TestCase):
|
|||
mock_get_client.return_value = (self.mock_client, "test-model")
|
||||
|
||||
activity_file = (
|
||||
"/home/fox/git/opencompletion/research/activity17-choose-adventure.yaml"
|
||||
Path(__file__).parent.parent.parent / "research" / "activity17-choose-adventure.yaml"
|
||||
)
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find a step with metadata_remove operations
|
||||
found_remove_operation = False
|
||||
|
|
@ -450,9 +450,9 @@ class TestRealActivityFiles(unittest.TestCase):
|
|||
mock_get_client.return_value = (self.mock_client, "test-model")
|
||||
|
||||
activity_file = (
|
||||
"/home/fox/git/opencompletion/research/activity20-n-plus-1.yaml"
|
||||
Path(__file__).parent.parent.parent / "research" / "activity20-n-plus-1.yaml"
|
||||
)
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find the step with integer bucket (1912)
|
||||
found_integer_bucket = False
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ class TestBattleshipPreScript(unittest.TestCase):
|
|||
def test_battleship_yaml_has_pre_script(self):
|
||||
"""Test that battleship YAML loads and has pre_script"""
|
||||
activity_file = (
|
||||
"/home/fox/git/opencompletion/research/activity29-battleship.yaml"
|
||||
Path(__file__).parent.parent.parent / "research" / "activity29-battleship.yaml"
|
||||
)
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find step with pre_script
|
||||
found_pre_script = False
|
||||
|
|
@ -57,9 +57,9 @@ class TestBattleshipPreScript(unittest.TestCase):
|
|||
def test_battleship_pre_script_execution_simulation(self):
|
||||
"""Test simulated battleship pre_script execution"""
|
||||
activity_file = (
|
||||
"/home/fox/git/opencompletion/research/activity29-battleship.yaml"
|
||||
Path(__file__).parent.parent.parent / "research" / "activity29-battleship.yaml"
|
||||
)
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find the step with pre_script (step_2)
|
||||
step_with_pre_script = None
|
||||
|
|
@ -96,8 +96,8 @@ class TestBattleshipPreScript(unittest.TestCase):
|
|||
|
||||
def test_testship_yaml_has_pre_script(self):
|
||||
"""Test that testship YAML also has pre_script"""
|
||||
activity_file = "/home/fox/git/opencompletion/research/activity29-testship.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity_file = Path(__file__).parent.parent.parent / "research" / "activity29-testship.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Should also have pre_script (same structure as battleship)
|
||||
found_pre_script = False
|
||||
|
|
|
|||
|
|
@ -320,8 +320,8 @@ class TestActivityYAMLChanges(unittest.TestCase):
|
|||
"""Test that activity3's new terminal section loads correctly"""
|
||||
import guarded_ai as guarded_ai
|
||||
|
||||
activity_file = "/home/fox/git/opencompletion/research/activity3.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity_file = Path(__file__).parent.parent.parent / "research" / "activity3.yaml"
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Should have section_5 now
|
||||
section_ids = [section["section_id"] for section in activity["sections"]]
|
||||
|
|
@ -348,9 +348,9 @@ class TestActivityYAMLChanges(unittest.TestCase):
|
|||
import guarded_ai as guarded_ai
|
||||
|
||||
activity_file = (
|
||||
"/home/fox/git/opencompletion/research/activity17-choose-adventure.yaml"
|
||||
Path(__file__).parent.parent.parent / "research" / "activity17-choose-adventure.yaml"
|
||||
)
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find steps with metadata_remove
|
||||
found_metadata_remove = False
|
||||
|
|
@ -375,8 +375,8 @@ class TestActivityYAMLChanges(unittest.TestCase):
|
|||
"activity29-battleship.yaml",
|
||||
"activity29-testship.yaml",
|
||||
]:
|
||||
activity_file = f"/home/fox/git/opencompletion/research/{battleship_file}"
|
||||
activity = guarded_ai.load_yaml_activity(activity_file)
|
||||
activity_file = Path(__file__).parent.parent.parent / "research" / battleship_file
|
||||
activity = guarded_ai.load_yaml_activity(str(activity_file))
|
||||
|
||||
# Find exit transitions and verify they go to step_4
|
||||
exit_transitions_found = 0
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import tempfile
|
|||
import json
|
||||
import sys
|
||||
import os
|
||||
import yaml
|
||||
from unittest.mock import Mock, patch, MagicMock
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -446,7 +447,7 @@ script_result = {'status': 'error'}
|
|||
with open(test_file, "w") as f:
|
||||
f.write(malformed_yaml)
|
||||
|
||||
with self.assertRaises(Exception): # YAML parsing error
|
||||
with self.assertRaises(yaml.YAMLError): # YAML parsing error
|
||||
app.get_activity_content("research/malformed.yaml")
|
||||
|
||||
finally:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue