Skip to content

Commit 06ce367

Browse files
committed
Add tests
1 parent 510e309 commit 06ce367

File tree

12 files changed

+500
-1
lines changed

12 files changed

+500
-1
lines changed

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ source = [
7979
[tool.coverage.report]
8080
show_missing = true
8181
skip_covered = true
82-
omit = []
82+
omit = [
83+
"src/danoan/llm_assistant/prompt/core/utils.py",
84+
"src/danoan/llm_assistant/runner/cli/utils.py"
85+
]
8386
fail_under = 75
8487

8588

test/common/test_config.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from danoan.llm_assistant.common import config, exception
2+
3+
from pathlib import Path
4+
import os
5+
import tempfile
6+
7+
import pytest
8+
9+
10+
def test_get_configuration_folder_cwd(monkeypatch):
11+
# Configuration file in the current working dir
12+
with tempfile.TemporaryDirectory() as _tmpdir:
13+
tmpdir = Path(_tmpdir)
14+
config_file = tmpdir / config.LLM_ASSISTANT_CONFIGURATION_FILENAME
15+
config_file.touch()
16+
17+
monkeypatch.chdir(tmpdir)
18+
assert config.get_configuration_folder() == tmpdir
19+
20+
21+
def test_get_configuration_folder_parent_cwd(monkeypatch):
22+
# Configuration file in a parent directory of current working dir
23+
with tempfile.TemporaryDirectory() as _tmpdir:
24+
tmpdir = Path(_tmpdir)
25+
config_file = tmpdir / config.LLM_ASSISTANT_CONFIGURATION_FILENAME
26+
config_file.touch()
27+
28+
working_dir = tmpdir / "A" / "B" / "C"
29+
working_dir.mkdir(parents=True)
30+
31+
monkeypatch.chdir(working_dir)
32+
assert config.get_configuration_folder() == tmpdir
33+
34+
35+
def test_get_configuration_folder_envvar(monkeypatch):
36+
# Configuration file defined by environment variable
37+
with tempfile.TemporaryDirectory() as _envvar_dir:
38+
envvar_dir = Path(_envvar_dir)
39+
monkeypatch.setenv(config.LLM_ASSISTANT_ENV_VARIABLE, str(envvar_dir))
40+
41+
assert config.get_configuration_folder() == envvar_dir
42+
43+
44+
def test_get_configuration_folder_error():
45+
# No configuration file and not environment variable defined
46+
with pytest.raises(exception.EnvironmentVariableNotDefinedError) as ex:
47+
config.get_configuration_folder()
48+
49+
50+
def test_get_configuration_filepath(monkeypatch):
51+
monkeypatch.setenv(config.LLM_ASSISTANT_ENV_VARIABLE, os.getcwd())
52+
assert (
53+
config.get_configuration_filepath()
54+
== Path(os.getcwd()) / config.LLM_ASSISTANT_CONFIGURATION_FILENAME
55+
)
56+
57+
58+
def test_get_configuration(monkeypatch):
59+
config_file_toml = """
60+
[runner]
61+
openai_key = "key"
62+
model = "gpt-3.5-turbo"
63+
use_cache = true
64+
cache_path = "cache.db"
65+
local_folder = "local"
66+
"""
67+
with tempfile.TemporaryDirectory() as _tmpdir:
68+
tmpdir = Path(_tmpdir)
69+
config_file = tmpdir / config.LLM_ASSISTANT_CONFIGURATION_FILENAME
70+
with open(config_file, "w") as f:
71+
f.write(config_file_toml)
72+
73+
monkeypatch.chdir(tmpdir)
74+
config_obj = config.get_configuration()
75+
assert config_obj.runner.openai_key == "key"
76+
assert config_obj.runner.model == "gpt-3.5-turbo"
77+
assert config_obj.runner.use_cache == True
78+
79+
80+
def test_get_configuration_error(monkeypatch):
81+
with tempfile.TemporaryDirectory() as _tmpdir:
82+
tmpdir = Path(_tmpdir)
83+
monkeypatch.chdir(tmpdir)
84+
with pytest.raises(exception.EnvironmentVariableNotDefinedError):
85+
config.get_configuration()
86+
87+
monkeypatch.setenv(str(config.LLM_ASSISTANT_ENV_VARIABLE), str(tmpdir))
88+
with pytest.raises(exception.ConfigurationFileDoesNotExistError):
89+
config.get_configuration()
90+
91+
92+
def test_get_prompt_configuration(monkeypatch):
93+
config_file_toml = """
94+
[runner]
95+
openai_key = "key"
96+
model = "gpt-3.5-turbo"
97+
use_cache = true
98+
cache_path = "cache.db"
99+
local_folder = "prompts"
100+
"""
101+
102+
prompt_config_file_toml = """
103+
name = ""
104+
system_prompt = ""
105+
user_prompt = ""
106+
"""
107+
108+
with tempfile.TemporaryDirectory() as _tmpdir:
109+
tmpdir = Path(_tmpdir)
110+
111+
prompt_folder = tmpdir / "prompts" / "correct-text"
112+
prompt_folder.mkdir(parents=True)
113+
prompt_config_file = prompt_folder / "config.toml"
114+
with open(prompt_config_file, "w") as f:
115+
f.write(prompt_config_file_toml)
116+
117+
config_file = tmpdir / config.LLM_ASSISTANT_CONFIGURATION_FILENAME
118+
with open(config_file, "w") as f:
119+
f.write(config_file_toml)
120+
121+
monkeypatch.chdir(tmpdir)
122+
assert config.get_prompt_configuration("correct-text") is not None

test/prompt/cli/test_push.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
Manual Test
3+
4+
Initial State:
5+
Current Branch: Master
6+
Tags: No Tags
7+
8+
Action 1:
9+
Create a new file: banana
10+
Call versioning push
11+
Select Prompt Tweak
12+
Create version 1.0.0
13+
Create Branch: v1.0
14+
Push changes
15+
16+
Action 2:
17+
Create a new file: apple
18+
Call versioning push
19+
Select Prompt Tweak
20+
Create version 1.0.1
21+
Keep within the same branch v1.0
22+
Push changes
23+
24+
Action 3:
25+
Select Interface change
26+
27+
Action 4:
28+
Select Scope change
29+
30+
"""

0 commit comments

Comments
 (0)