refactor: use regex to normalize /add command spaces in tests

This commit is contained in:
Paul Gauthier (aider) 2024-10-29 14:03:40 -07:00
parent 3df3d86295
commit 94a49e601c

View file

@ -1,5 +1,6 @@
import codecs
import os
import re
import shutil
import sys
import tempfile
@ -748,8 +749,8 @@ class TestCommands(TestCase):
self.assertTrue(Path(session_file).exists())
with open(session_file, encoding=io.encoding) as f:
commands_text = f.read()
commands_text = commands_text.replace(" ", " ") # Normalize spaces
self.assertIn("/add file1.txt", commands_text.replace(" ", " "))
commands_text = re.sub(r'/add +', '/add ', commands_text) # Normalize add command spaces
self.assertIn("/add file1.txt", commands_text)
# Split commands and check each one
for line in commands_text.splitlines():
if line.startswith("/read-only "):
@ -822,8 +823,8 @@ class TestCommands(TestCase):
self.assertTrue(Path(session_file).exists())
with open(session_file, encoding=io.encoding) as f:
commands_text = f.read()
commands_text = commands_text.replace(" ", " ") # Normalize spaces
self.assertIn("/add internal1.txt", commands_text.replace(" ", " "))
commands_text = re.sub(r'/add +', '/add ', commands_text) # Normalize add command spaces
self.assertIn("/add internal1.txt", commands_text)
# Split commands and check each one
for line in commands_text.splitlines():
if line.startswith("/read-only "):