Skip to content

Commit 32eaa20

Browse files
committed
LCORE-304: Info about tests
1 parent 75b4f4f commit 32eaa20

File tree

4 files changed

+211
-120
lines changed

4 files changed

+211
-120
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ The development requires at least [Python 3.12](https://docs.python.org/3/whatsn
4646

4747
### Tooling installation
4848

49-
1. `pip install --user pdm`
50-
1. `pdm --version` -- should return no error
49+
1. `pip install --user uv`
50+
1. `uv --version` -- should return no error
5151

5252

5353

@@ -60,10 +60,10 @@ git clone https://github.com/YOUR-GIT-PROFILE/lightspeed-stack.git
6060
# move into the directory
6161
cd lightspeed-stack
6262

63-
# setup your devel environment with pdm
64-
pdm install -G dev
63+
# setup your devel environment with uv
64+
uv install -G dev
6565

66-
# Now you can run test commands trough make targets, or prefix the rest of commands with `pdm run`, eg. `pdm run make test`
66+
# Now you can run test commands trough make targets, or prefix the rest of commands with `uv run`, eg. `uv run make test`
6767

6868
# run unit tests
6969
make unit-tests
@@ -173,114 +173,7 @@ Static security check is performed by _Bandit_ tool. The check can be started by
173173
```
174174
make security-check
175175
```
176-
## Testing
177176

178-
Two groups of software tests are used in this repository, each group from the test suite having different granularity. These groups are designed to represent three layers:
179-
180-
1. Unit Tests
181-
1. Integration Tests
182-
183-
Unit tests followed by integration and e2e tests can be started by using the following command:
184-
185-
```
186-
make test
187-
```
188-
189-
It is also possible to run just one selected group of tests:
190-
191-
```
192-
make test-unit Run the unit tests
193-
make test-integration Run integration tests tests
194-
make test-e2e Run end to end tests
195-
```
196-
197-
All tests are based on the [Pytest framework](https://docs.pytest.org/en/) and code coverage is measured by the plugin [pytest-cov](https://github.com/pytest-dev/pytest-cov). For mocking and patching, the [unittest framework](https://docs.python.org/3/library/unittest.html) is used.
198-
199-
Currently code coverage threshold for integration tests is set to 60%. This value is specified directly in Makefile, because the coverage threshold is different from threshold required for unit tests.
200-
201-
As specified in Definition of Done, new changes need to be covered by tests.
202-
203-
204-
205-
### Tips and hints for developing unit tests
206-
207-
#### Patching
208-
209-
**WARNING**:
210-
Since tests are executed using Pytest, which relies heavily on fixtures,
211-
we discourage use of `patch` decorators in all test code, as they may interact with one another.
212-
213-
It is possible to use patching inside the test implementation as a context manager:
214-
215-
```python
216-
def test_xyz():
217-
with patch("ols.config", new=Mock()):
218-
...
219-
...
220-
...
221-
```
222-
223-
- `new=` allow us to use different function or class
224-
- `return_value=` allow us to define return value (no mock will be called)
225-
226-
227-
#### Verifying that some exception is thrown
228-
229-
Sometimes it is needed to test whether some exception is thrown from a tested function or method. In this case `pytest.raises` can be used:
230-
231-
232-
```python
233-
def test_conversation_cache_wrong_cache(invalid_cache_type_config):
234-
"""Check if wrong cache env.variable is detected properly."""
235-
with pytest.raises(ValueError):
236-
CacheFactory.conversation_cache(invalid_cache_type_config)
237-
```
238-
239-
It is also possible to check if the exception is thrown with the expected message. The message (or its part) is written as regexp:
240-
241-
```python
242-
def test_constructor_no_provider():
243-
"""Test that constructor checks for provider."""
244-
# we use bare Exception in the code, so need to check
245-
# message, at least
246-
with pytest.raises(Exception, match="ERROR: Missing provider"):
247-
load_llm(provider=None)
248-
```
249-
250-
#### Checking what was printed and logged to stdout or stderr by the tested code
251-
252-
It is possible to capture stdout and stderr by using standard fixture `capsys`:
253-
254-
```python
255-
def test_foobar(capsys):
256-
"""Test the foobar function that prints to stdout."""
257-
foobar("argument1", "argument2")
258-
259-
# check captured log output
260-
captured_out = capsys.readouterr().out
261-
assert captured_out == "Output printed by foobar function"
262-
captured_err = capsys.readouterr().err
263-
assert captured_err == ""
264-
```
265-
266-
Capturing logs:
267-
268-
```python
269-
@patch.dict(os.environ, {"LOG_LEVEL": "INFO"})
270-
def test_logger_show_message_flag(mock_load_dotenv, capsys):
271-
"""Test logger set with show_message flag."""
272-
logger = Logger(logger_name="foo", log_level=logging.INFO, show_message=True)
273-
logger.logger.info("This is my debug message")
274-
275-
# check captured log output
276-
# the log message should be captured
277-
captured_out = capsys.readouterr().out
278-
assert "This is my debug message" in captured_out
279-
280-
# error output should be empty
281-
captured_err = capsys.readouterr().err
282-
assert captured_err == ""
283-
```
284177

285178

286179
## Code style

README.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,26 @@ Lightspeed Core Stack (LCS) is an AI-powered assistant that provides answers to
1212
<!-- vim-markdown-toc GFM -->
1313

1414
* [Architecture](#architecture)
15-
* [Integration with Llama Stack](#integration-with-llama-stack)
1615
* [Prerequisites](#prerequisites)
1716
* [Installation](#installation)
1817
* [Configuration](#configuration)
18+
* [Integration with Llama Stack](#integration-with-llama-stack)
1919
* [Llama Stack as separate server](#llama-stack-as-separate-server)
2020
* [Llama Stack as client library](#llama-stack-as-client-library)
2121
* [System prompt](#system-prompt)
2222
* [Usage](#usage)
2323
* [Make targets](#make-targets)
2424
* [Running Linux container image](#running-linux-container-image)
2525
* [Endpoints](#endpoints)
26+
* [OpenAPI specification](#openapi-specification)
2627
* [Readiness Endpoint](#readiness-endpoint)
2728
* [Liveness Endpoint](#liveness-endpoint)
2829
* [Publish the service as Python package on PyPI](#publish-the-service-as-python-package-on-pypi)
2930
* [Generate distribution archives to be uploaded into Python registry](#generate-distribution-archives-to-be-uploaded-into-python-registry)
3031
* [Upload distribution archives into selected Python registry](#upload-distribution-archives-into-selected-python-registry)
3132
* [Packages on PyPI and Test PyPI](#packages-on-pypi-and-test-pypi)
3233
* [Contributing](#contributing)
34+
* [Testing](#testing)
3335
* [License](#license)
3436
* [Additional tools](#additional-tools)
3537
* [Utility to generate OpenAPI schema](#utility-to-generate-openapi-schema)
@@ -52,12 +54,6 @@ Overall architecture with all main parts is displayed below:
5254

5355
Lightspeed Core Stack is based on the FastAPI framework (Uvicorn). The service is split into several parts described below.
5456

55-
## Integration with Llama Stack
56-
57-
![Integration with Llama Stack](docs/core2llama-stack_interface.png)
58-
59-
60-
6157
# Prerequisites
6258

6359
* Python 3.12, or 3.13
@@ -73,16 +69,19 @@ Installation steps depends on operation system. Please look at instructions for
7369
- [macOS installation](https://lightspeed-core.github.io/lightspeed-stack/installation_macos)
7470

7571

76-
7772
# Configuration
7873

74+
## Integration with Llama Stack
75+
7976
The Llama Stack can be run as a standalone server and accessed via its the REST
8077
API. However, instead of direct communication via the REST API (and JSON
8178
format), there is an even better alternative. It is based on the so-called
8279
Llama Stack Client. It is a library available for Python, Swift, Node.js or
8380
Kotlin, which "wraps" the REST API stack in a suitable way, which is easier for
8481
many applications.
8582

83+
![Integration with Llama Stack](docs/core2llama-stack_interface.png)
84+
8685
## Llama Stack as separate server
8786

8887
If Llama Stack runs as a separate server, the Lightspeed service needs to be configured to be able to access it. For example, if server runs on localhost:8321, the service configuration should look like:
@@ -311,10 +310,19 @@ If this configuration file does not exist, you will be prompted to specify API t
311310
* https://test.pypi.org/project/lightspeed-stack/0.1.0/
312311

313312

313+
314314
# Contributing
315315

316316
* See [contributors](CONTRIBUTING.md) guide.
317317

318+
319+
320+
# Testing
321+
322+
* See [testing](docs/testing.md) guide.
323+
324+
325+
318326
# License
319327

320328
Published under the Apache 2.0 License

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# GitHub pages

0 commit comments

Comments
 (0)