Skip to content

Commit d2a162b

Browse files
authored
Improve the unit test flow and conflict name in the document (zilliztech#397)
Signed-off-by: SimFG <[email protected]>
1 parent 5ef5b93 commit d2a162b

File tree

3 files changed

+78
-21
lines changed

3 files changed

+78
-21
lines changed

.github/workflows/unit_test_main.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,42 @@ jobs:
6868
run: |
6969
python3 -m spacy download en_core_web_sm
7070
71-
- name: Unit Tests
71+
- name: Remove coverage xml
72+
run: |
73+
rm -rf ./coverage.xml
74+
75+
- name: Normal Unit Tests
7276
timeout-minutes: 30
7377
shell: bash
74-
working-directory: tests
7578
run: |
7679
export IS_CI=true
7780
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
78-
python3 -m pytest ./
81+
python3 -m pytest -k "not embedding and not processor" --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/
7982
80-
- name: Generate coverage report
83+
- name: Embedding Unit Tests
84+
timeout-minutes: 30
85+
shell: bash
8186
run: |
82-
rm -rf ./coverage.xml
83-
coverage erase
84-
coverage run --source=gptcache -m pytest ./tests
85-
coverage xml
87+
export IS_CI=true
88+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
89+
python3 -m pytest --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/unit_tests/embedding/
90+
91+
- name: Processor Unit Tests
92+
timeout-minutes: 30
93+
shell: bash
94+
run: |
95+
export IS_CI=true
96+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
97+
python3 -m pytest --cov=gptcache --cov-append --cov-report xml:coverage.xml ./tests/unit_tests/processor/
98+
99+
# - name: Generate coverage report
100+
# run: |
101+
# rm -rf ./coverage.xml
102+
# coverage erase
103+
# coverage run --source=gptcache -m pytest -k "not embedding and not processor" ./tests
104+
# coverage run --source=gptcache -m pytest ./tests/unit_tests/embedding/
105+
# coverage run --source=gptcache -m pytest ./tests/unit_tests/processor/
106+
# coverage xml
86107

87108
- name: Upload coverage to Codecov
88109
uses: codecov/[email protected]

docs/_exts/docgen2.py

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55

66
_default_skip_file_list = ["__init__.py"]
77
_default_skip_dir_list = ["__pycache__"]
8+
_conflict_name_dict = {
9+
"manager": ["eviction", "object_data", "scalar_data", "vector_data"]
10+
}
811

912

1013
class DocGen:
11-
def __init__(self, lib_name="gptcache", source_dir="../gptcache", output_dir="references", skip_list=[]):
14+
def __init__(
15+
self,
16+
lib_name="gptcache",
17+
source_dir="../gptcache",
18+
output_dir="references",
19+
skip_list=[],
20+
):
1221
self.lib_name = lib_name
1322
self.output_dir = os.path.abspath(output_dir)
1423
self.source_dir = os.path.abspath(source_dir)
@@ -26,8 +35,13 @@ def section_bar(input_str):
2635
def get_filename(input_str):
2736
if input_str == "gptcache":
2837
return input_str
29-
input_str = os.path.splitext(input_str)[1][1:]
30-
return input_str
38+
suffix = os.path.splitext(input_str)[1][1:]
39+
for conflict_dir, conflict_names in _conflict_name_dict.items():
40+
for conflict_name in conflict_names:
41+
if f"{conflict_dir}.{conflict_name}" in input_str:
42+
return f"{conflict_name}.{suffix}"
43+
44+
return suffix
3145

3246
@staticmethod
3347
def cap(input_str):
@@ -37,17 +51,25 @@ def cap(input_str):
3751
return str.join(" ", [i.capitalize() for i in input_str.split("_")])
3852

3953
def model_name(self, input_str: str):
40-
return self.lib_name + input_str[len(self.source_dir):].replace("/", ".")
54+
return self.lib_name + input_str[len(self.source_dir) :].replace("/", ".")
4155

4256
def get_module_and_libs(self, module_dir, is_root):
4357
module = self.model_name(module_dir)
4458
libs = []
4559
for file in os.listdir(module_dir):
46-
if os.path.isfile(os.path.join(module_dir, file)) and file not in _default_skip_file_list:
60+
if (
61+
os.path.isfile(os.path.join(module_dir, file))
62+
and file not in _default_skip_file_list
63+
):
4764
libs.append(module + "." + os.path.splitext(file)[0])
4865
if not is_root:
49-
if os.path.isdir(os.path.join(module_dir, file)) and file not in _default_skip_dir_list:
50-
_, child_libs = self.get_module_and_libs(os.path.join(module_dir, file), False)
66+
if (
67+
os.path.isdir(os.path.join(module_dir, file))
68+
and file not in _default_skip_dir_list
69+
):
70+
_, child_libs = self.get_module_and_libs(
71+
os.path.join(module_dir, file), False
72+
)
5173
libs.extend(child_libs)
5274
if len(libs) > 0:
5375
sorted(libs)
@@ -57,7 +79,8 @@ def get_module_and_libs(self, module_dir, is_root):
5779
def generate(self):
5880
# Set the output directory
5981
env = Environment(
60-
loader=FileSystemLoader(os.path.join(self.output_dir, "../_templates")), autoescape=select_autoescape()
82+
loader=FileSystemLoader(os.path.join(self.output_dir, "../_templates")),
83+
autoescape=select_autoescape(),
6184
)
6285

6386
# Add custom filters
@@ -89,18 +112,29 @@ def generate(self):
89112
index_temp = env.get_template("index.rst")
90113

91114
with open(os.path.join(self.output_dir, "index.rst"), "w") as f:
92-
t = index_temp.render({"modules": [DocGen.get_filename(module) for module in modules]})
115+
t = index_temp.render(
116+
{"modules": [DocGen.get_filename(module) for module in modules]}
117+
)
93118
f.write(t)
94119

95120
# Render the function templates and write rendered output to files
96121
func_temp = env.get_template("function.rst")
97122

98123
for index, module in enumerate(modules):
99-
with open(os.path.join(self.output_dir, f"{DocGen.get_filename(module)}.rst"), "w") as f:
100-
t = func_temp.render({"module_name": module, "funcs": [(DocGen.get_filename(lib), lib) for lib in libs[index]]})
124+
with open(
125+
os.path.join(self.output_dir, f"{DocGen.get_filename(module)}.rst"), "w"
126+
) as f:
127+
t = func_temp.render(
128+
{
129+
"module_name": module,
130+
"funcs": [
131+
(DocGen.get_filename(lib), lib) for lib in libs[index]
132+
],
133+
}
134+
)
101135
f.write(t)
102136

103137

104138
# if __name__ == "__main__":
105139
# gen = DocGen(source_dir="/Users/derek/fubang/gptcache/gptcache", output_dir="/Users/derek/fubang/gptcache/docs/references")
106-
# gen.generate()
140+
# gen.generate()

tests/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--extra-index-url https://test.pypi.org/simple/
22
loguru==0.5.3
3-
pytest-cov==2.8.1
3+
pytest-cov==4.1.0
44
pytest==7.2.0
55
coverage==7.2.3
66
pytest-assume==2.4.3
@@ -21,4 +21,6 @@ pexpect
2121
spacy
2222
safetensors
2323
typing_extensions<4.6.0
24+
stability-sdk
25+
grpcio==1.53.0
2426
protobuf==3.20.0

0 commit comments

Comments
 (0)