Skip to content

Commit

Permalink
Refactor test_cli_prompt.py and add conftest.py
Browse files Browse the repository at this point in the history
- Remove unnecessary imports and comments in test_cli_prompt.py
- Move git_repo fixture to conftest.py
- Update '--topic' option formatting in _cli.py
  • Loading branch information
basicthinker committed Jun 6, 2023
1 parent 8299aef commit abdb108
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
3 changes: 2 additions & 1 deletion devchat/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ def prompt(content: Optional[str], parent: Optional[str], reference: Optional[Li

@click.option('--skip', default=0, help='Skip number prompts before showing the prompt history.')
@click.option('-n', '--max-count', default=100, help='Limit the number of commits to output.')
@click.option('-t', '--topic', default=None, help='Hash of the root prompt of the topic to select prompts from.')
@click.option('-t', '--topic', default=None,
help='Hash of the root prompt of the topic to select prompts from.')
def log(skip, max_count, topic):
"""
Show the prompt history.
Expand Down
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import shutil
import tempfile
import pytest
from git import Repo


@pytest.fixture(name='git_repo', scope='module')
def fixture_git_repo(request):
# Create a temporary directory
repo_dir = tempfile.mkdtemp()

# Initialize a new Git repository in the temporary directory
Repo.init(repo_dir)

# Change the current working directory to the temporary directory
prev_cwd = os.getcwd()
os.chdir(repo_dir)

# Add a cleanup function to remove the temporary directory after the test
def cleanup():
os.chdir(prev_cwd)
shutil.rmtree(repo_dir)

request.addfinalizer(cleanup)

return repo_dir
28 changes: 0 additions & 28 deletions tests/test_cli_prompt.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
"""
test_cli.py - Tests for the command line interface.
"""
import os
import re
import json
import shutil
import tempfile
import pytest
from git import Repo
from click.testing import CliRunner
from devchat._cli import main
from devchat.utils import response_tokens

runner = CliRunner()


@pytest.fixture(name="git_repo")
def fixture_git_repo(request):
# Create a temporary directory
repo_dir = tempfile.mkdtemp()

# Initialize a new Git repository in the temporary directory
Repo.init(repo_dir)

# Change the current working directory to the temporary directory
prev_cwd = os.getcwd()
os.chdir(repo_dir)

# Add a cleanup function to remove the temporary directory after the test
def cleanup():
os.chdir(prev_cwd)
shutil.rmtree(repo_dir)

request.addfinalizer(cleanup)

return repo_dir


def test_prompt_no_args(git_repo): # pylint: disable=W0613
result = runner.invoke(main, ['prompt'])
assert result.exit_code == 0
Expand Down

0 comments on commit abdb108

Please sign in to comment.