ai-python-wolverine/tests/test_wolverine.py

57 wiersze
1.6 KiB
Python
Czysty Zwykły widok Historia

2023-04-17 19:13:48 +00:00
import os
2023-04-17 19:23:46 +00:00
import json
2023-04-17 19:13:48 +00:00
import pytest
import tempfile
2023-04-17 19:23:46 +00:00
from wolverine import apply_changes, json_validated_response
2023-04-17 19:13:48 +00:00
@pytest.fixture(scope='function')
def temp_file():
# Create a temporary file
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
f.write("first line\nsecond line\nthird line")
file_path = f.name
yield file_path
# Clean up the temporary file
os.remove(file_path)
def test_apply_changes_replace(temp_file):
# Make a "replace" change to the second line
changes = [
{"operation": "Replace", "line": 2, "content": "new second line"}
]
apply_changes(temp_file, changes)
# Check that the file was updated correctly
with open(temp_file) as f:
content = f.read()
assert content == "first line\nnew second line\nthird line"
def test_apply_changes_delete(temp_file):
# Make a "delete" change to the third line
changes = [
2023-04-17 19:23:46 +00:00
{"operation": "Delete", "line": 3, "content": ""},
2023-04-17 19:13:48 +00:00
]
apply_changes(temp_file, changes)
# Check that the file was updated correctly
with open(temp_file) as f:
content = f.read()
2023-04-17 19:23:46 +00:00
assert content == "first line\nsecond line\n"
2023-04-17 19:13:48 +00:00
def test_apply_changes_insert(temp_file):
# Make an "insert" change after the second line
changes = [
{"operation": "InsertAfter", "line": 2, "content": "inserted line"},
]
apply_changes(temp_file, changes)
# Check that the file was updated correctly
with open(temp_file) as f:
content = f.read()
2023-04-17 19:23:46 +00:00
assert content == 'first line\nsecond line\ninserted line\nthird line'