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: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[flake8]
max-line-length = 120
pytest-mark-no-parentheses = false
pytest-fixture-no-parentheses = false
2 changes: 1 addition & 1 deletion .github/workflows/conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
# Check for environment.yml changes
- name: Cache conda dependencies
id: conda
uses: actions/cache@v2
uses: actions/cache@v4
env:
# Increase this value to manually reset cache if needed
CONDA_CACHE_NUMBER: 0
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.8', '3.9', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.8'
- uses: pre-commit/action@v2.0.0
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ repos:
language_version: python3

- repo: https://github.com/myint/docformatter
rev: v1.5.0
# Temp pin for https://github.com/PyCQA/docformatter/issues/293
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38
hooks:
- id: docformatter
args: [
Expand All @@ -42,7 +43,7 @@ repos:
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']

- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
Expand Down
2 changes: 1 addition & 1 deletion birdfeeder/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = "Vladimir Kamarzin"
__email__ = "vvk@vvk.pp.ru"
__version__ = "1.3.0"
__version__ = "1.4.0"
40 changes: 36 additions & 4 deletions birdfeeder/pytest_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os
import shutil
import socket
import time
Expand Down Expand Up @@ -140,7 +139,6 @@ def mysql(session_id, unused_port, docker_manager):
"""Creates MySQL docker container."""
port = unused_port()
password = "pass"
volume = f"/tmp/mysql-data/{session_id}" if os.getenv("CI") else f"birdfeeder-mysql-test-{session_id}"
options = " ".join(
[
"--innodb-flush-log-at-trx-commit=0",
Expand All @@ -158,8 +156,6 @@ def mysql(session_id, unused_port, docker_manager):
name=f"mysql-{session_id}",
ports={"3306": port},
environment={"MYSQL_ROOT_PASSWORD": password},
# Speed up MySQL startup time, approx 30 seconds
volumes=[f"{volume}:/var/lib/mysql:rw"],
detach=True,
# needed for compatibility with Apple Silicon computers
# becausre there's no ARM version of MySQL 5.7 image
Expand All @@ -177,6 +173,42 @@ def mysql(session_id, unused_port, docker_manager):
container.remove(v=True, force=True)


@pytest.fixture(scope="session")
def mysql8(session_id, unused_port, docker_manager):
"""Creates MySQL docker container."""
port = unused_port()
password = "pass"
options = " ".join(
[
"--innodb-flush-log-at-trx-commit=0",
"--innodb-flush-method=O_DIRECT_NO_FSYNC",
"--innodb-file-per-table=OFF",
"--sql-mode=''",
]
)

container = docker_manager.containers.run(
image="mysql:8.4",
# Setting some command-line options to speed up test execution and to bring AWS settings
command=options,
name=f"mysql-8-{session_id}",
ports={"3306": port},
environment={"MYSQL_ROOT_PASSWORD": password},
detach=True,
platform="linux/x86_64",
)
container.service_port = port
container.user = "root"
container.host = "127.0.0.1"
container.password = password

try:
yield container
finally:
# Cleanup everything after test run
container.remove(v=True, force=True)


def wait_db(url: Union[str, URL], retries: int = 60) -> None:
"""Waits for server readiness."""
while retries:
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies:
- PyMySQL>=1.0.2,<2.0.0
- mysqlclient>=2,<3
- pip
- async-timeout>=5.0.1,<6.0.0
- pip:
- poetry2conda>=0.3,<0.4
- pre-commit>=2.2.0,<3.0.0
2,024 changes: 1,087 additions & 937 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

# Default section.
# Convert dephell metainfo and dependencies from poetry to setup.py:
Expand Down Expand Up @@ -28,7 +28,7 @@ versioning = "semver"

[tool.poetry]
name = "birdfeeder-coinalpha"
version = "1.3.0"
version = "1.4.0"
description = "Helper library for CoinAlpha projects"
license = "MIT"
authors = ["Vladimir Kamarzin <vvk@vvk.pp.ru>"]
Expand Down Expand Up @@ -63,8 +63,9 @@ kafka-python = "^2"
pydantic = "^1.9.0"
boto3 = "^1"
aioconsole = ">=0.1.16"
async-timeout = "^5.0.1"

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
# See https://python-poetry.org/docs/dependency-specification/
poetry2conda = "^0.3"
pre-commit = "^2.2.0"
Expand Down
22 changes: 3 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
from distutils.core import setup # type: ignore[misc]

import os.path

Expand All @@ -21,7 +21,7 @@
setup(
long_description=readme,
name='birdfeeder-coinalpha',
version='1.3.0',
version='1.4.0',
description='Helper library for CoinAlpha projects',
python_requires='==3.*,>=3.8.0',
project_urls={"repository": "https://github.com/coinalpha/birdfeeder"},
Expand All @@ -42,6 +42,7 @@
'aioconsole>=0.1.16',
'aiohttp==3.*,>=3.2.0',
'aiorun==2020.*,>=2020.0.0',
'async-timeout==5.*,>=5.0.1',
'boto3==1.*,>=1.0.0',
'cachetools==4.*,>=4.0.0',
'environs==9.*,>=9.0.0',
Expand All @@ -52,21 +53,4 @@
'ruamel.yaml==0.*,>=0.16.0',
'typer>=0.3',
],
extras_require={
"dev": [
"docker==4.*,>=4.0.0",
"mysqlclient==2.*,>=2.0.0",
"poetry2conda==0.*,>=0.3.0",
"pre-commit==2.*,>=2.2.0",
"pymysql==1.*,>=1.0.2",
"pytest==6.*,>=6.0.0",
"pytest-aiohttp",
"pytest-asyncio==0.*,>=0.14.0",
"pytest-cov==2.*,>=2.7.0",
"pytest-mock==3.*,>=3.1.0",
"redis==3.*,>=3.5.0",
"sqlalchemy==1.*,>=1.4.0",
"sqlalchemy-utils==0.*,>=0.37.0",
]
},
)
5 changes: 5 additions & 0 deletions tests/test_pytest_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def test_get_new_db(get_new_db, mysql, session_id):
assert db_url is not None


def test_get_new_db_8(get_new_db, mysql8, session_id):
with get_new_db(mysql8, session_id) as db_url:
assert db_url is not None


def test_empty_db(empty_db):
assert empty_db is not None

Expand Down
Loading