Update sys.path to use pathlib in json_tests.py

pull/1202/head
Merwane Hamadi 2023-04-12 14:50:45 -07:00
parent 36091853e0
commit ca5a52f48a
2 changed files with 22 additions and 7 deletions

View File

@ -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()

View File

@ -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):