Skip to content

Commit

Permalink
better ci with precommit and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
miki725 committed Jun 6, 2019
1 parent 7cdd397 commit 1363d30
Show file tree
Hide file tree
Showing 12 changed files with 264 additions and 166 deletions.
42 changes: 42 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
sha: 'master'
hooks:
- id: check-added-large-files
args: [--maxkb=1024]
- id: check-byte-order-marker
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: pretty-format-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: fix-encoding-pragma
exclude: test_data/.*\.py$
- id: flake8
- id: mixed-line-ending
- id: trailing-whitespace

- repo: local
hooks:
- id: importanize
name: importanize
entry: python -m importanize
language: system
language_version: python3
types: [python]
args: [-v]

- repo: https://github.com/ambv/black
sha: 'master'
hooks:
- id: black
args: [--line-length=80, --safe]
language_version: python3
exclude: test_data/.*\.py$
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Config file for automatic testing at travis-ci.org

language: python
dist: xenial
sudo: false

language: python
cache:
directories:
- $HOME/.cache/pip
Expand All @@ -13,14 +15,12 @@ python:
- "2.7"
- "pypy"

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
- pip install -U -r requirements-dev.txt
- pip install tox-travis
- pip install coveralls

script:
make check

after_success:
coveralls
# command to run tests, e.g. python setup.py test
script: tox

sudo: false
after_success: coveralls
1 change: 0 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ Contributors
~~~~~~~~~~~~

* Serkan Hoscai - https://github.com/shosca

37 changes: 20 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.PHONY: clean-pyc clean-build clean

# automatic help generator
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
help: ## show help
@grep -E '^[a-zA-Z_\-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
cut -d':' -f1- | \
sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'

install: ## install all requirements including dev dependencies
pip install -U -r requirements-dev.txt
Expand All @@ -14,22 +17,25 @@ clean-build: ## remove build artifacts
@rm -rf dist/
@rm -rf *.egg-info

clean-pyc: ## remove Python file artifacts
-@find . -name '*.pyc' -follow -print0 | xargs -0 rm -f
-@find . -name '*.pyo' -follow -print0 | xargs -0 rm -f
-@find . -name '__pycache__' -type d -follow -print0 | xargs -0 rm -rf
clean-pyc: ## clean pyc files
-@find . -path ./.tox -prune -o -name '*.pyc' -follow -print0 | xargs -0 rm -f
-@find . -path ./.tox -prune -o -name '*.pyo' -follow -print0 | xargs -0 rm -f
-@find . -path ./.tox -prune -o -name '__pycache__' -type d -follow -print0 | xargs -0 rm -rf

clean-test: ## remove test and coverage artifacts
@rm -rf .coverage coverage*
@rm -rf htmlcov/
@rm -rf .cache

clean-all: ## remove tox test artifacts
clean-all: clean ## remove tox test artifacts
rm -rf .tox

lint: ## check style with flake8 and importanize
flake8 alchemy_mock
python -m importanize --ci alchemy_mock/
lint: clean ## lint whole library
if python -c "import sys; exit(1) if sys.version[:3] < '3.6' else exit(0)"; \
then \
pre-commit run --all-files ; \
fi
python setup.py checkdocs

test: clean ## run all tests
pytest --doctest-modules --cov=alchemy_mock/ --cov-report=term-missing alchemy_mock/
Expand All @@ -42,12 +48,9 @@ test-all: clean ## run all tests with tox

check: lint clean test ## run all necessary steps to check validity of project

release: clean ## package and upload a release
# python setup.py checkdocs
python setup.py sdist upload
python setup.py bdist_wheel upload
release: clean ## push release to pypi
python setup.py sdist bdist_wheel upload

dist: clean ## package
python setup.py sdist
python setup.py bdist_wheel
dist: clean ## create distribution of the library
python setup.py sdist bdist_wheel
ls -l dist
6 changes: 3 additions & 3 deletions alchemy_mock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from __future__ import absolute_import, print_function, unicode_literals


__version__ = '0.4.0'
__description__ = 'SQLAlchemy mock helpers.'
__author__ = 'Miroslav Shubernetskiy'
__version__ = "0.4.0"
__description__ = "SQLAlchemy mock helpers."
__author__ = "Miroslav Shubernetskiy"
35 changes: 22 additions & 13 deletions alchemy_mock/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from .utils import match_type


ALCHEMY_UNARY_EXPRESSION_TYPE = type(column('').asc())
ALCHEMY_BINARY_EXPRESSION_TYPE = type(column('') == '')
ALCHEMY_BOOLEAN_CLAUSE_LIST = type(or_(column('') == '', column('').is_(None)))
ALCHEMY_FUNC_TYPE = type(func.dummy(column('')))
ALCHEMY_UNARY_EXPRESSION_TYPE = type(column("").asc())
ALCHEMY_BINARY_EXPRESSION_TYPE = type(column("") == "")
ALCHEMY_BOOLEAN_CLAUSE_LIST = type(or_(column("") == "", column("").is_(None)))
ALCHEMY_FUNC_TYPE = type(func.dummy(column("")))
ALCHEMY_TYPES = (
ALCHEMY_UNARY_EXPRESSION_TYPE,
ALCHEMY_BINARY_EXPRESSION_TYPE,
Expand All @@ -36,9 +36,8 @@ class PrettyExpression(object):
>>> PrettyExpression(PrettyExpression(15))
15
"""
__slots__ = [
'expr',
]

__slots__ = ["expr"]

def __init__(self, e):
if isinstance(e, PrettyExpression):
Expand All @@ -51,9 +50,9 @@ def __repr__(self):

compiled = self.expr.compile()

return '{}(sql={!r}, params={!r})'.format(
return "{}(sql={!r}, params={!r})".format(
self.expr.__class__.__name__,
match_type(six.text_type(compiled).replace('\n', ' '), str),
match_type(six.text_type(compiled).replace("\n", " "), str),
{match_type(k, str): v for k, v in compiled.params.items()},
)

Expand Down Expand Up @@ -107,27 +106,37 @@ def __eq__(self, other):
# if the right hand side is mock.ANY,
# mocks comparison will not be used hence
# we hard-code comparison here
if isinstance(self.expr, type(mock.ANY)) or isinstance(other, type(mock.ANY)):
if isinstance(self.expr, type(mock.ANY)) or isinstance(
other, type(mock.ANY)
):
return True

# handle string comparison bytes vs unicode in dict keys
if isinstance(self.expr, six.string_types) and isinstance(other, six.string_types):
if isinstance(self.expr, six.string_types) and isinstance(
other, six.string_types
):
other = match_type(other, type(self.expr))

# compare sqlalchemy public api attributes
if type(self.expr) is not type(other):
return False

if not isinstance(self.expr, ALCHEMY_TYPES):

def _(v):
return type(self)(v)

if isinstance(self.expr, (list, tuple)):
return all(_(i) == j for i, j in six.moves.zip_longest(self.expr, other))
return all(
_(i) == j
for i, j in six.moves.zip_longest(self.expr, other)
)

elif isinstance(self.expr, collections.Mapping):
same_keys = self.expr.keys() == other.keys()
return same_keys and all(_(self.expr[k]) == other[k] for k in self.expr.keys())
return same_keys and all(
_(self.expr[k]) == other[k] for k in self.expr.keys()
)

else:
return self.expr is other or self.expr == other
Expand Down
Loading

0 comments on commit 1363d30

Please sign in to comment.