Skip to content

Commit 5e6b396

Browse files
committed
basic tests
1 parent 4d07408 commit 5e6b396

File tree

9 files changed

+1219
-168
lines changed

9 files changed

+1219
-168
lines changed

.github/workflows/tests.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
concurrency:
14+
group: unit-${{ github.ref }}-${{ matrix.python-version }}-${{ matrix.poetry-version }}
15+
cancel-in-progress: true
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: [3.9]
21+
poetry-version: [1.8]
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
with:
26+
persist-credentials: false
27+
fetch-depth: 0
28+
29+
- name: Set up Python ${{ matrix.python-version }}
30+
uses: actions/setup-python@v4
31+
with:
32+
python-version: ${{ matrix.python-version }}
33+
34+
- name: Install Poetry ${{ matrix.poetry-version }}
35+
run: |
36+
pip install "poetry~=${{ matrix.poetry-version }}.0"
37+
38+
# Ensure that Poetry is not upgraded past the version we are testing
39+
poetry add "poetry@~${{ matrix.poetry-version }}" --lock
40+
41+
- name: Install packages
42+
run: |
43+
poetry install
44+
45+
- name: Run tests
46+
run: |
47+
poetry run -- pytest tests

.gitignore

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# PyCharm
132+
.idea/
133+
134+
# VSCode
135+
.vscode

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.3"
2+
services:
3+
ydb:
4+
image: ydbplatform/local-ydb:trunk
5+
restart: always
6+
ports:
7+
- 2136:2136
8+
hostname: localhost
9+
environment:
10+
- YDB_USE_IN_MEMORY_PDISKS=true
11+
- YDB_ENABLE_COLUMN_TABLES=true

poetry.lock

Lines changed: 837 additions & 148 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,16 @@ ydb = "^3.18.3"
1414
pre-commit = "^4.0.1"
1515
ruff = "^0.6.9"
1616
mypy = "^1.11.2"
17-
poethepoet = "^0.29.0"
17+
poethepoet = "0.28.0"
1818
types-protobuf = "^5.28.0.20240924"
19+
PyYAML = "~5.3.0"
20+
pytest = "^7.0.0"
21+
pytest-asyncio = "0.21.0"
22+
pytest-docker-compose = "3.2.1"
23+
docker-compose = "1.29.2"
24+
docker = "5.0.0"
25+
requests = "2.31.0"
26+
urllib3 = "1.26.6"
1927

2028
[build-system]
2129
requires = ["poetry-core"]
@@ -38,6 +46,9 @@ src = ["ydb_dbapi", "tests"]
3846
[tool.ruff.lint]
3947
select = ["F", "E"]
4048

49+
[tool.pytest.ini_options]
50+
asyncio_mode = "auto"
51+
4152
[[tool.mypy.overrides]]
4253
module = "ydb.*"
4354
ignore_missing_imports = true

tests/conftest.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
import pytest
3+
import time
4+
import ydb
5+
6+
7+
@pytest.fixture(scope="module")
8+
def docker_compose_file(pytestconfig):
9+
return os.path.join(str(pytestconfig.rootdir), "docker-compose.yml")
10+
11+
12+
def wait_container_ready(driver):
13+
driver.wait(timeout=30)
14+
15+
with ydb.SessionPool(driver) as pool:
16+
started_at = time.time()
17+
while time.time() - started_at < 30:
18+
try:
19+
with pool.checkout() as session:
20+
session.execute_scheme(
21+
"create table `.sys_health/test_table` "
22+
"(A int32, primary key(A));"
23+
)
24+
25+
return True
26+
27+
except ydb.Error:
28+
time.sleep(1)
29+
30+
raise RuntimeError("Container is not ready after timeout.")
31+
32+
33+
@pytest.fixture(scope="module")
34+
def endpoint(pytestconfig, module_scoped_container_getter):
35+
with ydb.Driver(endpoint="localhost:2136", database="/local") as driver:
36+
wait_container_ready(driver)
37+
yield "localhost:2136"
38+
39+
40+
@pytest.fixture(scope="module")
41+
def database():
42+
return "/local"
43+
44+
45+
@pytest.fixture()
46+
async def driver(endpoint, database, event_loop):
47+
driver_config = ydb.DriverConfig(
48+
endpoint,
49+
database,
50+
)
51+
52+
driver = ydb.aio.Driver(driver_config=driver_config)
53+
await driver.wait(timeout=15)
54+
55+
yield driver
56+
57+
await driver.stop(timeout=10)

tests/test_cursor.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import pytest
2+
3+
import ydb
4+
5+
import ydb_dbapi
6+
import ydb_dbapi.cursors
7+
8+
9+
@pytest.fixture
10+
async def cursor(driver: ydb.aio.Driver):
11+
session_pool = ydb.aio.QuerySessionPool(driver)
12+
session = await session_pool.acquire()
13+
cursor = ydb_dbapi.cursors.Cursor(session_pool, session)
14+
15+
yield cursor
16+
17+
await session_pool.release(session)
18+
19+
20+
@pytest.mark.asyncio
21+
async def test_cursor_ddl(cursor):
22+
op = ydb_dbapi.cursors.YdbQuery(
23+
yql_text="""
24+
CREATE TABLE table (
25+
id Int64 NOT NULL,
26+
i64Val Int64,
27+
PRIMARY KEY(id)
28+
)
29+
""",
30+
is_ddl=True,
31+
)
32+
33+
await cursor.execute(op)

0 commit comments

Comments
 (0)