Skip to content

Commit

Permalink
Improve the unit test flow and conflict name in the document (#397)
Browse files Browse the repository at this point in the history
Signed-off-by: SimFG <bang.fu@zilliz.com>
  • Loading branch information
SimFG authored May 30, 2023
1 parent 7db6237 commit b14d669
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/unit_test_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,42 @@ jobs:
run: |
python3 -m spacy download en_core_web_sm
- name: Unit Tests
- name: Remove coverage xml
run: |
rm -rf ./coverage.xml
- name: Normal Unit Tests
timeout-minutes: 30
shell: bash
working-directory: tests
run: |
export IS_CI=true
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python3 -m pytest ./
python3 -m pytest -k "not embedding and not processor" --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/
- name: Generate coverage report
- name: Embedding Unit Tests
timeout-minutes: 30
shell: bash
run: |
rm -rf ./coverage.xml
coverage erase
coverage run --source=gptcache -m pytest ./tests
coverage xml
export IS_CI=true
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python3 -m pytest --cov=gptcache --cov-report xml:coverage.xml --cov-append ./tests/unit_tests/embedding/
- name: Processor Unit Tests
timeout-minutes: 30
shell: bash
run: |
export IS_CI=true
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
python3 -m pytest --cov=gptcache --cov-append --cov-report xml:coverage.xml ./tests/unit_tests/processor/
# - name: Generate coverage report
# run: |
# rm -rf ./coverage.xml
# coverage erase
# coverage run --source=gptcache -m pytest -k "not embedding and not processor" ./tests
# coverage run --source=gptcache -m pytest ./tests/unit_tests/embedding/
# coverage run --source=gptcache -m pytest ./tests/unit_tests/processor/
# coverage xml

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.0
Expand Down
58 changes: 46 additions & 12 deletions docs/_exts/docgen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@

_default_skip_file_list = ["__init__.py"]
_default_skip_dir_list = ["__pycache__"]
_conflict_name_dict = {
"manager": ["eviction", "object_data", "scalar_data", "vector_data"]
}


class DocGen:
def __init__(self, lib_name="gptcache", source_dir="../gptcache", output_dir="references", skip_list=[]):
def __init__(
self,
lib_name="gptcache",
source_dir="../gptcache",
output_dir="references",
skip_list=[],
):
self.lib_name = lib_name
self.output_dir = os.path.abspath(output_dir)
self.source_dir = os.path.abspath(source_dir)
Expand All @@ -26,8 +35,13 @@ def section_bar(input_str):
def get_filename(input_str):
if input_str == "gptcache":
return input_str
input_str = os.path.splitext(input_str)[1][1:]
return input_str
suffix = os.path.splitext(input_str)[1][1:]
for conflict_dir, conflict_names in _conflict_name_dict.items():
for conflict_name in conflict_names:
if f"{conflict_dir}.{conflict_name}" in input_str:
return f"{conflict_name}.{suffix}"

return suffix

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

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

def get_module_and_libs(self, module_dir, is_root):
module = self.model_name(module_dir)
libs = []
for file in os.listdir(module_dir):
if os.path.isfile(os.path.join(module_dir, file)) and file not in _default_skip_file_list:
if (
os.path.isfile(os.path.join(module_dir, file))
and file not in _default_skip_file_list
):
libs.append(module + "." + os.path.splitext(file)[0])
if not is_root:
if os.path.isdir(os.path.join(module_dir, file)) and file not in _default_skip_dir_list:
_, child_libs = self.get_module_and_libs(os.path.join(module_dir, file), False)
if (
os.path.isdir(os.path.join(module_dir, file))
and file not in _default_skip_dir_list
):
_, child_libs = self.get_module_and_libs(
os.path.join(module_dir, file), False
)
libs.extend(child_libs)
if len(libs) > 0:
sorted(libs)
Expand All @@ -57,7 +79,8 @@ def get_module_and_libs(self, module_dir, is_root):
def generate(self):
# Set the output directory
env = Environment(
loader=FileSystemLoader(os.path.join(self.output_dir, "../_templates")), autoescape=select_autoescape()
loader=FileSystemLoader(os.path.join(self.output_dir, "../_templates")),
autoescape=select_autoescape(),
)

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

with open(os.path.join(self.output_dir, "index.rst"), "w") as f:
t = index_temp.render({"modules": [DocGen.get_filename(module) for module in modules]})
t = index_temp.render(
{"modules": [DocGen.get_filename(module) for module in modules]}
)
f.write(t)

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

for index, module in enumerate(modules):
with open(os.path.join(self.output_dir, f"{DocGen.get_filename(module)}.rst"), "w") as f:
t = func_temp.render({"module_name": module, "funcs": [(DocGen.get_filename(lib), lib) for lib in libs[index]]})
with open(
os.path.join(self.output_dir, f"{DocGen.get_filename(module)}.rst"), "w"
) as f:
t = func_temp.render(
{
"module_name": module,
"funcs": [
(DocGen.get_filename(lib), lib) for lib in libs[index]
],
}
)
f.write(t)


# if __name__ == "__main__":
# gen = DocGen(source_dir="/Users/derek/fubang/gptcache/gptcache", output_dir="/Users/derek/fubang/gptcache/docs/references")
# gen.generate()
# gen.generate()
4 changes: 3 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--extra-index-url https://test.pypi.org/simple/
loguru==0.5.3
pytest-cov==2.8.1
pytest-cov==4.1.0
pytest==7.2.0
coverage==7.2.3
pytest-assume==2.4.3
Expand All @@ -21,4 +21,6 @@ pexpect
spacy
safetensors
typing_extensions<4.6.0
stability-sdk
grpcio==1.53.0
protobuf==3.20.0

0 comments on commit b14d669

Please sign in to comment.