From e823bbf101745865034ba655a0deb83b839ac34d Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Mon, 7 Aug 2023 18:37:24 +0700 Subject: [PATCH] test: more --- .git-commits.yaml | 36 +++++++++++++ .pre-commit-config.yaml | 104 ++++++++++++++++++++++++------------- Makefile | 4 +- peewee_migrate/migrator.py | 1 + tests/test_migrator.py | 15 ++++++ 5 files changed, 122 insertions(+), 38 deletions(-) create mode 100644 .git-commits.yaml diff --git a/.git-commits.yaml b/.git-commits.yaml new file mode 100644 index 0000000..2d51f8a --- /dev/null +++ b/.git-commits.yaml @@ -0,0 +1,36 @@ +--- + +convention: + commitTypes: + - feat + - fix + - perf + - refactor + - style + - test + - build + - ops + - docs + - merge + commitScopes: [] + releaseTagGlobPattern: v[0-9]*.[0-9]*.[0-9]* + +changelog: + commitTypes: + - feat + - fix + - perf + - merge + includeInvalidCommits: true + commitScopes: [] + commitIgnoreRegexPattern: "^WIP " + headlines: + feat: Features + fix: Bug Fixes + perf: Performance Improvements + merge: Merges + breakingChange: BREAKING CHANGES + commitUrl: https://github.com/klen/peewee_migrate/commit/%commit% + commitRangeUrl: https://github.com/klen/peewee_migrate/compare/%from%...%to%?diff=split + issueRegexPattern: "#[0-9]+" + issueUrl: https://github.com/klen/peewee_migrate/issues/%issue% diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75a52f9..5d2c758 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,51 +1,83 @@ # See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks + fail_fast: true +default_install_hook_types: [commit-msg, pre-commit, pre-push] repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: check-added-large-files - - id: check-ast - - id: check-case-conflict - - id: check-executables-have-shebangs - - id: check-merge-conflict - - id: check-symlinks - - id: check-toml - - id: check-yaml - - id: debug-statements - - id: end-of-file-fixer - - id: trailing-whitespace + +- repo: https://github.com/qoomon/git-conventional-commits + rev: 'v2.6.5' + hooks: + - id: conventional-commits + args: ["-c", ".git-commits.yaml"] + stages: ["commit-msg"] + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-case-conflict + stages: ["pre-commit"] + - id: check-merge-conflict + stages: ["pre-commit"] + - id: check-added-large-files + stages: ["pre-commit"] + - id: check-ast + stages: ["pre-commit"] + - id: check-executables-have-shebangs + stages: ["pre-commit"] + - id: check-symlinks + stages: ["pre-commit"] + - id: check-toml + stages: ["pre-commit"] + - id: check-yaml + stages: ["pre-commit"] + - id: debug-statements + stages: ["pre-commit"] + - id: end-of-file-fixer + stages: ["pre-commit"] + - id: trailing-whitespace + stages: ["pre-commit"] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.7.0 hooks: - id: black + stages: ["pre-commit"] - repo: https://github.com/python-poetry/poetry - rev: '1.5.1' + rev: '1.5.0' hooks: - - id: poetry-check - - id: poetry-lock - args: ["--no-update"] + - id: poetry-check + files: ^(.*/)?pyproject\.toml$ + stages: ["pre-commit"] + - id: poetry-lock + files: ^(.*/)?(poetry\.lock|pyproject\.toml)$ + args: ["--no-update"] + stages: ["pre-commit"] - repo: local hooks: + - id: ruff + name: ruff + entry: poetry run ruff peewee_migrate + language: system + pass_filenames: false + files: \.py$ + stages: ["pre-commit"] + + - id: mypy + name: mypy + entry: poetry run mypy + language: system + pass_filenames: false + files: \.py$ + stages: ["pre-push"] - - id: mypy - name: mypy - entry: poetry run mypy - language: system - pass_filenames: false - - - id: ruff - name: ruff - entry: poetry run ruff peewee_migrate - language: system - pass_filenames: false - - - id: pytest - name: pytest - entry: poetry run pytest - language: system - pass_filenames: false + - id: pytest + name: pytest + entry: poetry run pytest + language: system + pass_filenames: false + files: \.py$ + stages: ["pre-push"] diff --git a/Makefile b/Makefile index 7f99cfd..1871674 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,9 @@ all: $(VIRTUAL_ENV) # Development # ============= -$(VIRTUAL_ENV): pyproject.toml +$(VIRTUAL_ENV): pyproject.toml .pre-commit-config.yaml @poetry install --with dev - @poetry run pre-commit install --hook-type pre-push + @poetry run pre-commit install @touch $(VIRTUAL_ENV) .PHONY: t test diff --git a/peewee_migrate/migrator.py b/peewee_migrate/migrator.py index 4dff99f..71c92d4 100644 --- a/peewee_migrate/migrator.py +++ b/peewee_migrate/migrator.py @@ -169,6 +169,7 @@ def add_fields(self, model: Union[str, TModelType], **fields: pw.Field) -> TMode meta.table_name, field.column_name, field ) ) + return model add_columns = depricated_method(add_fields, "add_columns") diff --git a/tests/test_migrator.py b/tests/test_migrator.py index d380717..0dfa7ba 100644 --- a/tests/test_migrator.py +++ b/tests/test_migrator.py @@ -178,6 +178,21 @@ class User(pw.Model): assert not migrations +def test_add_field_unique(migrator: Migrator): + @migrator.create_model + class TestTable(pw.Model): + class Meta: + table_name = "test_table" + + field = pw.CharField(null=False) + + migrator() + migrator.add_fields("test_table", field2=pw.CharField(unique=True)) + ops = migrator.__ops__ + assert len(ops) == 1 + assert ops[0].method == "add_column" # type: ignore[union-attr] + + def test_change_field_constraint(migrator: Migrator): @migrator.create_model class TestTable(pw.Model):