Skip to content

Commit

Permalink
Fix /copy command (and add a unit test)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechNickAI committed Aug 21, 2023
1 parent 0e217a1 commit c7eec0a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aicodebot/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def copy(self, human_input):
if not self.code_blocks:
self.console.print("No code blocks to copy.", style=self.console.error_style)
else:
pyperclip.copy(self.code_blocks)
pyperclip.copy("\n".join(self.code_blocks))
self.console.print(Panel("✅ Copied code blocks to clipboard."))
return self.CONTINUE

Expand Down
13 changes: 12 additions & 1 deletion tests/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from io import StringIO
from pathlib import Path
from tests.conftest import in_temp_directory
import pytest, textwrap
import pyperclip, pytest, textwrap


class MockConsole:
Expand Down Expand Up @@ -88,3 +88,14 @@ def test_apply_subcommand(chat, temp_git_repo):

# Check if the file was properly modified
assert "It is now even better!" in mod_file.read_text()


def test_copy_subcommand(chat, temp_git_repo):
with in_temp_directory(temp_git_repo.working_dir):
# Add the patch to the chat (simulating it coming in from the LM response)
chat.code_blocks = ["code block 1", "code block 2"]

# Apply the patch using the /apply command
assert chat.parse_human_input("/copy") == chat.CONTINUE

assert pyperclip.paste() is "\n".join(chat.code_blocks)

0 comments on commit c7eec0a

Please sign in to comment.