Skip to content

Commit 97ccbd5

Browse files
committed
test: initial support
1 parent 822bf1c commit 97ccbd5

File tree

6 files changed

+83
-0
lines changed

6 files changed

+83
-0
lines changed

.github/workflows/tests.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
20+
- name: Display Python version
21+
run: python -c "import sys; print(sys.version)"
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements.txt -r requirements-dev.txt
27+
28+
- name: Tests
29+
run: pytest

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ pytest = "^7.0"
2525
mypy = "^1.14"
2626
types-requests = "^2.32"
2727

28+
[tool.pytest.ini_options]
29+
addopts = "-v --cov=typesense_exporter --cov-report=term-missing --cov-report=xml --cov-report=html"
30+
testpaths = ["tests"]
31+
asyncio_mode = "auto"
32+
33+
[tool.coverage.run]
34+
branch = true
35+
source = ["typesense_exporter"]
36+
37+
[tool.coverage.html]
38+
directory = "coverage_html"
39+
2840
[build-system]
2941
requires = ["setuptools", "wheel"]
3042
build-backend = "setuptools.build_meta"

requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mypy>=1.14
2+
pytest-asyncio>=0.23.5
3+
pytest-cov>=4.1
4+
pytest>=7.0
5+
types-requests>=2.32

tests/__init__.py

Whitespace-only changes.

tests/conftest.py

Whitespace-only changes.

tests/test_typesense_exporter.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import pytest
2+
from typesense_exporter import parse_nodes_from_str
3+
4+
5+
@pytest.mark.parametrize("test_input,expected,protocol,description", [
6+
(
7+
"localhost:8108",
8+
[{"host": "localhost", "port": "8108", "protocol": "https"}],
9+
"https",
10+
"single node with port"
11+
),
12+
(
13+
"host1:8108,host2:8108",
14+
[
15+
{"host": "host1", "port": "8108", "protocol": "https"},
16+
{"host": "host2", "port": "8108", "protocol": "https"}
17+
],
18+
"https",
19+
"multiple nodes"
20+
),
21+
(
22+
"localhost",
23+
[{"host": "localhost", "port": "8108", "protocol": "https"}],
24+
"https",
25+
"default port"
26+
),
27+
(
28+
"localhost:8108",
29+
[{"host": "localhost", "port": "8108", "protocol": "http"}],
30+
"http",
31+
"custom protocol"
32+
),
33+
])
34+
def test_parse_nodes_from_str(test_input, expected, protocol, description):
35+
nodes = parse_nodes_from_str(test_input, default_protocol=protocol)
36+
assert len(nodes) == len(expected)
37+
assert nodes == expected

0 commit comments

Comments
 (0)