From f5e5d248551dac2bdef86fd6a56f7bbc12de165f Mon Sep 17 00:00:00 2001 From: long2ice Date: Wed, 20 May 2020 18:42:13 +0800 Subject: [PATCH] perfect test --- .coveragerc | 6 + .github/workflows/pypi.yml | 4 +- .github/workflows/pytest.yml | 23 --- .github/workflows/test.yml | 34 ++++ .gitignore | 3 +- CHANGELOG.rst | 4 + Makefile | 37 ++-- README.rst | 2 + aerich/cli.py | 2 +- aerich/ddl/postgres/__init__.py | 8 + aerich/ddl/sqlite/__init__.py | 8 + aerich/migrate.py | 8 + conftest.py | 11 ++ poetry.lock | 259 ++++++++++++++++++++++++++- pyproject.toml | 9 +- pytest.ini | 2 + requirements-dev.txt | 12 +- requirements.txt | 7 +- setup.cfg | 29 +++ setup.py | 2 +- tests/backends/__init__.py | 0 tests/backends/mysql/__init__.py | 19 -- tests/backends/mysql/test_ddl.py | 56 ------ tests/backends/mysql/test_migrate.py | 17 -- tests/test_ddl.py | 115 ++++++++++++ tests/test_migrate.py | 5 + tests/test_utils.py | 6 - tox.ini | 11 -- 28 files changed, 527 insertions(+), 172 deletions(-) create mode 100644 .coveragerc delete mode 100644 .github/workflows/pytest.yml create mode 100644 .github/workflows/test.yml create mode 100644 conftest.py create mode 100644 pytest.ini delete mode 100644 tests/backends/__init__.py delete mode 100644 tests/backends/mysql/__init__.py delete mode 100644 tests/backends/mysql/test_ddl.py delete mode 100644 tests/backends/mysql/test_migrate.py create mode 100644 tests/test_ddl.py create mode 100644 tests/test_migrate.py delete mode 100644 tests/test_utils.py delete mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..4ccd88c --- /dev/null +++ b/.coveragerc @@ -0,0 +1,6 @@ +[run] +branch = True +source = + aerich +[report] +show_missing = True \ No newline at end of file diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml index 388075c..44f27d3 100644 --- a/.github/workflows/pypi.yml +++ b/.github/workflows/pypi.yml @@ -1,12 +1,10 @@ name: pypi - on: release: types: - created - jobs: - build: + publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml deleted file mode 100644 index 3fe13a0..0000000 --- a/.github/workflows/pytest.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: pytest -on: [push, pull_request] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - uses: actions/cache@v1 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements-dev.txt') }} - restore-keys: | - ${{ runner.os }}-pip- - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - - name: Test with pytest - run: | - make test \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..37c5c98 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: test +on: [push, pull_request] +jobs: + testall: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + ports: + - 5432:5432 + env: + POSTGRES_PASSWORD: 123456 + POSTGRES_USER: postgres + options: --health-cmd=pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + steps: + - name: Start MySQL + run: sudo systemctl start mysql.service + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-dev.txt + - name: CI + env: + MYSQL_PASS: root + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + POSTGRES_PASS: 123456 + POSTGRES_HOST: 127.0.0.1 + POSTGRES_PORT: 5432 + run: make testall \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9ba7de7..ee8bf4c 100644 --- a/.gitignore +++ b/.gitignore @@ -142,4 +142,5 @@ cython_debug/ .idea migrations -aerich.ini \ No newline at end of file +aerich.ini +src \ No newline at end of file diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 44807b1..4ef48eb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,10 @@ ChangeLog 0.1 === +0.1.5 +----- +- Add sqlite and postgres support + 0.1.4 ----- - Fix transaction and fields import. diff --git a/Makefile b/Makefile index 874d018..70e2fc3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,10 @@ checkfiles = aerich/ tests/ black_opts = -l 100 -t py38 py_warn = PYTHONDEVMODE=1 +MYSQL_HOST ?= "127.0.0.1" +MYSQL_PORT ?= 3306 +POSTGRES_HOST ?= "127.0.0.1" +POSTGRES_PORT ?= 5432 help: @echo "Aerich development makefile" @@ -18,10 +22,6 @@ deps: @which pip-sync > /dev/null || pip install -q pip-tools @pip install -r requirements-dev.txt -up: - CUSTOM_COMPILE_COMMAND="make up" pip-compile -o requirements-dev.txt -U - sed -i "s/^-e .*/-e ./" requirements.txt - style: deps isort -rc $(checkfiles) black $(black_opts) $(checkfiles) @@ -36,20 +36,25 @@ endif bandit -r $(checkfiles) python setup.py check -mrs -lint: deps -ifneq ($(shell which black),) - black --check $(black_opts) $(checkfiles) || (echo "Please run 'make style' to auto-fix style issues" && false) -endif - flake8 $(checkfiles) - mypy $(checkfiles) - pylint $(checkfiles) - bandit -r $(checkfiles) - python setup.py check -mrs - test: deps - $(py_warn) py.test + $(py_warn) TEST_DB=sqlite://:memory: py.test + +test_sqlite: + $(py_warn) TEST_DB=sqlite://:memory: py.test --cov-report= + +test_mysql: + $(py_warn) TEST_DB="mysql://root:$(MYSQL_PASS)@$(MYSQL_HOST):$(MYSQL_PORT)/test_\{\}" py.test --cov-append --cov-report= + +test_postgres: + $(py_warn) TEST_DB="postgres://postgres:$(POSTGRES_PASS)@$(POSTGRES_HOST):$(POSTGRES_PORT)/test_\{\}" py.test --cov-append --cov-report= + +testall: deps test_sqlite test_postgres test_mysql + coverage report publish: deps rm -fR dist/ python setup.py sdist - twine upload dist/* \ No newline at end of file + twine upload dist/* + +ci: + @act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -b \ No newline at end of file diff --git a/README.rst b/README.rst index 9bbfbe2..fe33932 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +8,8 @@ Aerich :target: https://github.com/long2ice/aerich .. image:: https://github.com/long2ice/aerich/workflows/pypi/badge.svg :target: https://github.com/long2ice/aerich/actions?query=workflow:pypi +.. image:: https://github.com/long2ice/aerich/workflows/test/badge.svg + :target: https://github.com/long2ice/aerich/actions?query=workflow:test Introduction ============ diff --git a/aerich/cli.py b/aerich/cli.py index 8933885..8698ed0 100644 --- a/aerich/cli.py +++ b/aerich/cli.py @@ -154,7 +154,7 @@ def history(ctx): ) @click.pass_context async def init( - ctx: Context, tortoise_orm, location, + ctx: Context, tortoise_orm, location, ): config = ctx.obj["config"] name = ctx.obj["name"] diff --git a/aerich/ddl/postgres/__init__.py b/aerich/ddl/postgres/__init__.py index e69de29..1901301 100644 --- a/aerich/ddl/postgres/__init__.py +++ b/aerich/ddl/postgres/__init__.py @@ -0,0 +1,8 @@ +from tortoise.backends.asyncpg.schema_generator import AsyncpgSchemaGenerator + +from aerich.ddl import BaseDDL + + +class PostgresDDL(BaseDDL): + schema_generator_cls = AsyncpgSchemaGenerator + DIALECT = AsyncpgSchemaGenerator.DIALECT diff --git a/aerich/ddl/sqlite/__init__.py b/aerich/ddl/sqlite/__init__.py index e69de29..0fb28f5 100644 --- a/aerich/ddl/sqlite/__init__.py +++ b/aerich/ddl/sqlite/__init__.py @@ -0,0 +1,8 @@ +from tortoise.backends.sqlite.schema_generator import SqliteSchemaGenerator + +from aerich.ddl import BaseDDL + + +class SqliteDDL(BaseDDL): + schema_generator_cls = SqliteSchemaGenerator + DIALECT = SqliteSchemaGenerator.DIALECT diff --git a/aerich/migrate.py b/aerich/migrate.py index 9e8e111..3cdb299 100644 --- a/aerich/migrate.py +++ b/aerich/migrate.py @@ -13,11 +13,15 @@ from tortoise import ( Model, Tortoise, ) +from tortoise.backends.asyncpg.schema_generator import AsyncpgSchemaGenerator from tortoise.backends.mysql.schema_generator import MySQLSchemaGenerator +from tortoise.backends.sqlite.schema_generator import SqliteSchemaGenerator from tortoise.fields import Field from aerich.ddl import BaseDDL from aerich.ddl.mysql import MysqlDDL +from aerich.ddl.postgres import PostgresDDL +from aerich.ddl.sqlite import SqliteDDL from aerich.exceptions import ConfigurationError from aerich.utils import get_app_connection @@ -76,6 +80,10 @@ class Migrate: connection = get_app_connection(config, app) if connection.schema_generator is MySQLSchemaGenerator: cls.ddl = MysqlDDL(connection) + elif connection.schema_generator is SqliteSchemaGenerator: + cls.ddl = SqliteDDL(connection) + elif connection.schema_generator is AsyncpgSchemaGenerator: + cls.ddl = PostgresDDL(connection) else: raise NotImplementedError("Current only support MySQL") diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..2489eca --- /dev/null +++ b/conftest.py @@ -0,0 +1,11 @@ +import os + +import pytest +from tortoise.contrib.test import finalizer, initializer + + +@pytest.fixture(scope="module", autouse=True) +def initialize_tests(request): + db_url = os.environ.get("TEST_DB", "sqlite://:memory:") + initializer(["tests.models"], db_url=db_url) + request.addfinalizer(finalizer) diff --git a/poetry.lock b/poetry.lock index 9ff5fde..3b76564 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,5 @@ [[package]] -category = "main" +category = "dev" description = "MySQL driver for asyncio." name = "aiomysql" optional = false @@ -38,6 +38,14 @@ doc = ["sphinx-rtd-theme", "sphinx-autodoc-typehints (>=1.2.0)"] test = ["coverage (>=4.5)", "hypothesis (>=4.0)", "pytest (>=3.7.2)", "uvloop"] trio = ["trio (>=0.12)"] +[[package]] +category = "dev" +description = "apipkg: namespace control and lazy-import mechanism" +name = "apipkg" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.5" + [[package]] category = "dev" description = "A small Python module for determining appropriate platform-specific dirs, e.g. a \"user data dir\"." @@ -69,6 +77,19 @@ anyio = "*" dev = ["coverage", "pytest-runner", "pytest-trio", "pytest (>=3)", "sphinx", "tox"] docs = ["sphinx"] +[[package]] +category = "dev" +description = "An asyncio PostgreSQL driver" +name = "asyncpg" +optional = false +python-versions = ">=3.5.0" +version = "0.20.1" + +[package.extras] +dev = ["Cython (0.29.14)", "pytest (>=3.6.0)", "Sphinx (>=1.7.3,<1.8.0)", "sphinxcontrib-asyncio (>=0.2.0,<0.3.0)", "sphinx-rtd-theme (>=0.2.4,<0.3.0)", "pycodestyle (>=2.5.0,<2.6.0)", "flake8 (>=3.7.9,<3.8.0)", "uvloop (>=0.14.0,<0.15.0)"] +docs = ["Sphinx (>=1.7.3,<1.8.0)", "sphinxcontrib-asyncio (>=0.2.0,<0.3.0)", "sphinx-rtd-theme (>=0.2.4,<0.3.0)"] +test = ["pycodestyle (>=2.5.0,<2.6.0)", "flake8 (>=3.7.9,<3.8.0)", "uvloop (>=0.14.0,<0.15.0)"] + [[package]] category = "dev" description = "Enhance the standard unittest package with features for testing asyncio libraries" @@ -121,7 +142,7 @@ typed-ast = ">=1.4.0" d = ["aiohttp (>=3.3.2)", "aiohttp-cors"] [[package]] -category = "main" +category = "dev" description = "Foreign Function Interface for Python calling C code." name = "cffi" optional = false @@ -158,7 +179,18 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "0.4.3" [[package]] -category = "main" +category = "dev" +description = "Code coverage measurement for Python" +name = "coverage" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <4" +version = "5.1" + +[package.extras] +toml = ["toml"] + +[[package]] +category = "dev" description = "cryptography is a package which provides cryptographic recipes and primitives to Python developers." name = "cryptography" optional = false @@ -176,6 +208,20 @@ idna = ["idna (>=2.1)"] pep8test = ["flake8", "flake8-import-order", "pep8-naming"] test = ["pytest (>=3.6.0,<3.9.0 || >3.9.0,<3.9.1 || >3.9.1,<3.9.2 || >3.9.2)", "pretend", "iso8601", "pytz", "hypothesis (>=1.11.4,<3.79.2 || >3.79.2)"] +[[package]] +category = "dev" +description = "execnet: rapid multi-Python deployment" +name = "execnet" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.7.1" + +[package.dependencies] +apipkg = ">=1.4" + +[package.extras] +testing = ["pre-commit"] + [[package]] category = "dev" description = "the modular source code checker: pep8 pyflakes and co" @@ -228,6 +274,30 @@ optional = false python-versions = ">=3.5" version = "8.3.0" +[[package]] +category = "dev" +description = "Optional static typing for Python" +name = "mypy" +optional = false +python-versions = ">=3.5" +version = "0.770" + +[package.dependencies] +mypy-extensions = ">=0.4.3,<0.5.0" +typed-ast = ">=1.4.0,<1.5.0" +typing-extensions = ">=3.7.4" + +[package.extras] +dmypy = ["psutil (>=4.0)"] + +[[package]] +category = "dev" +description = "Experimental type system extensions for programs checked with the mypy typechecker." +name = "mypy-extensions" +optional = false +python-versions = "*" +version = "0.4.3" + [[package]] category = "dev" description = "Core utilities for Python packages" @@ -276,13 +346,26 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.6.0" [[package]] -category = "main" +category = "dev" description = "C parser in Python" name = "pycparser" optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.20" +[[package]] +category = "main" +description = "Data validation and settings management using python 3.6 type hinting" +name = "pydantic" +optional = false +python-versions = ">=3.6" +version = "1.5.1" + +[package.extras] +dotenv = ["python-dotenv (>=0.10.4)"] +email = ["email-validator (>=1.0.3)"] +typing_extensions = ["typing-extensions (>=3.7.2)"] + [[package]] category = "dev" description = "passive checker of Python programs" @@ -292,7 +375,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" version = "2.2.0" [[package]] -category = "main" +category = "dev" description = "Pure Python MySQL Driver" name = "pymysql" optional = false @@ -340,6 +423,49 @@ wcwidth = "*" checkqa-mypy = ["mypy (v0.761)"] testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "requests", "xmlschema"] +[[package]] +category = "dev" +description = "Pytest plugin for measuring coverage." +name = "pytest-cov" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.8.1" + +[package.dependencies] +coverage = ">=4.4" +pytest = ">=3.6" + +[package.extras] +testing = ["fields", "hunter", "process-tests (2.0.2)", "six", "virtualenv"] + +[[package]] +category = "dev" +description = "run tests in isolated forked subprocesses" +name = "pytest-forked" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "1.1.3" + +[package.dependencies] +pytest = ">=3.1.0" + +[[package]] +category = "dev" +description = "pytest xdist plugin for distributed testing and loop-on-failing modes" +name = "pytest-xdist" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" +version = "1.32.0" + +[package.dependencies] +execnet = ">=1.1" +pytest = ">=4.4.0" +pytest-forked = "*" +six = "*" + +[package.extras] +testing = ["filelock"] + [[package]] category = "dev" description = "Alternative regular expression module, to replace re." @@ -349,7 +475,7 @@ python-versions = "*" version = "2020.5.14" [[package]] -category = "main" +category = "dev" description = "Python 2 and 3 compatibility utilities" name = "six" optional = false @@ -399,9 +525,9 @@ pypika = ">=0.36.5" typing-extensions = ">=3.7" [package.source] -reference = "95c384a4742ee5980f8e4ae934bfdb0d8137bb40" +reference = "1f67b7a0ca1384365d6ff89d9e245e733166d1a6" type = "git" -url = "https://github.com/tortoise/tortoise-orm.git" +url = "https://github.com/long2ice/tortoise-orm.git" [[package]] category = "dev" description = "a fork of Python 2 and 3 ast modules with type comment support" @@ -427,7 +553,7 @@ python-versions = "*" version = "0.1.9" [metadata] -content-hash = "1f38996f0ce404419e0361a2545e8a42cc72bae8e5d69910bd29b152b77d2d38" +content-hash = "ee362e98a77707ce405e5aa22f872724bbc4410ee48ef217d5a83e8e3c7c10d0" python-versions = "^3.8" [metadata.files] @@ -443,6 +569,10 @@ anyio = [ {file = "anyio-1.3.0-py3-none-any.whl", hash = "sha256:db2c3d21576870b95d4fd0b8f4a0f9c64057f777c578f3a8127179a17c8c067e"}, {file = "anyio-1.3.0.tar.gz", hash = "sha256:7deae0315dd10aa41c21528b83352e4b52f44e6153a21081a3d1cd8c03728e46"}, ] +apipkg = [ + {file = "apipkg-1.5-py2.py3-none-any.whl", hash = "sha256:58587dd4dc3daefad0487f6d9ae32b4542b185e1c36db6993290e7c41ca2b47c"}, + {file = "apipkg-1.5.tar.gz", hash = "sha256:37228cda29411948b422fae072f57e31d3396d2ee1c9783775980ee9c9990af6"}, +] appdirs = [ {file = "appdirs-1.4.4-py2.py3-none-any.whl", hash = "sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128"}, {file = "appdirs-1.4.4.tar.gz", hash = "sha256:7d5d0167b2b1ba821647616af46a749d1c653740dd0d2415100fe26e27afdf41"}, @@ -454,6 +584,29 @@ async-generator = [ asyncclick = [ {file = "asyncclick-7.0.9.tar.gz", hash = "sha256:62cebf3eca36d973802e2dd521ca1db11c5bf4544e9795e093d1a53cb688a8c2"}, ] +asyncpg = [ + {file = "asyncpg-0.20.1-cp35-cp35m-macosx_10_13_x86_64.whl", hash = "sha256:f7184689177eeb5a11fa1b2baf3f6f2e26bfd7a85acf4de1a3adbd0867d7c0e2"}, + {file = "asyncpg-0.20.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:f0c9719ac00615f097fe91082b785bce36dbf02a5ec4115ede0ebfd2cd9500cb"}, + {file = "asyncpg-0.20.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:1388caa456070dab102be874205e3ae8fd1de2577d5de9fa22e65ba5c0f8b110"}, + {file = "asyncpg-0.20.1-cp35-cp35m-win32.whl", hash = "sha256:ec6e7046c98730cb2ba4df41387e10cb8963a3ac2918f69ae416f8aab9ca7b1b"}, + {file = "asyncpg-0.20.1-cp35-cp35m-win_amd64.whl", hash = "sha256:25edb0b947eb632b6b53e5a4b36cba5677297bb34cbaba270019714d0a5fed76"}, + {file = "asyncpg-0.20.1-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:95cd2df61ee00b789bdcd04a080e6d9188693b841db2bf9a87ebaed9e53147e0"}, + {file = "asyncpg-0.20.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:058baec9d6b75612412baa872a1aa47317d0ff88c318a49f9c4a2389043d5a8d"}, + {file = "asyncpg-0.20.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:c773c7dbe2f4d3ebc9e3030e94303e45d6742e6c2fc25da0c46a56ea3d83caeb"}, + {file = "asyncpg-0.20.1-cp36-cp36m-win32.whl", hash = "sha256:5664d1bd8abe64fc60a0e701eb85fa1d8c9a4a8018a5a59164d27238f2caf395"}, + {file = "asyncpg-0.20.1-cp36-cp36m-win_amd64.whl", hash = "sha256:57666dfae38f4dbf84ffbf0c5c0f78733fef0e8e083230275dcb9ccad1d5ee09"}, + {file = "asyncpg-0.20.1-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:0c336903c3b08e970f8af2f606332f1738dba156bca83ed0467dc2f5c70da796"}, + {file = "asyncpg-0.20.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:ad5ba062e09673b1a4b8d0facaf5a6d9719bf7b337440d10b07fe994d90a9552"}, + {file = "asyncpg-0.20.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:ba90d3578bc6dddcbce461875672fd9bdb34f0b8215b68612dd3b65a956ff51c"}, + {file = "asyncpg-0.20.1-cp37-cp37m-win32.whl", hash = "sha256:da238592235717419a6a7b5edc8564da410ebfd056ca4ecc41e70b1b5df86fba"}, + {file = "asyncpg-0.20.1-cp37-cp37m-win_amd64.whl", hash = "sha256:74510234c294c6a6767089ba9c938f09a491426c24405634eb357bd91dffd734"}, + {file = "asyncpg-0.20.1-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:391aea89871df8c1560750af6c7170f2772c2d133b34772acf3637e3cf4db93e"}, + {file = "asyncpg-0.20.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:a981500bf6947926e53c48f4d60ae080af1b4ad7fa78e363465a5b5ad4f2b65e"}, + {file = "asyncpg-0.20.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:a9e6fd6f0f9e8bd77e9a4e1ef9a4f83a80674d9136a754ae3603e915da96b627"}, + {file = "asyncpg-0.20.1-cp38-cp38-win32.whl", hash = "sha256:e39aac2b3a2f839ce65aa255ce416de899c58b7d38d601d24ca35558e13b48e3"}, + {file = "asyncpg-0.20.1-cp38-cp38-win_amd64.whl", hash = "sha256:2af6a5a705accd36e13292ea43d08c20b15e52d684beb522cb3a7d3c9c8f3f48"}, + {file = "asyncpg-0.20.1.tar.gz", hash = "sha256:394bf19bdddbba07a38cd6fb526ebf66e120444d6b3097332b78efd5b26495b0"}, +] asynctest = [ {file = "asynctest-0.13.0-py3-none-any.whl", hash = "sha256:5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676"}, {file = "asynctest-0.13.0.tar.gz", hash = "sha256:c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac"}, @@ -511,6 +664,39 @@ colorama = [ {file = "colorama-0.4.3-py2.py3-none-any.whl", hash = "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff"}, {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, ] +coverage = [ + {file = "coverage-5.1-cp27-cp27m-macosx_10_12_x86_64.whl", hash = "sha256:0cb4be7e784dcdc050fc58ef05b71aa8e89b7e6636b99967fadbdba694cf2b65"}, + {file = "coverage-5.1-cp27-cp27m-macosx_10_13_intel.whl", hash = "sha256:c317eaf5ff46a34305b202e73404f55f7389ef834b8dbf4da09b9b9b37f76dd2"}, + {file = "coverage-5.1-cp27-cp27m-manylinux1_i686.whl", hash = "sha256:b83835506dfc185a319031cf853fa4bb1b3974b1f913f5bb1a0f3d98bdcded04"}, + {file = "coverage-5.1-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:5f2294dbf7875b991c381e3d5af2bcc3494d836affa52b809c91697449d0eda6"}, + {file = "coverage-5.1-cp27-cp27m-win32.whl", hash = "sha256:de807ae933cfb7f0c7d9d981a053772452217df2bf38e7e6267c9cbf9545a796"}, + {file = "coverage-5.1-cp27-cp27m-win_amd64.whl", hash = "sha256:bf9cb9a9fd8891e7efd2d44deb24b86d647394b9705b744ff6f8261e6f29a730"}, + {file = "coverage-5.1-cp27-cp27mu-manylinux1_i686.whl", hash = "sha256:acf3763ed01af8410fc36afea23707d4ea58ba7e86a8ee915dfb9ceff9ef69d0"}, + {file = "coverage-5.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:dec5202bfe6f672d4511086e125db035a52b00f1648d6407cc8e526912c0353a"}, + {file = "coverage-5.1-cp35-cp35m-macosx_10_12_x86_64.whl", hash = "sha256:7a5bdad4edec57b5fb8dae7d3ee58622d626fd3a0be0dfceda162a7035885ecf"}, + {file = "coverage-5.1-cp35-cp35m-manylinux1_i686.whl", hash = "sha256:1601e480b9b99697a570cea7ef749e88123c04b92d84cedaa01e117436b4a0a9"}, + {file = "coverage-5.1-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:dbe8c6ae7534b5b024296464f387d57c13caa942f6d8e6e0346f27e509f0f768"}, + {file = "coverage-5.1-cp35-cp35m-win32.whl", hash = "sha256:a027ef0492ede1e03a8054e3c37b8def89a1e3c471482e9f046906ba4f2aafd2"}, + {file = "coverage-5.1-cp35-cp35m-win_amd64.whl", hash = "sha256:0e61d9803d5851849c24f78227939c701ced6704f337cad0a91e0972c51c1ee7"}, + {file = "coverage-5.1-cp36-cp36m-macosx_10_13_x86_64.whl", hash = "sha256:2d27a3f742c98e5c6b461ee6ef7287400a1956c11421eb574d843d9ec1f772f0"}, + {file = "coverage-5.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:66460ab1599d3cf894bb6baee8c684788819b71a5dc1e8fa2ecc152e5d752019"}, + {file = "coverage-5.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:5c542d1e62eece33c306d66fe0a5c4f7f7b3c08fecc46ead86d7916684b36d6c"}, + {file = "coverage-5.1-cp36-cp36m-win32.whl", hash = "sha256:2742c7515b9eb368718cd091bad1a1b44135cc72468c731302b3d641895b83d1"}, + {file = "coverage-5.1-cp36-cp36m-win_amd64.whl", hash = "sha256:dead2ddede4c7ba6cb3a721870f5141c97dc7d85a079edb4bd8d88c3ad5b20c7"}, + {file = "coverage-5.1-cp37-cp37m-macosx_10_13_x86_64.whl", hash = "sha256:01333e1bd22c59713ba8a79f088b3955946e293114479bbfc2e37d522be03355"}, + {file = "coverage-5.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:e1ea316102ea1e1770724db01998d1603ed921c54a86a2efcb03428d5417e489"}, + {file = "coverage-5.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:adeb4c5b608574a3d647011af36f7586811a2c1197c861aedb548dd2453b41cd"}, + {file = "coverage-5.1-cp37-cp37m-win32.whl", hash = "sha256:782caea581a6e9ff75eccda79287daefd1d2631cc09d642b6ee2d6da21fc0a4e"}, + {file = "coverage-5.1-cp37-cp37m-win_amd64.whl", hash = "sha256:00f1d23f4336efc3b311ed0d807feb45098fc86dee1ca13b3d6768cdab187c8a"}, + {file = "coverage-5.1-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:402e1744733df483b93abbf209283898e9f0d67470707e3c7516d84f48524f55"}, + {file = "coverage-5.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:a3f3654d5734a3ece152636aad89f58afc9213c6520062db3978239db122f03c"}, + {file = "coverage-5.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:6402bd2fdedabbdb63a316308142597534ea8e1895f4e7d8bf7476c5e8751fef"}, + {file = "coverage-5.1-cp38-cp38-win32.whl", hash = "sha256:8fa0cbc7ecad630e5b0f4f35b0f6ad419246b02bc750de7ac66db92667996d24"}, + {file = "coverage-5.1-cp38-cp38-win_amd64.whl", hash = "sha256:79a3cfd6346ce6c13145731d39db47b7a7b859c0272f02cdb89a3bdcbae233a0"}, + {file = "coverage-5.1-cp39-cp39-win32.whl", hash = "sha256:a82b92b04a23d3c8a581fc049228bafde988abacba397d57ce95fe95e0338ab4"}, + {file = "coverage-5.1-cp39-cp39-win_amd64.whl", hash = "sha256:bb28a7245de68bf29f6fb199545d072d1036a1917dca17a1e75bbb919e14ee8e"}, + {file = "coverage-5.1.tar.gz", hash = "sha256:f90bfc4ad18450c80b024036eaf91e4a246ae287701aaa88eaebebf150868052"}, +] cryptography = [ {file = "cryptography-2.9.2-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:daf54a4b07d67ad437ff239c8a4080cfd1cc7213df57d33c97de7b4738048d5e"}, {file = "cryptography-2.9.2-cp27-cp27m-manylinux1_x86_64.whl", hash = "sha256:3b3eba865ea2754738616f87292b7f29448aec342a7c720956f8083d252bf28b"}, @@ -532,6 +718,10 @@ cryptography = [ {file = "cryptography-2.9.2-cp38-cp38-win_amd64.whl", hash = "sha256:1dfa985f62b137909496e7fc182dac687206d8d089dd03eaeb28ae16eec8e7d5"}, {file = "cryptography-2.9.2.tar.gz", hash = "sha256:a0c30272fb4ddda5f5ffc1089d7405b7a71b0b0f51993cb4e5dbb4590b2fc229"}, ] +execnet = [ + {file = "execnet-1.7.1-py2.py3-none-any.whl", hash = "sha256:d4efd397930c46415f62f8a31388d6be4f27a91d7550eb79bc64a756e0056547"}, + {file = "execnet-1.7.1.tar.gz", hash = "sha256:cacb9df31c9680ec5f95553976c4da484d407e85e41c83cb812aa014f0eddc50"}, +] flake8 = [ {file = "flake8-3.8.1-py2.py3-none-any.whl", hash = "sha256:6c1193b0c3f853ef763969238f6c81e9e63ace9d024518edc020d5f1d6d93195"}, {file = "flake8-3.8.1.tar.gz", hash = "sha256:ea6623797bf9a52f4c9577d780da0bb17d65f870213f7b5bcc9fca82540c31d5"}, @@ -553,6 +743,26 @@ more-itertools = [ {file = "more-itertools-8.3.0.tar.gz", hash = "sha256:558bb897a2232f5e4f8e2399089e35aecb746e1f9191b6584a151647e89267be"}, {file = "more_itertools-8.3.0-py3-none-any.whl", hash = "sha256:7818f596b1e87be009031c7653d01acc46ed422e6656b394b0f765ce66ed4982"}, ] +mypy = [ + {file = "mypy-0.770-cp35-cp35m-macosx_10_6_x86_64.whl", hash = "sha256:a34b577cdf6313bf24755f7a0e3f3c326d5c1f4fe7422d1d06498eb25ad0c600"}, + {file = "mypy-0.770-cp35-cp35m-manylinux1_x86_64.whl", hash = "sha256:86c857510a9b7c3104cf4cde1568f4921762c8f9842e987bc03ed4f160925754"}, + {file = "mypy-0.770-cp35-cp35m-win_amd64.whl", hash = "sha256:a8ffcd53cb5dfc131850851cc09f1c44689c2812d0beb954d8138d4f5fc17f65"}, + {file = "mypy-0.770-cp36-cp36m-macosx_10_6_x86_64.whl", hash = "sha256:7687f6455ec3ed7649d1ae574136835a4272b65b3ddcf01ab8704ac65616c5ce"}, + {file = "mypy-0.770-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:3beff56b453b6ef94ecb2996bea101a08f1f8a9771d3cbf4988a61e4d9973761"}, + {file = "mypy-0.770-cp36-cp36m-win_amd64.whl", hash = "sha256:15b948e1302682e3682f11f50208b726a246ab4e6c1b39f9264a8796bb416aa2"}, + {file = "mypy-0.770-cp37-cp37m-macosx_10_6_x86_64.whl", hash = "sha256:b90928f2d9eb2f33162405f32dde9f6dcead63a0971ca8a1b50eb4ca3e35ceb8"}, + {file = "mypy-0.770-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:c56ffe22faa2e51054c5f7a3bc70a370939c2ed4de308c690e7949230c995913"}, + {file = "mypy-0.770-cp37-cp37m-win_amd64.whl", hash = "sha256:8dfb69fbf9f3aeed18afffb15e319ca7f8da9642336348ddd6cab2713ddcf8f9"}, + {file = "mypy-0.770-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:219a3116ecd015f8dca7b5d2c366c973509dfb9a8fc97ef044a36e3da66144a1"}, + {file = "mypy-0.770-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:7ec45a70d40ede1ec7ad7f95b3c94c9cf4c186a32f6bacb1795b60abd2f9ef27"}, + {file = "mypy-0.770-cp38-cp38-win_amd64.whl", hash = "sha256:f91c7ae919bbc3f96cd5e5b2e786b2b108343d1d7972ea130f7de27fdd547cf3"}, + {file = "mypy-0.770-py3-none-any.whl", hash = "sha256:3b1fc683fb204c6b4403a1ef23f0b1fac8e4477091585e0c8c54cbdf7d7bb164"}, + {file = "mypy-0.770.tar.gz", hash = "sha256:8a627507ef9b307b46a1fea9513d5c98680ba09591253082b4c48697ba05a4ae"}, +] +mypy-extensions = [ + {file = "mypy_extensions-0.4.3-py2.py3-none-any.whl", hash = "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d"}, + {file = "mypy_extensions-0.4.3.tar.gz", hash = "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8"}, +] packaging = [ {file = "packaging-20.4-py2.py3-none-any.whl", hash = "sha256:998416ba6962ae7fbd6596850b80e17859a5753ba17c32284f67bfff33784181"}, {file = "packaging-20.4.tar.gz", hash = "sha256:4357f74f47b9c12db93624a82154e9b120fa8293699949152b22065d556079f8"}, @@ -577,6 +787,25 @@ pycparser = [ {file = "pycparser-2.20-py2.py3-none-any.whl", hash = "sha256:7582ad22678f0fcd81102833f60ef8d0e57288b6b5fb00323d101be910e35705"}, {file = "pycparser-2.20.tar.gz", hash = "sha256:2d475327684562c3a96cc71adf7dc8c4f0565175cf86b6d7a404ff4c771f15f0"}, ] +pydantic = [ + {file = "pydantic-1.5.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:2a6904e9f18dea58f76f16b95cba6a2f20b72d787abd84ecd67ebc526e61dce6"}, + {file = "pydantic-1.5.1-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:da8099fca5ee339d5572cfa8af12cf0856ae993406f0b1eb9bb38c8a660e7416"}, + {file = "pydantic-1.5.1-cp36-cp36m-manylinux2014_i686.whl", hash = "sha256:68dece67bff2b3a5cc188258e46b49f676a722304f1c6148ae08e9291e284d98"}, + {file = "pydantic-1.5.1-cp36-cp36m-manylinux2014_x86_64.whl", hash = "sha256:ab863853cb502480b118187d670f753be65ec144e1654924bec33d63bc8b3ce2"}, + {file = "pydantic-1.5.1-cp36-cp36m-win_amd64.whl", hash = "sha256:2007eb062ed0e57875ce8ead12760a6e44bf5836e6a1a7ea81d71eeecf3ede0f"}, + {file = "pydantic-1.5.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:20a15a303ce1e4d831b4e79c17a4a29cb6740b12524f5bba3ea363bff65732bc"}, + {file = "pydantic-1.5.1-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:473101121b1bd454c8effc9fe66d54812fdc128184d9015c5aaa0d4e58a6d338"}, + {file = "pydantic-1.5.1-cp37-cp37m-manylinux2014_i686.whl", hash = "sha256:9be755919258d5d168aeffbe913ed6e8bd562e018df7724b68cabdee3371e331"}, + {file = "pydantic-1.5.1-cp37-cp37m-manylinux2014_x86_64.whl", hash = "sha256:b96ce81c4b5ca62ab81181212edfd057beaa41411cd9700fbcb48a6ba6564b4e"}, + {file = "pydantic-1.5.1-cp37-cp37m-win_amd64.whl", hash = "sha256:93b9f265329d9827f39f0fca68f5d72cc8321881cdc519a1304fa73b9f8a75bd"}, + {file = "pydantic-1.5.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:e2c753d355126ddd1eefeb167fa61c7037ecd30b98e7ebecdc0d1da463b4ea09"}, + {file = "pydantic-1.5.1-cp38-cp38-manylinux1_i686.whl", hash = "sha256:8433dbb87246c0f562af75d00fa80155b74e4f6924b0db6a2078a3cd2f11c6c4"}, + {file = "pydantic-1.5.1-cp38-cp38-manylinux2014_i686.whl", hash = "sha256:0a1cdf24e567d42dc762d3fed399bd211a13db2e8462af9dfa93b34c41648efb"}, + {file = "pydantic-1.5.1-cp38-cp38-manylinux2014_x86_64.whl", hash = "sha256:8be325fc9da897029ee48d1b5e40df817d97fe969f3ac3fd2434ba7e198c55d5"}, + {file = "pydantic-1.5.1-cp38-cp38-win_amd64.whl", hash = "sha256:3714a4056f5bdbecf3a41e0706ec9b228c9513eee2ad884dc2c568c4dfa540e9"}, + {file = "pydantic-1.5.1-py36.py37.py38-none-any.whl", hash = "sha256:70f27d2f0268f490fe3de0a9b6fca7b7492b8fd6623f9fecd25b221ebee385e3"}, + {file = "pydantic-1.5.1.tar.gz", hash = "sha256:f0018613c7a0d19df3240c2a913849786f21b6539b9f23d85ce4067489dfacfa"}, +] pyflakes = [ {file = "pyflakes-2.2.0-py2.py3-none-any.whl", hash = "sha256:0d94e0e05a19e57a99444b6ddcf9a6eb2e5c68d3ca1e98e90707af8152c90a92"}, {file = "pyflakes-2.2.0.tar.gz", hash = "sha256:35b2d75ee967ea93b55750aa9edbbf72813e06a66ba54438df2cfac9e3c27fc8"}, @@ -596,6 +825,18 @@ pytest = [ {file = "pytest-5.4.2-py3-none-any.whl", hash = "sha256:95c710d0a72d91c13fae35dce195633c929c3792f54125919847fdcdf7caa0d3"}, {file = "pytest-5.4.2.tar.gz", hash = "sha256:eb2b5e935f6a019317e455b6da83dd8650ac9ffd2ee73a7b657a30873d67a698"}, ] +pytest-cov = [ + {file = "pytest-cov-2.8.1.tar.gz", hash = "sha256:cc6742d8bac45070217169f5f72ceee1e0e55b0221f54bcf24845972d3a47f2b"}, + {file = "pytest_cov-2.8.1-py2.py3-none-any.whl", hash = "sha256:cdbdef4f870408ebdbfeb44e63e07eb18bb4619fae852f6e760645fa36172626"}, +] +pytest-forked = [ + {file = "pytest-forked-1.1.3.tar.gz", hash = "sha256:1805699ed9c9e60cb7a8179b8d4fa2b8898098e82d229b0825d8095f0f261100"}, + {file = "pytest_forked-1.1.3-py2.py3-none-any.whl", hash = "sha256:1ae25dba8ee2e56fb47311c9638f9e58552691da87e82d25b0ce0e4bf52b7d87"}, +] +pytest-xdist = [ + {file = "pytest-xdist-1.32.0.tar.gz", hash = "sha256:1d4166dcac69adb38eeaedb88c8fada8588348258a3492ab49ba9161f2971129"}, + {file = "pytest_xdist-1.32.0-py2.py3-none-any.whl", hash = "sha256:ba5ec9fde3410bd9a116ff7e4f26c92e02fa3d27975ef3ad03f330b3d4b54e91"}, +] regex = [ {file = "regex-2020.5.14-cp27-cp27m-win32.whl", hash = "sha256:e565569fc28e3ba3e475ec344d87ed3cd8ba2d575335359749298a0899fe122e"}, {file = "regex-2020.5.14-cp27-cp27m-win_amd64.whl", hash = "sha256:d466967ac8e45244b9dfe302bbe5e3337f8dc4dec8d7d10f5e950d83b140d33a"}, diff --git a/pyproject.toml b/pyproject.toml index 6702ad2..bf599eb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,9 @@ authors = ["long2ice "] [tool.poetry.dependencies] python = "^3.8" -tortoise-orm = {git = "https://github.com/tortoise/tortoise-orm.git", branch = "develop"} -aiomysql = "*" +tortoise-orm = {git = "https://github.com/long2ice/tortoise-orm.git", branch = "develop"} asyncclick = "*" +pydantic = "*" [tool.poetry.dev-dependencies] taskipy = "*" @@ -17,6 +17,11 @@ flake8 = "*" isort = "*" black = "^19.10b0" pytest = "*" +pytest-cov = "*" +aiomysql = "*" +asyncpg = "*" +pytest-xdist = "*" +mypy = "*" [tool.taskipy.tasks] export = "poetry export -f requirements.txt --without-hashes > requirements.txt" diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..eb81f7f --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +addopts = -p no:warnings --ignore=src \ No newline at end of file diff --git a/requirements-dev.txt b/requirements-dev.txt index 2b91103..81c383f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,9 +1,11 @@ aiomysql==0.0.20 aiosqlite==0.13.0 anyio==1.3.0 +apipkg==1.5 appdirs==1.4.4 async-generator==1.10 asyncclick==7.0.9 +asyncpg==0.20.1 asynctest==0.13.0 atomicwrites==1.4.0; sys_platform == "win32" attrs==19.3.0 @@ -12,29 +14,37 @@ cffi==1.14.0 ciso8601==2.1.3; sys_platform != "win32" and implementation_name == "cpython" click==7.1.2 colorama==0.4.3; sys_platform == "win32" +coverage==5.1 cryptography==2.9.2 +execnet==1.7.1 flake8==3.8.1 iso8601==0.1.12; sys_platform == "win32" or implementation_name != "cpython" isort==4.3.21 mccabe==0.6.1 more-itertools==8.3.0 +mypy==0.770 +mypy-extensions==0.4.3 packaging==20.4 pathspec==0.8.0 pluggy==0.13.1 py==1.8.1 pycodestyle==2.6.0 pycparser==2.20 +pydantic==1.5.1 pyflakes==2.2.0 pymysql==0.9.2 pyparsing==2.4.7 pypika==0.37.6 pytest==5.4.2 +pytest-cov==2.8.1 +pytest-forked==1.1.3 +pytest-xdist==1.32.0 regex==2020.5.14 six==1.14.0 sniffio==1.1.0 taskipy==1.2.1 toml==0.10.1 --e git+https://github.com/tortoise/tortoise-orm.git@95c384a4742ee5980f8e4ae934bfdb0d8137bb40#egg=tortoise-orm +-e git+https://github.com/long2ice/tortoise-orm.git@1f67b7a0ca1384365d6ff89d9e245e733166d1a6#egg=tortoise-orm typed-ast==1.4.1 typing-extensions==3.7.4.2 wcwidth==0.1.9 diff --git a/requirements.txt b/requirements.txt index b81e49a..623ebe3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,15 +1,10 @@ -aiomysql==0.0.20 aiosqlite==0.13.0 anyio==1.3.0 async-generator==1.10 asyncclick==7.0.9 -cffi==1.14.0 ciso8601==2.1.3; sys_platform != "win32" and implementation_name == "cpython" -cryptography==2.9.2 iso8601==0.1.12; sys_platform == "win32" or implementation_name != "cpython" -pycparser==2.20 -pymysql==0.9.2 +pydantic==1.5.1 pypika==0.37.6 -six==1.14.0 sniffio==1.1.0 typing-extensions==3.7.4.2 diff --git a/setup.cfg b/setup.cfg index 8442426..cf9b321 100644 --- a/setup.cfg +++ b/setup.cfg @@ -14,5 +14,34 @@ force_grid_wrap=0 use_parentheses=True line_length=100 +[tool:pytest] +addopts = -n auto --cov=tortoise --tb=native -q +[mypy] +pretty = True +ignore_missing_imports = True +check_untyped_defs = True +disallow_subclassing_any = True +disallow_untyped_calls = True +disallow_untyped_defs = False +disallow_incomplete_defs = False +disallow_untyped_decorators = True +no_implicit_optional = True +warn_redundant_casts = True +warn_unused_ignores = True +warn_no_return = True +warn_return_any = False +warn_unused_configs = True +warn_unreachable = True +allow_redefinition = True +strict_equality = True +show_error_context = True +[mypy-tests.*] +check_untyped_defs = False +disallow_untyped_defs = False +disallow_incomplete_defs = False +warn_unreachable = False + +[mypy-conftest] +disallow_untyped_defs = False \ No newline at end of file diff --git a/setup.py b/setup.py index 1452c96..c082fee 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,6 @@ setup( keywords=( 'migrate Tortoise-ORM mysql' ), - dependency_links=['https://github.com/tortoise/tortoise-orm.git@develop#egg=tortoise-orm'], + dependency_links=['https://github.com/long2ice/tortoise-orm.git@develop#egg=tortoise-orm'], install_requires=requirements(), ) diff --git a/tests/backends/__init__.py b/tests/backends/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/backends/mysql/__init__.py b/tests/backends/mysql/__init__.py deleted file mode 100644 index c25edb5..0000000 --- a/tests/backends/mysql/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -from asynctest import TestCase -from tortoise import Tortoise - -from aerich.ddl.mysql import MysqlDDL - -TORTOISE_ORM = { - "connections": {"default": "mysql://root:123456@127.0.0.1:3306/test",}, - "apps": {"models": {"models": ["tests.models"], "default_connection": "default",},}, -} - - -class DBTestCase(TestCase): - async def setUp(self) -> None: - await Tortoise.init(config=TORTOISE_ORM) - self.client = Tortoise.get_connection("default") - self.ddl = MysqlDDL(self.client) - - async def tearDown(self) -> None: - await Tortoise.close_connections() diff --git a/tests/backends/mysql/test_ddl.py b/tests/backends/mysql/test_ddl.py deleted file mode 100644 index 6f7ab9b..0000000 --- a/tests/backends/mysql/test_ddl.py +++ /dev/null @@ -1,56 +0,0 @@ -from tests.backends.mysql import DBTestCase -from tests.models import Category - - -class TestDDL(DBTestCase): - def test_create_table(self): - ret = self.ddl.create_table(Category) - self.assertEqual( - ret, - """CREATE TABLE IF NOT EXISTS `category` ( - `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, - `slug` VARCHAR(200) NOT NULL, - `name` VARCHAR(200) NOT NULL, - `created_at` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), - `user_id` INT NOT NULL COMMENT 'User', - CONSTRAINT `fk_category_user_e2e3874c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE -) CHARACTER SET utf8mb4;""", - ) - - def test_drop_table(self): - ret = self.ddl.drop_table(Category) - self.assertEqual(ret, "DROP TABLE IF EXISTS category") - - def test_add_column(self): - ret = self.ddl.add_column(Category, Category._meta.fields_map.get("name")) - self.assertEqual(ret, "ALTER TABLE category ADD `name` VARCHAR(200) NOT NULL") - - def test_drop_column(self): - ret = self.ddl.drop_column(Category, "name") - self.assertEqual(ret, "ALTER TABLE category DROP COLUMN name") - self.assertEqual(ret, "ALTER TABLE category DROP COLUMN name") - - def test_add_index(self): - ret = self.ddl.add_index(Category, ["name"]) - self.assertEqual(ret, "ALTER TABLE category ADD INDEX idx_category_name_8b0cb9 (`name`)") - ret = self.ddl.add_index(Category, ["name"], True) - self.assertEqual( - ret, "ALTER TABLE category ADD UNIQUE INDEX uid_category_name_8b0cb9 (`name`)" - ) - - def test_drop_index(self): - ret = self.ddl.drop_index(Category, ["name"]) - self.assertEqual(ret, "ALTER TABLE category DROP INDEX idx_category_name_8b0cb9") - ret = self.ddl.drop_index(Category, ["name"], True) - self.assertEqual(ret, "ALTER TABLE category DROP INDEX uid_category_name_8b0cb9") - - def test_add_fk(self): - ret = self.ddl.add_fk(Category, Category._meta.fields_map.get("user")) - self.assertEqual( - ret, - "ALTER TABLE category ADD CONSTRAINT `fk_category_user_e2e3874c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE", - ) - - def test_drop_fk(self): - ret = self.ddl.drop_fk(Category, Category._meta.fields_map.get("user")) - self.assertEqual(ret, "ALTER TABLE category DROP FOREIGN KEY fk_category_user_e2e3874c") diff --git a/tests/backends/mysql/test_migrate.py b/tests/backends/mysql/test_migrate.py deleted file mode 100644 index 0741700..0000000 --- a/tests/backends/mysql/test_migrate.py +++ /dev/null @@ -1,17 +0,0 @@ -from asynctest import TestCase -from tortoise import Tortoise - -from aerich.migrate import Migrate -from tests.backends.mysql import TORTOISE_ORM - - -class TestMigrate(TestCase): - async def setUp(self) -> None: - await Migrate.init_with_old_models(TORTOISE_ORM, "models", "./migrations") - - async def test_migrate(self): - Migrate.diff_model( - Tortoise.apps.get("models").get("Category"), - Tortoise.apps.get("diff_models").get("Category"), - ) - print(Migrate.upgrade_operators) diff --git a/tests/test_ddl.py b/tests/test_ddl.py new file mode 100644 index 0000000..224a7f7 --- /dev/null +++ b/tests/test_ddl.py @@ -0,0 +1,115 @@ +from tortoise import Tortoise +from tortoise.backends.asyncpg.schema_generator import AsyncpgSchemaGenerator +from tortoise.backends.mysql.schema_generator import MySQLSchemaGenerator +from tortoise.backends.sqlite.schema_generator import SqliteSchemaGenerator +from tortoise.contrib import test + +from aerich.ddl.mysql import MysqlDDL +from aerich.ddl.postgres import PostgresDDL +from aerich.ddl.sqlite import SqliteDDL +from tests.models import Category + + +class TestDDL(test.TruncationTestCase): + maxDiff = None + + def setUp(self) -> None: + client = Tortoise.get_connection("models") + if client.schema_generator is MySQLSchemaGenerator: + self.ddl = MysqlDDL(client) + elif client.schema_generator is SqliteSchemaGenerator: + self.ddl = SqliteDDL(client) + elif client.schema_generator is AsyncpgSchemaGenerator: + self.ddl = PostgresDDL(client) + + def test_create_table(self): + ret = self.ddl.create_table(Category) + if isinstance(self.ddl, MysqlDDL): + self.assertEqual( + ret, + """CREATE TABLE IF NOT EXISTS `category` ( + `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT, + `slug` VARCHAR(200) NOT NULL, + `name` VARCHAR(200) NOT NULL, + `created_at` DATETIME(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), + `user_id` INT NOT NULL COMMENT 'User', + CONSTRAINT `fk_category_user_e2e3874c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE +) CHARACTER SET utf8mb4;""", + ) + elif isinstance(self.ddl, SqliteDDL): + self.assertEqual( + ret, + """CREATE TABLE IF NOT EXISTS "category" ( + "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + "slug" VARCHAR(200) NOT NULL, + "name" VARCHAR(200) NOT NULL, + "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "user_id" INT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE /* User */ +);""", + ) + elif isinstance(self.ddl, PostgresDDL): + print(ret) + self.assertEqual( + ret, + """CREATE TABLE IF NOT EXISTS "category" ( + "id" SERIAL NOT NULL PRIMARY KEY, + "slug" VARCHAR(200) NOT NULL, + "name" VARCHAR(200) NOT NULL, + "created_at" TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + "user_id" INT NOT NULL REFERENCES "user" ("id") ON DELETE CASCADE +); +COMMENT ON COLUMN "category"."user_id" IS 'User';""", + ) + + def test_drop_table(self): + ret = self.ddl.drop_table(Category) + self.assertEqual(ret, "DROP TABLE IF EXISTS category") + + def test_add_column(self): + ret = self.ddl.add_column(Category, Category._meta.fields_map.get("name")) + if isinstance(self.ddl, MysqlDDL): + self.assertEqual(ret, "ALTER TABLE category ADD `name` VARCHAR(200) NOT NULL") + elif isinstance(self.ddl, PostgresDDL): + self.assertEqual(ret, 'ALTER TABLE category ADD "name" VARCHAR(200) NOT NULL') + elif isinstance(self.ddl, SqliteDDL): + self.assertEqual(ret, 'ALTER TABLE category ADD "name" VARCHAR(200) NOT NULL') + + def test_drop_column(self): + ret = self.ddl.drop_column(Category, "name") + self.assertEqual(ret, "ALTER TABLE category DROP COLUMN name") + self.assertEqual(ret, "ALTER TABLE category DROP COLUMN name") + + def test_add_index(self): + index = self.ddl.add_index(Category, ["name"]) + index_u = self.ddl.add_index(Category, ["name"], True) + if isinstance(self.ddl, MysqlDDL): + self.assertEqual( + index, "ALTER TABLE category ADD INDEX idx_category_name_8b0cb9 (`name`)" + ) + self.assertEqual( + index_u, "ALTER TABLE category ADD UNIQUE INDEX uid_category_name_8b0cb9 (`name`)" + ) + elif isinstance(self.ddl, SqliteDDL): + self.assertEqual( + index_u, 'ALTER TABLE category ADD UNIQUE INDEX uid_category_name_8b0cb9 ("name")' + ) + self.assertEqual( + index_u, 'ALTER TABLE category ADD UNIQUE INDEX uid_category_name_8b0cb9 ("name")' + ) + + def test_drop_index(self): + ret = self.ddl.drop_index(Category, ["name"]) + self.assertEqual(ret, "ALTER TABLE category DROP INDEX idx_category_name_8b0cb9") + ret = self.ddl.drop_index(Category, ["name"], True) + self.assertEqual(ret, "ALTER TABLE category DROP INDEX uid_category_name_8b0cb9") + + def test_add_fk(self): + ret = self.ddl.add_fk(Category, Category._meta.fields_map.get("user")) + self.assertEqual( + ret, + "ALTER TABLE category ADD CONSTRAINT `fk_category_user_e2e3874c` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE", + ) + + def test_drop_fk(self): + ret = self.ddl.drop_fk(Category, Category._meta.fields_map.get("user")) + self.assertEqual(ret, "ALTER TABLE category DROP FOREIGN KEY fk_category_user_e2e3874c") diff --git a/tests/test_migrate.py b/tests/test_migrate.py new file mode 100644 index 0000000..bd82e01 --- /dev/null +++ b/tests/test_migrate.py @@ -0,0 +1,5 @@ +from tortoise.contrib import test + + +class TestMigrate(test.TruncationTestCase): + pass diff --git a/tests/test_utils.py b/tests/test_utils.py deleted file mode 100644 index 6176ca6..0000000 --- a/tests/test_utils.py +++ /dev/null @@ -1,6 +0,0 @@ -from unittest import TestCase - - -class TestUtils(TestCase): - def test_get_app_connection(self): - pass diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 847aa22..0000000 --- a/tox.ini +++ /dev/null @@ -1,11 +0,0 @@ -[tox] -envlist = py{37,38,39} -skip_missing_interpreters = True - -[testenv] -whitelist_externals= - make -commands= - make ci -deps = - -r requirements-dev.txt