Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Update sys.path to use pathlib in json_tests.py

Merwane Hamadica5a52f48ab1
diff --git a/tests/integration/test_commands.py b/tests/integration/test_commands.py
index 0a053eef3c..26413437f4 100644
--- a/tests/integration/test_commands.py
+++ b/tests/integration/test_commands.py
@@ -19,15 +19,18 @@ env_vars = {
'TEMPERATURE': "0"
}
-# Set environment variables for the test.
class TestCommands(unittest.TestCase):
+
def test_write_file(self):
- # Test case to check if the write_file command can successfully write 'Hello World' to a file named 'hello_world.txt'.
+ # Test case to check if the write_file command can successfully write 'Hello World' to a file
+ # named 'hello_world.txt'.
# Read the current ai_settings.yaml file and store its content.
- with open('ai_settings.yaml', 'r') as f:
- ai_settings = f.read()
+ ai_settings = None
+ with contextlib.suppress(Exception):
+ with open('ai_settings.yaml', 'r') as f:
+ ai_settings = f.read()
try:
with contextlib.suppress(Exception):
@@ -56,13 +59,15 @@ EOF'''
# Read the content of the 'hello_world.txt' file created during the test.
content = read_file('hello_world.txt')
finally:
- # Restore the original ai_settings.yaml file.
- with open('ai_settings.yaml', 'w') as f:
- f.write(ai_settings)
+ if ai_settings:
+ # Restore the original ai_settings.yaml file.
+ with open('ai_settings.yaml', 'w') as f:
+ f.write(ai_settings)
# Check if the content of the 'hello_world.txt' file is equal to 'Hello World'.
self.assertEqual(content, 'Hello World', f"Expected 'Hello World', got {content}")
+
# Run the test case.
if __name__ == '__main__':
unittest.main()
diff --git a/tests/unit/json_tests.py b/tests/unit/json_tests.py
index 561b8a38a8..4899f265f0 100644
--- a/tests/unit/json_tests.py
+++ b/tests/unit/json_tests.py
@@ -1,6 +1,16 @@
import unittest
+<<<<<<< HEAD
from autogpt.json_parser import fix_and_parse_json
+=======
+import os
+import sys
+from pathlib import Path
+
+# Probably a better way:
+sys.path.append(str(Path(__file__).resolve().parent.parent.parent / 'scripts'))
+from json_parser import fix_and_parse_json
+>>>>>>> 27e0703d (Update sys.path to use pathlib in json_tests.py)
class TestParseJson(unittest.TestCase):