Skip to content

Commit 52be9d5

Browse files
committed
ADD: Release version test for databento-python
1 parent 5d1dc0a commit 52be9d5

File tree

10 files changed

+319
-115
lines changed

10 files changed

+319
-115
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@ jobs:
3131
scripts/build.sh
3232
3333
# Run tests
34+
- name: Run tests in release mode
35+
if: ${{ github.ref == 'refs/heads/main' }}
36+
run: scripts/test.sh --release
3437
- name: Run tests
38+
if: ${{ github.ref != 'refs/heads/main' }}
3539
run: scripts/test.sh

scripts/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#! /usr/bin/env bash
2-
pytest tests .
2+
pytest tests . $@

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pathlib
2+
3+
4+
TESTS_ROOT = pathlib.Path(__file__).absolute().parent
5+
PROJECT_ROOT = pathlib.Path(__file__).absolute().parent.parent

tests/conftest.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
"""Pytest fixtures"""
2+
import pathlib
3+
from typing import Callable, Iterable
4+
5+
import pytest
6+
from databento import Schema
7+
8+
from tests import TESTS_ROOT
9+
10+
11+
def pytest_addoption(parser: pytest.Parser) -> None:
12+
"""
13+
Function to customize pytest cli options.
14+
This should not be invoked directly.
15+
16+
Parameters
17+
----------
18+
parser : pytest.Parser
19+
The pytest argument parser.
20+
21+
See Also
22+
--------
23+
pytest.addoption
24+
25+
"""
26+
# Add a --release flag
27+
parser.addoption(
28+
"--release",
29+
action="store_true",
30+
help="indicates release tests should be run",
31+
)
32+
33+
34+
def pytest_configure(config: pytest.Config) -> None:
35+
"""
36+
Function to configure pytest.
37+
This should not be invoked directly.
38+
39+
Parameters
40+
----------
41+
config : pytest.Config
42+
The pytest configuration.
43+
44+
"""
45+
# Add custom mark for `release`
46+
config.addinivalue_line(
47+
"markers",
48+
"release: mark tests as release tests (run with --release)",
49+
)
50+
51+
52+
def pytest_collection_modifyitems(
53+
config: pytest.Config,
54+
items: Iterable[pytest.Item],
55+
) -> None:
56+
"""
57+
Function to customize test items.
58+
This should not be invoked directly.
59+
60+
Parameters
61+
----------
62+
config : pytest.Config
63+
The pytest configuration.
64+
items : Iterable[pytest.Item]
65+
The pytest test item.
66+
67+
"""
68+
skip_release = pytest.mark.skip(
69+
reason="skipping release test (invoke pytest with --release to execute)",
70+
)
71+
72+
for item in items:
73+
# Skip release tests if `--release` was not specified
74+
if "release" in item.keywords and not config.getoption("--release"):
75+
item.add_marker(skip_release)
76+
77+
78+
@pytest.fixture(name="test_data_path")
79+
def fixture_test_data_path() -> Callable[[Schema], pathlib.Path]:
80+
"""
81+
Factory fixture for retrieving stub data paths.
82+
83+
Parameters
84+
----------
85+
schema : Schema
86+
The schema of the stub data path to request.
87+
88+
Returns
89+
-------
90+
Callable
91+
92+
See Also
93+
--------
94+
test_data
95+
96+
"""
97+
98+
def func(schema: Schema) -> pathlib.Path:
99+
return pathlib.Path(TESTS_ROOT) / "data" / f"test_data.{schema}.dbn.zst"
100+
101+
return func
102+
103+
104+
@pytest.fixture(name="test_data")
105+
def fixture_test_data(
106+
test_data_path: Callable[[Schema], pathlib.Path],
107+
) -> Callable[[Schema], bytes]:
108+
"""
109+
Factory fixture for retrieving stub test data.
110+
111+
Parameters
112+
----------
113+
test_data_path : Callable
114+
The test_data_path fixture.
115+
116+
Returns
117+
-------
118+
Callable
119+
120+
See Also
121+
--------
122+
test_data_path
123+
124+
"""
125+
126+
def func(schema: Schema) -> bytes:
127+
return test_data_path(schema).read_bytes()
128+
129+
return func

tests/fixtures.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

tests/test_bento_data_source.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import pathlib
2+
from typing import Callable
3+
14
import pytest
25
from databento.common.dbnstore import FileDataSource, MemoryDataSource
36
from databento.common.enums import Schema
47

5-
from tests.fixtures import get_test_data, get_test_data_path
6-
78

89
@pytest.mark.parametrize("schema", [pytest.param(x) for x in Schema])
910
def test_memory_data_source(
11+
test_data: Callable[[Schema], bytes],
1012
schema: Schema,
1113
) -> None:
1214
"""Test create of MemoryDataSource"""
@@ -18,7 +20,7 @@ def test_memory_data_source(
1820
):
1921
pytest.skip(f"untested schema {schema}")
2022

21-
data = get_test_data(schema)
23+
data = test_data(schema)
2224
data_source = MemoryDataSource(data)
2325

2426
assert len(data) == data_source.nbytes
@@ -27,6 +29,7 @@ def test_memory_data_source(
2729

2830
@pytest.mark.parametrize("schema", [pytest.param(x) for x in Schema])
2931
def test_file_data_source(
32+
test_data_path: Callable[[Schema], pathlib.Path],
3033
schema: Schema,
3134
) -> None:
3235
"""Test create of FileDataSource"""
@@ -38,7 +41,7 @@ def test_file_data_source(
3841
):
3942
pytest.skip(f"untested schema {schema}")
4043

41-
path = get_test_data_path(schema)
44+
path = test_data_path(schema)
4245
data_source = FileDataSource(path)
4346

4447
assert path.stat().st_size == data_source.nbytes

0 commit comments

Comments
 (0)