Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/backend_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Test with pytest
if: github.actor != 'dependabot[bot]'
run: |
make run-unit-tests
make run-unit-tests-debug
env:
PYTHONPATH: src
- name: Upload coverage reports to Codecov
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,18 @@ exec-terrarium:
# Testing & Linting
.PHONY: run-unit-tests
run-unit-tests:
poetry run pytest -n auto src/backend/tests/unit/$(file) --cov=src/backend --cov-report=xml

.PHONY: run-unit-tests-debug
run-unit-tests-debug:
poetry run pytest src/backend/tests/unit/$(file) --cov=src/backend --cov-report=xml

.PHONY: run-community-tests
run-community-tests:
poetry run pytest -n auto src/community/tests/$(file) --cov=src/community --cov-report=xml

.PHONY: run-community-tests-debug
run-community-tests-debug:
poetry run pytest src/community/tests/$(file) --cov=src/community --cov-report=xml

.PHONY: run-integration-tests
Expand Down
36 changes: 35 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ freezegun = "^1.5.1"
pre-commit = "^2.20.0"
ruff = "^0.6.0"
pytest-asyncio = "^0.23.7"
pytest-xdist = "^3.6.1"

[tool.poetry.group.setup]
optional = true
Expand Down
4 changes: 2 additions & 2 deletions src/backend/tests/unit/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Writing Unit Test
# Writing Unit Tests

This README will explain how to best write unit tests for the OSS Toolkit project.

Expand All @@ -10,7 +10,7 @@ make test-db
make run-unit-tests
```

## Test DB
## Testing the Database

Some of the unit tests rely on a database being present. The tests are expecting a postgres DB to be running in a docker container. the `make test-db` target will create the test database required for the tests to run.

Expand Down
5 changes: 3 additions & 2 deletions src/backend/tests/unit/tools/test_lang_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from backend.services.context import Context
from backend.tools import LangChainVectorDBRetriever, LangChainWikiRetriever
from backend.tools.base import ToolError, ToolErrorCode

is_cohere_env_set = (
os.environ.get("COHERE_API_KEY") is not None
Expand Down Expand Up @@ -78,7 +79,7 @@ async def test_wiki_retriever_no_docs() -> None:
):
result = await retriever.call({"query": query}, ctx)

assert result == [{'details': '','success': False,'text': 'No results found.','type': 'other'}]
assert result == ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.')



Expand Down Expand Up @@ -164,4 +165,4 @@ async def test_vector_db_retriever_no_docs() -> None:
mock_db.as_retriever().get_relevant_documents.return_value = mock_docs
result = await retriever.call({"query": query}, ctx)

assert result == [{'details': '', 'success': False, 'text': 'No results found.', 'type': 'other'}]
assert result == ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.')
2 changes: 1 addition & 1 deletion src/backend/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _get_class_specific_preamble(cls, tool_class_id):
preamble = f"If you decide to use the toolkit_python_interpreter tool and plan to plot something, try returning the result as a PNG. Ensure that the generated code does not require an internet connection. Avoid using the following packages in code generation: {forbidden_preamble_packages}. "
return preamble
except Exception as e:
logger.error(f"Error while retrieving the Python interpreter preamble.: {str(e)}")
logger.error(event=f"Error while retrieving the Python interpreter preamble: {str(e)}")
return None

return None
Expand Down
Loading