Skip to content
Closed
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
6 changes: 0 additions & 6 deletions .isort.cfg

This file was deleted.

19 changes: 19 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
repos:
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort


- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
language: python
matrix:
include:
- python: 3.4
- python: 3.5
- python: 3.6
- python: 3.7
dist: xenial
sudo: true
- python: pypy3
install:
- pip install -e ".[test]"
- make install
script:
- isort --recursive --diff validators tests && isort --recursive --check-only validators tests
- flake8 validators tests
- py.test --doctest-glob="*.rst" --doctest-modules --ignore=setup.py
- make lint
- make test
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
lint:
isort --diff validators tests
isort --check-only validators tests

flake8 validators tests

install:
pip install -e ".[test]"

test:
py.test --doctest-glob="*.rst" --doctest-modules --ignore=setup.py
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ schema.
True


Development
-----------

To install the package for development use the following commands,

.. code-block:: bash

make install # For installing the package

make test # For running tests

make lint # For checking lint



Pre-commit hooks are run as soon as you commit something.

To run pre-commit hooks manually

.. code-block:: bash

pre-commit run --all-files

Resources
---------

Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

from validators import __version__

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
from validators import __version__

# -- General configuration ------------------------------------------------

Expand Down
17 changes: 17 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[isort]
known_first_party=sqlalchemy_utils,tests
line_length=88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this line length from 79 to 88? In general I'd prefer this PR kept everything the same as it was and just add the pre-commit hooks.

Copy link
Contributor Author

@jdvala jdvala Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will change it back, but 88 seems to be the default for black formatter and I thought that some time in the future we will introduce black as the formatter so I changed it. 88 seems to be the sweet spot. Anyways I will change it.

multi_line_output=3
order_by_type=false
include_trailing_comma=True

[flake8]
ignore = D10,E203,E501,W503,E231,E265,W504,E122,E121
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for adding all these ignores?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these were already set, and there were already a lot of violation for flake8 so for the most common ones I added it to ignore. If I remove them then I would have to do a lot of editing to code which I am not too sure if you would like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kvesteri could you please confirm if these ignores are ok? I can then submit my PR. Thanks

max-line-length = 88
select = A,B,C4,D,E,F,M,Q,T,W,ABS,BLK
inline-quotes = "
docstring-convention = google
exclude =
.git,
__pycache__,
src/validators/libs
13 changes: 4 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
Python Data Validation for Humans™.
"""

from setuptools import setup, find_packages
import os
import re
import sys

from setuptools import find_packages, setup

PY3 = sys.version_info[0] == 3
HERE = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -23,13 +23,8 @@ def get_version():
pattern = r"^__version__ = '(.*?)'$"
return re.search(pattern, contents, re.MULTILINE).group(1)


extras_require = {
'test': [
'pytest>=2.2.3',
'flake8>=2.4.0',
'isort>=4.2.2'
],
'test': ['pytest>=2.2.3', 'flake8>=2.4.0', 'isort>=4.2.2', 'pre-commit',],
}

install_requires = [
Expand Down Expand Up @@ -67,7 +62,7 @@ def get_version():
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
'Topic :: Software Development :: Libraries :: Python Modules',
],
python_requires='>=3.4'
python_requires='>=3.4',
)
153 changes: 79 additions & 74 deletions tests/i18n/test_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,101 +5,106 @@
from validators.i18n.es import es_cif, es_doi, es_nie, es_nif


@pytest.mark.parametrize(('value',), [
('B25162520',),
('U4839822F',),
('B96817697',),
('P7067074J',),
('Q7899705C',),
('C75098681',),
('G76061860',),
('C71345375',),
('G20558169',),
('U5021960I',),
])
@pytest.mark.parametrize(
('value',),
[
('B25162520',),
('U4839822F',),
('B96817697',),
('P7067074J',),
('Q7899705C',),
('C75098681',),
('G76061860',),
('C71345375',),
('G20558169',),
('U5021960I',),
],
)
def test_returns_true_on_valid_cif(value):
assert es_cif(value)


@pytest.mark.parametrize(('value',), [
('12345',),
('ABCDEFGHI',),
('Z5021960I',),
])
@pytest.mark.parametrize(('value',), [('12345',), ('ABCDEFGHI',), ('Z5021960I',),])
def test_returns_false_on_invalid_cif(value):
result = es_cif(value)
assert isinstance(result, ValidationFailure)


@pytest.mark.parametrize(('value',), [
('X0095892M',),
('X8868108K',),
('X2911154K',),
('Y2584969J',),
('X7536157T',),
('Y5840388N',),
('Z2915723H',),
('Y4002236C',),
('X7750702R',),
('Y0408759V',),
])
@pytest.mark.parametrize(
('value',),
[
('X0095892M',),
('X8868108K',),
('X2911154K',),
('Y2584969J',),
('X7536157T',),
('Y5840388N',),
('Z2915723H',),
('Y4002236C',),
('X7750702R',),
('Y0408759V',),
],
)
def test_returns_true_on_valid_nie(value):
assert es_nie(value)


@pytest.mark.parametrize(('value',), [
('K0000023T',),
('L0000024R',),
('M0000025W',),
('00000026A',),
('00000027G',),
('00000028M',),
('00000029Y',),
('00000030F',),
('00000031P',),
('00000032D',),
('00000033X',),
('00000034B',),
('00000035N',),
('00000036J',),
('00000037Z',),
('00000038S',),
('00000039Q',),
('00000040V',),
('00000041H',),
('00000042L',),
('00000043C',),
('00000044K',),
('00000045E',),
])
@pytest.mark.parametrize(
('value',),
[
('K0000023T',),
('L0000024R',),
('M0000025W',),
('00000026A',),
('00000027G',),
('00000028M',),
('00000029Y',),
('00000030F',),
('00000031P',),
('00000032D',),
('00000033X',),
('00000034B',),
('00000035N',),
('00000036J',),
('00000037Z',),
('00000038S',),
('00000039Q',),
('00000040V',),
('00000041H',),
('00000042L',),
('00000043C',),
('00000044K',),
('00000045E',),
],
)
def test_returns_true_on_valid_nif(value):
assert es_nif(value)


@pytest.mark.parametrize(('value',), [
('12345',),
('X0000000T',),
('00000000T',),
('00000001R',),
])
@pytest.mark.parametrize(
('value',), [('12345',), ('X0000000T',), ('00000000T',), ('00000001R',),]
)
def test_returns_false_on_invalid_nif(value):
result = es_nif(value)
assert isinstance(result, ValidationFailure)


@pytest.mark.parametrize(('value',), [
# CIFs
('B25162520',),
('U4839822F',),
('B96817697',),
# NIEs
('X0095892M',),
('X8868108K',),
('X2911154K',),
# NIFs
('26643189N',),
('07060225F',),
('49166693F',),
])
@pytest.mark.parametrize(
('value',),
[
# CIFs
('B25162520',),
('U4839822F',),
('B96817697',),
# NIEs
('X0095892M',),
('X8868108K',),
('X2911154K',),
# NIFs
('26643189N',),
('07060225F',),
('49166693F',),
],
)
def test_returns_true_on_valid_doi(value):
assert es_doi(value)
Loading