AIUnitTest 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ai_unit_test/__init__.py +0 -0
- ai_unit_test/_version.py +21 -0
- ai_unit_test/cli.py +286 -0
- ai_unit_test/coverage_helper.py +30 -0
- ai_unit_test/file_helper.py +99 -0
- ai_unit_test/llm.py +93 -0
- ai_unit_test/main.py +28 -0
- ai_unit_test/py.typed +0 -0
- aiunittest-0.0.1.dist-info/METADATA +65 -0
- aiunittest-0.0.1.dist-info/RECORD +13 -0
- aiunittest-0.0.1.dist-info/WHEEL +5 -0
- aiunittest-0.0.1.dist-info/licenses/LICENSE +201 -0
- aiunittest-0.0.1.dist-info/top_level.txt +1 -0
ai_unit_test/__init__.py
ADDED
|
File without changes
|
ai_unit_test/_version.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
|
|
5
|
+
|
|
6
|
+
TYPE_CHECKING = False
|
|
7
|
+
if TYPE_CHECKING:
|
|
8
|
+
from typing import Tuple
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
12
|
+
else:
|
|
13
|
+
VERSION_TUPLE = object
|
|
14
|
+
|
|
15
|
+
version: str
|
|
16
|
+
__version__: str
|
|
17
|
+
__version_tuple__: VERSION_TUPLE
|
|
18
|
+
version_tuple: VERSION_TUPLE
|
|
19
|
+
|
|
20
|
+
__version__ = version = '0.0.1'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 0, 1)
|
ai_unit_test/cli.py
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import asyncio
|
|
3
|
+
import logging
|
|
4
|
+
import sys
|
|
5
|
+
import tomllib
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from ai_unit_test.coverage_helper import collect_missing_lines
|
|
12
|
+
from ai_unit_test.file_helper import (
|
|
13
|
+
extract_function_source,
|
|
14
|
+
find_relevant_tests,
|
|
15
|
+
find_test_file,
|
|
16
|
+
get_source_code_chunks,
|
|
17
|
+
read_file_content,
|
|
18
|
+
write_file_content,
|
|
19
|
+
)
|
|
20
|
+
from ai_unit_test.llm import update_test_with_llm
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
|
|
24
|
+
app = typer.Typer()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
PYPROJECT_TOML_PATH = Path("pyproject.toml")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def load_pyproject_config(pyproject_path: Path = PYPROJECT_TOML_PATH) -> dict[str, Any]:
|
|
31
|
+
"""Loads the pyproject.toml file, if it exists, otherwise returns an empty dictionary."""
|
|
32
|
+
logger.debug(f"Attempting to load pyproject config from: {pyproject_path}")
|
|
33
|
+
if not pyproject_path.exists():
|
|
34
|
+
logger.debug("pyproject.toml not found.")
|
|
35
|
+
return {}
|
|
36
|
+
with pyproject_path.open("rb") as fp:
|
|
37
|
+
config: dict[str, Any] = tomllib.load(fp)
|
|
38
|
+
logger.debug("pyproject.toml loaded successfully.")
|
|
39
|
+
return config
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def extract_from_pyproject(
|
|
43
|
+
data: dict[str, Any],
|
|
44
|
+
) -> tuple[list[str], str | None, str | None]:
|
|
45
|
+
"""
|
|
46
|
+
Extracts (source_folders, tests_folder, coverage_file)
|
|
47
|
+
from the standard pyproject.toml structure.
|
|
48
|
+
"""
|
|
49
|
+
logger.debug("Extracting configuration from pyproject.toml data.")
|
|
50
|
+
folders: list[str] = []
|
|
51
|
+
tests_folder: str | None = None
|
|
52
|
+
coverage_path: str | None = None
|
|
53
|
+
|
|
54
|
+
folders = data.get("tool", {}).get("coverage", {}).get("run", {}).get("source", [])
|
|
55
|
+
logger.debug(f"Found source folders: {folders}")
|
|
56
|
+
|
|
57
|
+
tests_folder = data.get("tool", {}).get("pytest", {}).get("ini_options", {}).get("testpaths", [None])[0]
|
|
58
|
+
logger.debug(f"Found tests folder: {tests_folder}")
|
|
59
|
+
|
|
60
|
+
if not tests_folder and Path("tests").is_dir():
|
|
61
|
+
logger.debug("No tests folder in pyproject.toml, falling back to 'tests' directory.")
|
|
62
|
+
tests_folder = "tests"
|
|
63
|
+
|
|
64
|
+
coverage_path = data.get("tool", {}).get("coverage", {}).get("run", {}).get("data_file")
|
|
65
|
+
logger.debug(f"Found coverage file path: {coverage_path}")
|
|
66
|
+
|
|
67
|
+
return folders, tests_folder, coverage_path
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _resolve_paths_from_config(
|
|
71
|
+
folders: list[str] | None,
|
|
72
|
+
tests_folder: str | None,
|
|
73
|
+
coverage_file: str,
|
|
74
|
+
auto: bool,
|
|
75
|
+
) -> tuple[list[str], str, str]:
|
|
76
|
+
if auto or not (folders and tests_folder):
|
|
77
|
+
logger.info("Auto-discovery enabled or folders/tests_folder not provided. Loading from pyproject.toml.")
|
|
78
|
+
cfg: dict[str, Any] = load_pyproject_config()
|
|
79
|
+
folders_from_cfg: list[str]
|
|
80
|
+
tests_dir_from_cfg: str | None
|
|
81
|
+
cov_file_from_cfg: str | None
|
|
82
|
+
folders_from_cfg, tests_dir_from_cfg, cov_file_from_cfg = extract_from_pyproject(cfg)
|
|
83
|
+
|
|
84
|
+
if not folders:
|
|
85
|
+
folders = folders_from_cfg
|
|
86
|
+
logger.debug(f"Using source folders from pyproject.toml: {folders}")
|
|
87
|
+
if not tests_folder:
|
|
88
|
+
tests_folder = tests_dir_from_cfg
|
|
89
|
+
logger.debug(f"Using tests folder from pyproject.toml: {tests_folder}")
|
|
90
|
+
if coverage_file == ".coverage" and cov_file_from_cfg:
|
|
91
|
+
coverage_file = cov_file_from_cfg
|
|
92
|
+
logger.debug(f"Using coverage file from pyproject.toml: {coverage_file}")
|
|
93
|
+
|
|
94
|
+
if not folders:
|
|
95
|
+
logger.error("Source code folders not defined (--folders) and not found in pyproject.toml.")
|
|
96
|
+
sys.exit(1)
|
|
97
|
+
if not tests_folder:
|
|
98
|
+
logger.error("Tests folder not defined (--tests-folder) and not found in pyproject.toml.")
|
|
99
|
+
sys.exit(1)
|
|
100
|
+
|
|
101
|
+
return folders, tests_folder, coverage_file
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def _detect_test_style(test_file_path: Path) -> str:
|
|
105
|
+
"""Detects if the test file uses unittest.TestCase classes or pytest functions."""
|
|
106
|
+
test_content = read_file_content(test_file_path)
|
|
107
|
+
if not test_content:
|
|
108
|
+
return "unknown"
|
|
109
|
+
|
|
110
|
+
try:
|
|
111
|
+
tree = ast.parse(test_content)
|
|
112
|
+
for node in ast.walk(tree):
|
|
113
|
+
if isinstance(node, ast.ClassDef):
|
|
114
|
+
for base in node.bases:
|
|
115
|
+
if isinstance(base, ast.Attribute) and base.attr == "TestCase":
|
|
116
|
+
return "unittest_class"
|
|
117
|
+
elif isinstance(base, ast.Name) and base.id == "TestCase":
|
|
118
|
+
return "unittest_class"
|
|
119
|
+
# If no TestCase classes are found, assume pytest function style
|
|
120
|
+
return "pytest_function"
|
|
121
|
+
except SyntaxError:
|
|
122
|
+
logger.warning(f"Could not parse test file {test_file_path} for style detection.")
|
|
123
|
+
return "unknown"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
async def _process_missing_info(missing_info: dict[Path, list[int]], tests_folder: str) -> None:
|
|
127
|
+
for source_file_path, uncovered_lines_list in missing_info.items():
|
|
128
|
+
logger.info(f"Processing source file: {source_file_path}")
|
|
129
|
+
test_file: Path | None = find_test_file(str(source_file_path), tests_folder)
|
|
130
|
+
if not test_file:
|
|
131
|
+
logger.warning(f"Test file not found for {source_file_path}, skipping.")
|
|
132
|
+
continue
|
|
133
|
+
|
|
134
|
+
# Detect test style
|
|
135
|
+
test_style = _detect_test_style(test_file)
|
|
136
|
+
logger.debug(f"Detected test style for {test_file}: {test_style}")
|
|
137
|
+
|
|
138
|
+
# Get all logical chunks (classes and functions) from the source file
|
|
139
|
+
code_chunks = get_source_code_chunks(source_file_path)
|
|
140
|
+
|
|
141
|
+
other_tests_content = read_file_content(test_file)
|
|
142
|
+
|
|
143
|
+
for chunk in code_chunks:
|
|
144
|
+
chunk_uncovered_lines = []
|
|
145
|
+
for line_num in uncovered_lines_list:
|
|
146
|
+
if chunk.start_line <= line_num <= chunk.end_line:
|
|
147
|
+
chunk_uncovered_lines.append(line_num)
|
|
148
|
+
|
|
149
|
+
if not chunk_uncovered_lines:
|
|
150
|
+
continue # No uncovered lines in this chunk, skip
|
|
151
|
+
|
|
152
|
+
logger.info(
|
|
153
|
+
f"Updating {test_file} for chunk '{chunk.name}' "
|
|
154
|
+
f"(lines {chunk.start_line}-{chunk.end_line}) with uncovered lines: {chunk_uncovered_lines}"
|
|
155
|
+
)
|
|
156
|
+
try:
|
|
157
|
+
updated_test: str = await update_test_with_llm(
|
|
158
|
+
chunk.source_code, # Pass chunk source code
|
|
159
|
+
read_file_content(test_file) or "", # Still pass the whole test file for context
|
|
160
|
+
str(source_file_path),
|
|
161
|
+
chunk_uncovered_lines, # Pass chunk-specific uncovered lines
|
|
162
|
+
other_tests_content,
|
|
163
|
+
test_style, # Pass the detected test style
|
|
164
|
+
)
|
|
165
|
+
write_file_content(test_file, updated_test, mode="a") # Append the new test content
|
|
166
|
+
logger.info(f"✅ Test file updated successfully: {test_file}")
|
|
167
|
+
except Exception as exc: # pragma: no cover
|
|
168
|
+
logger.error(f"Error updating {test_file}: {exc}")
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
async def _main(
|
|
172
|
+
folders: list[str] | None = None,
|
|
173
|
+
tests_folder: str | None = None,
|
|
174
|
+
coverage_file: str = ".coverage",
|
|
175
|
+
auto: bool = False,
|
|
176
|
+
) -> None:
|
|
177
|
+
logger.info("Starting AI Unit Test generation process.")
|
|
178
|
+
logger.debug(
|
|
179
|
+
f"Initial parameters: folders={folders}, "
|
|
180
|
+
f"tests_folder={tests_folder}, "
|
|
181
|
+
f"coverage_file={coverage_file}, "
|
|
182
|
+
f"auto={auto}"
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
folders, tests_folder, coverage_file = _resolve_paths_from_config(folders, tests_folder, coverage_file, auto)
|
|
186
|
+
|
|
187
|
+
logger.info(f"Using source folders: {folders}")
|
|
188
|
+
logger.info(f"Using tests folder: {tests_folder}")
|
|
189
|
+
logger.info(f"Using coverage file: {coverage_file}")
|
|
190
|
+
|
|
191
|
+
if not Path(coverage_file).exists():
|
|
192
|
+
logger.error(f"Coverage file not found: {coverage_file}")
|
|
193
|
+
sys.exit(1)
|
|
194
|
+
|
|
195
|
+
missing_info = collect_missing_lines(coverage_file)
|
|
196
|
+
if not missing_info:
|
|
197
|
+
logger.info("No files with missing coverage 🎉")
|
|
198
|
+
return
|
|
199
|
+
logger.info(f"👉 Found {len(missing_info)} files with missing coverage.")
|
|
200
|
+
|
|
201
|
+
await _process_missing_info(missing_info, tests_folder)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
DEFAULT_FOLDERS_OPTION = typer.Option(None, "--folders", help="Source code folders to analyze.")
|
|
205
|
+
DEFAULT_TESTS_FOLDER_OPTION = typer.Option(None, "--tests-folder", help="Folder where the tests are located.")
|
|
206
|
+
DEFAULT_COVERAGE_FILE_OPTION = typer.Option(".coverage", "--coverage-file", help=".coverage file.")
|
|
207
|
+
DEFAULT_AUTO_OPTION = typer.Option(False, "--auto", help="Try to discover folders/tests from pyproject.toml.")
|
|
208
|
+
DEFAULT_FILE_PATH_ARGUMENT = typer.Argument(..., help="Path to the source file.")
|
|
209
|
+
DEFAULT_FUNCTION_NAME_ARGUMENT = typer.Argument(..., help="Name of the function to test.")
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
@app.command()
|
|
213
|
+
def func(
|
|
214
|
+
file_path: str = DEFAULT_FILE_PATH_ARGUMENT,
|
|
215
|
+
function_name: str = DEFAULT_FUNCTION_NAME_ARGUMENT,
|
|
216
|
+
tests_folder: str | None = DEFAULT_TESTS_FOLDER_OPTION,
|
|
217
|
+
auto: bool = DEFAULT_AUTO_OPTION,
|
|
218
|
+
) -> None:
|
|
219
|
+
"""
|
|
220
|
+
Generates a test for a specific function in a file.
|
|
221
|
+
"""
|
|
222
|
+
logger.info(f"Generating test for function '{function_name}' in file '{file_path}'.")
|
|
223
|
+
|
|
224
|
+
if auto or not tests_folder:
|
|
225
|
+
logger.info("Auto-discovery enabled or tests_folder not provided. Loading from pyproject.toml.")
|
|
226
|
+
cfg: dict[str, Any] = load_pyproject_config()
|
|
227
|
+
_, tests_dir_from_cfg, _ = extract_from_pyproject(cfg)
|
|
228
|
+
|
|
229
|
+
if not tests_folder:
|
|
230
|
+
tests_folder = tests_dir_from_cfg
|
|
231
|
+
logger.debug(f"Using tests folder from pyproject.toml: {tests_folder}")
|
|
232
|
+
|
|
233
|
+
if not tests_folder:
|
|
234
|
+
logger.error("Tests folder not defined (--tests-folder) and not found in pyproject.toml.")
|
|
235
|
+
sys.exit(1)
|
|
236
|
+
|
|
237
|
+
source_code = extract_function_source(file_path, function_name)
|
|
238
|
+
if not source_code:
|
|
239
|
+
logger.error(f"Function '{function_name}' not found in '{file_path}'.")
|
|
240
|
+
sys.exit(1)
|
|
241
|
+
|
|
242
|
+
test_file: Path | None = find_test_file(file_path, tests_folder)
|
|
243
|
+
if not test_file:
|
|
244
|
+
logger.warning(f"Test file not found for {file_path}, skipping.")
|
|
245
|
+
return
|
|
246
|
+
|
|
247
|
+
test_code: str = read_file_content(test_file) or ""
|
|
248
|
+
|
|
249
|
+
# Detect test style
|
|
250
|
+
test_style = _detect_test_style(test_file)
|
|
251
|
+
logger.debug(f"Detected test style for {test_file}: {test_style}")
|
|
252
|
+
|
|
253
|
+
# Read all other test files for context
|
|
254
|
+
other_tests_content = find_relevant_tests(file_path, tests_folder)
|
|
255
|
+
|
|
256
|
+
logger.info(f"Updating {test_file} for function '{function_name}'.")
|
|
257
|
+
try:
|
|
258
|
+
updated_test: str = asyncio.run(
|
|
259
|
+
update_test_with_llm(source_code, test_code, str(file_path), [], other_tests_content, test_style)
|
|
260
|
+
)
|
|
261
|
+
write_file_content(test_file, updated_test)
|
|
262
|
+
logger.info(f"✅ Test file updated successfully: {test_file}")
|
|
263
|
+
except Exception as exc: # pragma: no cover
|
|
264
|
+
logger.error(f"Error updating {test_file}: {exc}")
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
@app.command()
|
|
268
|
+
def main(
|
|
269
|
+
folders: list[str] | None = DEFAULT_FOLDERS_OPTION,
|
|
270
|
+
tests_folder: str | None = DEFAULT_TESTS_FOLDER_OPTION,
|
|
271
|
+
coverage_file: str = DEFAULT_COVERAGE_FILE_OPTION,
|
|
272
|
+
auto: bool = DEFAULT_AUTO_OPTION,
|
|
273
|
+
) -> None:
|
|
274
|
+
"""
|
|
275
|
+
Automatically updates unit tests using the .coverage file and
|
|
276
|
+
the settings declared in pyproject.toml
|
|
277
|
+
"""
|
|
278
|
+
logger.debug("CLI 'main' command invoked.")
|
|
279
|
+
asyncio.run(
|
|
280
|
+
_main(
|
|
281
|
+
folders=folders,
|
|
282
|
+
tests_folder=tests_folder,
|
|
283
|
+
coverage_file=coverage_file,
|
|
284
|
+
auto=auto,
|
|
285
|
+
)
|
|
286
|
+
)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from coverage import Coverage
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def collect_missing_lines(data_file: str) -> dict[Path, list[int]]:
|
|
10
|
+
"""Returns a mapping {file: [lines without coverage]} using the .coverage file."""
|
|
11
|
+
logger.debug(f"Collecting missing lines from {data_file}")
|
|
12
|
+
cov = Coverage(data_file=data_file)
|
|
13
|
+
cov.load()
|
|
14
|
+
missing: dict[Path, list[int]] = {}
|
|
15
|
+
measured_files = cov.get_data().measured_files()
|
|
16
|
+
logger.debug(f"Measured files by coverage: {measured_files}")
|
|
17
|
+
for file_path_str in measured_files:
|
|
18
|
+
logger.debug(f"Processing measured file: {file_path_str}")
|
|
19
|
+
# The method analysis2 is marked as private by the library, but it is the best way to get the missing lines.
|
|
20
|
+
# The official API does not provide a direct way to get the missing lines for a specific file.
|
|
21
|
+
# The analysis method returns (statements, excluded, missing, annotate_html)
|
|
22
|
+
_, _, missing_lines, _ = cov.analysis(file_path_str)
|
|
23
|
+
logger.debug(f"Analysis for {file_path_str}: missing_lines={missing_lines}")
|
|
24
|
+
if missing_lines:
|
|
25
|
+
logger.debug(f"Found {len(missing_lines)} missing lines in {file_path_str}")
|
|
26
|
+
missing[Path(file_path_str)] = missing_lines
|
|
27
|
+
else:
|
|
28
|
+
logger.debug(f"No missing lines found in {file_path_str}")
|
|
29
|
+
logger.info(f"Found {len(missing)} files with missing lines")
|
|
30
|
+
return missing
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import ast
|
|
2
|
+
import logging
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
logger = logging.getLogger(__name__)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class Chunk:
|
|
12
|
+
name: str
|
|
13
|
+
type: Literal["class", "function"]
|
|
14
|
+
source_code: str
|
|
15
|
+
start_line: int
|
|
16
|
+
end_line: int
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def find_test_file(source_file_path: str, tests_folder: str) -> Path | None:
|
|
20
|
+
"""Finds the corresponding test file for a given source file."""
|
|
21
|
+
source_file = Path(source_file_path)
|
|
22
|
+
test_file_name = f"test_{source_file.name}"
|
|
23
|
+
# Look for the test file in the tests_folder and its subdirectories
|
|
24
|
+
test_files = list(Path(tests_folder).rglob(test_file_name))
|
|
25
|
+
if test_files:
|
|
26
|
+
return test_files[0]
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def find_relevant_tests(source_file_path: str, tests_folder: str) -> str:
|
|
31
|
+
"""
|
|
32
|
+
Finds the most relevant test file for a given source file and returns its content.
|
|
33
|
+
The primary strategy is to find a test file with a similar name.
|
|
34
|
+
"""
|
|
35
|
+
test_file_path = find_test_file(source_file_path, tests_folder)
|
|
36
|
+
if test_file_path:
|
|
37
|
+
return read_file_content(test_file_path)
|
|
38
|
+
return ""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def read_file_content(file_path: Path | str) -> str:
|
|
42
|
+
"""Reads the content of a file."""
|
|
43
|
+
try:
|
|
44
|
+
with open(file_path) as f:
|
|
45
|
+
return f.read()
|
|
46
|
+
except FileNotFoundError:
|
|
47
|
+
logger.warning(f"File not found: {file_path}")
|
|
48
|
+
return ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def write_file_content(file_path: Path, content: str, mode: str = "w") -> None:
|
|
52
|
+
"""Writes content to a file."""
|
|
53
|
+
with open(file_path, mode) as f:
|
|
54
|
+
f.write(content)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def extract_function_source(file_path: str, function_name: str) -> str | None:
|
|
58
|
+
"""Extracts the source code of a specific function from a file."""
|
|
59
|
+
try:
|
|
60
|
+
with open(file_path) as f:
|
|
61
|
+
file_content = f.read()
|
|
62
|
+
tree = ast.parse(file_content)
|
|
63
|
+
for node in ast.walk(tree):
|
|
64
|
+
if isinstance(node, ast.FunctionDef) and node.name == function_name:
|
|
65
|
+
return ast.get_source_segment(file_content, node)
|
|
66
|
+
except (FileNotFoundError, SyntaxError) as e:
|
|
67
|
+
logger.error(f"Error reading or parsing {file_path}: {e}")
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_source_code_chunks(file_path: Path) -> list[Chunk]:
|
|
72
|
+
"""
|
|
73
|
+
Extracts top-level classes and functions from a Python file as code chunks.
|
|
74
|
+
"""
|
|
75
|
+
chunks: list[Chunk] = []
|
|
76
|
+
try:
|
|
77
|
+
file_content = read_file_content(file_path)
|
|
78
|
+
tree = ast.parse(file_content)
|
|
79
|
+
|
|
80
|
+
for node in tree.body:
|
|
81
|
+
if isinstance(node, (ast.ClassDef, ast.FunctionDef)):
|
|
82
|
+
source_segment = ast.get_source_segment(file_content, node)
|
|
83
|
+
if source_segment is not None:
|
|
84
|
+
chunks.append(
|
|
85
|
+
Chunk(
|
|
86
|
+
name=node.name,
|
|
87
|
+
type="class" if isinstance(node, ast.ClassDef) else "function",
|
|
88
|
+
source_code=source_segment,
|
|
89
|
+
start_line=node.lineno,
|
|
90
|
+
end_line=(
|
|
91
|
+
node.end_lineno
|
|
92
|
+
if hasattr(node, "end_lineno") and node.end_lineno is not None
|
|
93
|
+
else node.lineno
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
except (FileNotFoundError, SyntaxError) as e:
|
|
98
|
+
logger.error(f"Error reading or parsing {file_path}: {e}")
|
|
99
|
+
return chunks
|
ai_unit_test/llm.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from openai import AsyncOpenAI
|
|
5
|
+
|
|
6
|
+
logger = logging.getLogger(__name__)
|
|
7
|
+
|
|
8
|
+
MODEL = "gpt-4o-mini"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def update_test_with_llm(
|
|
12
|
+
source_code: str,
|
|
13
|
+
test_code: str,
|
|
14
|
+
file_name: str,
|
|
15
|
+
coverage_lines: list[int],
|
|
16
|
+
other_tests_content: str,
|
|
17
|
+
test_style: str,
|
|
18
|
+
) -> str:
|
|
19
|
+
"""Calls the chat model to generate the new test file."""
|
|
20
|
+
logger.info(f"Updating test for {file_name} with LLM.")
|
|
21
|
+
logger.debug(
|
|
22
|
+
f"Source code length: {len(source_code)}, Test code length: {len(test_code)}, Uncovered lines: {coverage_lines}"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
api_key_val: str | None = os.environ.get("OPENAI_API_KEY")
|
|
26
|
+
if not api_key_val:
|
|
27
|
+
logger.error("OPENAI_API_KEY environment variable not set.")
|
|
28
|
+
raise RuntimeError("Set the OPENAI_API_KEY environment variable with your OpenAI key.")
|
|
29
|
+
|
|
30
|
+
api_url: str | None = os.environ.get("OPENAI_API_URL")
|
|
31
|
+
|
|
32
|
+
client: AsyncOpenAI = AsyncOpenAI(api_key=api_key_val, base_url=api_url)
|
|
33
|
+
|
|
34
|
+
system_msg_base = (
|
|
35
|
+
"You are an expert Python test developer. Your task is to write new unit tests to cover missing lines "
|
|
36
|
+
"in a given code chunk. You must follow the style of existing tests provided as reference. "
|
|
37
|
+
"Your response must be only the new test code, without any explanations, comments, or markdown formatting. "
|
|
38
|
+
"Your response must be only valid Python code."
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
if test_style == "unittest_class":
|
|
42
|
+
system_msg_specific = (
|
|
43
|
+
"Generate a new test method to be added inside a `unittest.TestCase` class. "
|
|
44
|
+
"The method name should start with `test_` and it should accept `self` as its first argument."
|
|
45
|
+
)
|
|
46
|
+
elif test_style == "pytest_function":
|
|
47
|
+
system_msg_specific = "Generate a new test function. The function name should start with `test_`."
|
|
48
|
+
else:
|
|
49
|
+
system_msg_specific = "Generate a new test function or method, adapting to the existing test file's style."
|
|
50
|
+
|
|
51
|
+
system_msg = f"{system_msg_base} {system_msg_specific}"
|
|
52
|
+
|
|
53
|
+
user_msg: str = f"""Here is the information for the test generation:
|
|
54
|
+
|
|
55
|
+
<file_to_be_tested>
|
|
56
|
+
{file_name}
|
|
57
|
+
</file_to_be_tested>
|
|
58
|
+
|
|
59
|
+
<uncovered_lines>
|
|
60
|
+
{coverage_lines}
|
|
61
|
+
</uncovered_lines>
|
|
62
|
+
|
|
63
|
+
<source_code_chunk>
|
|
64
|
+
{source_code}
|
|
65
|
+
</source_code_chunk>
|
|
66
|
+
|
|
67
|
+
<existing_tests>
|
|
68
|
+
{test_code}
|
|
69
|
+
</existing_tests>
|
|
70
|
+
|
|
71
|
+
<style_reference_tests>
|
|
72
|
+
{other_tests_content}
|
|
73
|
+
</style_reference_tests>
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
logger.debug(f"User message for LLM: {user_msg}")
|
|
77
|
+
try:
|
|
78
|
+
rsp = await client.chat.completions.create(
|
|
79
|
+
model=MODEL,
|
|
80
|
+
messages=[
|
|
81
|
+
{"role": "system", "content": system_msg},
|
|
82
|
+
{"role": "user", "content": user_msg},
|
|
83
|
+
],
|
|
84
|
+
temperature=0.1,
|
|
85
|
+
)
|
|
86
|
+
response_content: str | None = rsp.choices[0].message.content
|
|
87
|
+
if response_content is None:
|
|
88
|
+
response_content = ""
|
|
89
|
+
logger.debug(f"LLM response received: {response_content[:100]}...")
|
|
90
|
+
return response_content
|
|
91
|
+
except Exception as e:
|
|
92
|
+
logger.error(f"Error calling OpenAI API: {e}")
|
|
93
|
+
raise
|
ai_unit_test/main.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from ai_unit_test.cli import app
|
|
6
|
+
|
|
7
|
+
DEFAULT_VERBOSE_OPTION = typer.Option(False, "--verbose", "-v", help="Enable verbose logging.")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def setup_logging(verbose: bool) -> None:
|
|
11
|
+
log_level: int = logging.DEBUG if verbose else logging.INFO
|
|
12
|
+
logging.basicConfig(
|
|
13
|
+
level=log_level,
|
|
14
|
+
format="%(levelname)s: %(message)s",
|
|
15
|
+
)
|
|
16
|
+
logging.debug(f"log_level: {log_level}")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@app.callback()
|
|
20
|
+
def main(verbose: bool = DEFAULT_VERBOSE_OPTION) -> None:
|
|
21
|
+
"""
|
|
22
|
+
AI Unit Test
|
|
23
|
+
"""
|
|
24
|
+
setup_logging(verbose)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
app()
|
ai_unit_test/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: AIUnitTest
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: CLI to generate and update Python unit tests automatically using coverage and AI
|
|
5
|
+
Author: Ofido
|
|
6
|
+
Project-URL: Homepage, https://github.com/ofido/AIUnitTest
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/ofido/AIUnitTest/issues
|
|
8
|
+
Keywords: testing,coverage,openai,automation
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Topic :: Software Development :: Testing
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: openai
|
|
22
|
+
Requires-Dist: coverage
|
|
23
|
+
Requires-Dist: typer
|
|
24
|
+
Requires-Dist: tomli
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: black; extra == "dev"
|
|
27
|
+
Requires-Dist: isort; extra == "dev"
|
|
28
|
+
Requires-Dist: flake8; extra == "dev"
|
|
29
|
+
Requires-Dist: flake8-bugbear; extra == "dev"
|
|
30
|
+
Requires-Dist: flake8-annotations; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy; extra == "dev"
|
|
32
|
+
Requires-Dist: pymarkdown; extra == "dev"
|
|
33
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
|
|
39
|
+
# AIUnitTest
|
|
40
|
+
|
|
41
|
+
AIUnitTest is a command-line tool that reads your `pyproject.toml` and
|
|
42
|
+
test coverage data (`.coverage`) to generate and update missing Python
|
|
43
|
+
unit tests using AI.
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- **Coverage Analysis**: Uses Coverage.py API to identify untested lines.
|
|
48
|
+
- **AI-Powered Test Generation**: Calls OpenAI GPT to create or enhance test cases.
|
|
49
|
+
- **Config-Driven**: Automatically picks up `coverage.run.source` and `pytest.ini_options.testpaths` from `pyproject.toml`.
|
|
50
|
+
- **Auto Mode**: `--auto` flag sets source and tests directories without manual arguments.
|
|
51
|
+
- **Async & Parallel**: Speeds up OpenAI requests for large codebases.
|
|
52
|
+
|
|
53
|
+
## How to Run
|
|
54
|
+
|
|
55
|
+
1. **Install the project:**
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
2. **Run the script:**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
ai-unit-test --auto
|
|
65
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ai_unit_test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
ai_unit_test/_version.py,sha256=vgltXBYF55vNcC2regxjGN0_cbebmm8VgcDdQaDapWQ,511
|
|
3
|
+
ai_unit_test/cli.py,sha256=ndaj8Q-VLMagC0fXxoz_NYOGFEydxdqtXvTBvclvCRU,11146
|
|
4
|
+
ai_unit_test/coverage_helper.py,sha256=LFmcUd6N6RlE0i2gL6ZT0NLQZWKVF075x5QbF_Sqj18,1444
|
|
5
|
+
ai_unit_test/file_helper.py,sha256=6_Nk_vUFNLl88Iz6Aqi-Zg1yXVWLIQmwAdhetP2tyqE,3442
|
|
6
|
+
ai_unit_test/llm.py,sha256=5C9p8AKPTSU1NXbTVhXGAVhPNrliX89BHhXw26Qj5d8,3036
|
|
7
|
+
ai_unit_test/main.py,sha256=JPNCsPzg5bZ6dbnFj5gTUdhBHREsqdiNKOeOz4IBhok,589
|
|
8
|
+
ai_unit_test/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
aiunittest-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
10
|
+
aiunittest-0.0.1.dist-info/METADATA,sha256=iwbZrDfQpUvKsdy4YXJ4VG304xH8yS6YxaADXfpt7Lc,2207
|
|
11
|
+
aiunittest-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
aiunittest-0.0.1.dist-info/top_level.txt,sha256=y04Krysj8jLRuh2omoQmEAm8EyjJ7BP4aDaPcmVxcLQ,13
|
|
13
|
+
aiunittest-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ai_unit_test
|