From f430251a227c437bcb4e99c4995702e667b3aeec Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:15:44 +0200 Subject: [PATCH 01/11] :art: added pre-commit hooks --- .isort.cfg | 6 - .pre-commit-config.yaml | 26 +++ .travis.yml | 1 - Makefile | 8 + docs/conf.py | 167 ++++++++++--------- setup.cfg | 17 ++ setup.py | 61 ++++--- tests/i18n/test_es.py | 153 ++++++++--------- tests/i18n/test_fi.py | 72 ++++---- tests/test_between.py | 23 +-- tests/test_card.py | 57 ++----- tests/test_domain.py | 66 ++++---- tests/test_email.py | 72 ++++---- tests/test_extremes.py | 14 +- tests/test_iban.py | 10 +- tests/test_ipv4.py | 18 +- tests/test_ipv4_cidr.py | 19 +-- tests/test_ipv6.py | 27 +-- tests/test_ipv6_cidr.py | 42 +++-- tests/test_length.py | 42 ++--- tests/test_mac_address.py | 19 ++- tests/test_md5.py | 20 ++- tests/test_sha1.py | 24 ++- tests/test_sha224.py | 24 ++- tests/test_sha256.py | 24 ++- tests/test_sha512.py | 54 +++--- tests/test_slug.py | 15 +- tests/test_url.py | 273 ++++++++++++++++--------------- tests/test_uuid.py | 19 ++- tests/test_validation_failure.py | 4 +- validators/__init__.py | 54 ++++-- validators/between.py | 6 +- validators/card.py | 18 +- validators/domain.py | 12 +- validators/email.py | 23 ++- validators/extremes.py | 2 + validators/hashes.py | 25 +-- validators/i18n/__init__.py | 2 +- validators/i18n/es.py | 25 +-- validators/i18n/fi.py | 19 ++- validators/iban.py | 10 +- validators/ip_address.py | 10 +- validators/length.py | 4 +- validators/mac_address.py | 2 +- validators/slug.py | 2 +- validators/truthy.py | 5 +- validators/url.py | 14 +- validators/utils.py | 24 +-- validators/uuid.py | 2 +- 49 files changed, 841 insertions(+), 795 deletions(-) delete mode 100644 .isort.cfg create mode 100644 .pre-commit-config.yaml create mode 100644 Makefile create mode 100644 setup.cfg diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 52591e45..00000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -known_first_party=sqlalchemy_utils,tests -line_length=79 -multi_line_output=3 -not_skip=__init__.py -order_by_type=false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..9b1f197c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +repos: +- repo: https://github.com/ambv/black + rev: stable + hooks: + - id: black + language_version: python3.8 + + +- 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 diff --git a/.travis.yml b/.travis.yml index 977df9ef..9c936244 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python matrix: include: - - python: 3.4 - python: 3.5 - python: 3.6 - python: 3.7 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..95a6f6aa --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +lint: + isort --diff validators tests + isort --check-only validators tests + + flake8 validators tests + +install: + pip install -e ".[test]" diff --git a/docs/conf.py b/docs/conf.py index 43717706..e74fd5b2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,50 +12,51 @@ # 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__ +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', - 'sphinx.ext.todo', - 'sphinx.ext.coverage', - 'sphinx.ext.pngmath', - 'sphinx.ext.mathjax', - 'sphinx.ext.ifconfig', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.pngmath", + "sphinx.ext.mathjax", + "sphinx.ext.ifconfig", + "sphinx.ext.viewcode", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'validators' -copyright = u'2013-2014, Konsta Vesterinen' +project = u"validators" +copyright = u"2013-2014, Konsta Vesterinen" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -68,168 +69,171 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ['_build'] +exclude_patterns = ["_build"] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'validatorsdoc' +htmlhelp_basename = "validatorsdoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'validators.tex', u'validators Documentation', - u'Konsta Vesterinen', 'manual'), + ( + "index", + "validators.tex", + u"validators Documentation", + u"Konsta Vesterinen", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -237,12 +241,11 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'validators', u'validators Documentation', - [u'Konsta Vesterinen'], 1) + ("index", "validators", u"validators Documentation", [u"Konsta Vesterinen"], 1) ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -251,23 +254,29 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'validators', u'validators Documentation', - u'Konsta Vesterinen', 'validators', 'One line description of project.', - 'Miscellaneous'), + ( + "index", + "validators", + u"validators Documentation", + u"Konsta Vesterinen", + "validators", + "One line description of project.", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} +intersphinx_mapping = {"http://docs.python.org/": None} diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..4332c7d7 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,17 @@ +[isort] +known_first_party=sqlalchemy_utils,tests +line_length=88 +multi_line_output=3 +order_by_type=false +include_trailing_comma=True + +[flake8] +ignore = D10,E203,E501,W503,E231,E265 +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 diff --git a/setup.py b/setup.py index c1a5b80f..a151d45c 100644 --- a/setup.py +++ b/setup.py @@ -6,18 +6,19 @@ 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__)) def get_version(): - filename = os.path.join(HERE, 'validators', '__init__.py') + filename = os.path.join(HERE, "validators", "__init__.py") + print(filename) with open(filename) as f: contents = f.read() pattern = r"^__version__ = '(.*?)'$" @@ -25,49 +26,45 @@ def get_version(): 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 = [ - 'six>=1.4.0', - 'decorator>=3.4.0', + "six>=1.4.0", + "decorator>=3.4.0", ] setup( - name='validators', + name="validators", version=get_version(), - url='https://github.com/kvesteri/validators', - license='MIT', - author='Konsta Vesterinen', - author_email='konsta@fastmonkeys.com', - description='Python Data Validation for Humans™.', + url="https://github.com/kvesteri/validators", + license="MIT", + author="Konsta Vesterinen", + author_email="konsta@fastmonkeys.com", + description="Python Data Validation for Humans™.", long_description=__doc__, - packages=find_packages('.', exclude=['tests', 'tests.*']), + packages=find_packages(".", exclude=["tests", "tests.*"]), zip_safe=False, include_package_data=True, - platforms='any', + platforms="any", install_requires=install_requires, build_requires=install_requires, extras_require=extras_require, classifiers=[ - 'Environment :: Web Environment', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', - 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - 'Topic :: Software Development :: Libraries :: Python Modules' + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Topic :: Internet :: WWW/HTTP :: Dynamic Content", + "Topic :: Software Development :: Libraries :: Python Modules", ], - python_requires='>=3.4' + python_requires=">=3.4", ) diff --git a/tests/i18n/test_es.py b/tests/i18n/test_es.py index 3d955c7b..4edb2b90 100644 --- a/tests/i18n/test_es.py +++ b/tests/i18n/test_es.py @@ -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) diff --git a/tests/i18n/test_fi.py b/tests/i18n/test_fi.py index b900bc4e..d2991b19 100644 --- a/tests/i18n/test_fi.py +++ b/tests/i18n/test_fi.py @@ -5,56 +5,60 @@ from validators.i18n.fi import fi_business_id, fi_ssn -@pytest.mark.parametrize(('value',), [ - ('2336509-6',), # Supercell - ('0112038-9',), # Fast Monkeys - ('2417581-7',), # Nokia -]) +@pytest.mark.parametrize( + ("value",), + [ + ("2336509-6",), # Supercell + ("0112038-9",), # Fast Monkeys + ("2417581-7",), # Nokia + ], +) def test_returns_true_on_valid_business_id(value): assert fi_business_id(value) -@pytest.mark.parametrize(('value',), [ - (None,), - ('',), - ('1233312312',), - ('1333333-8',), - ('1231233-9',), -]) +@pytest.mark.parametrize( + ("value",), [(None,), ("",), ("1233312312",), ("1333333-8",), ("1231233-9",),] +) def test_returns_failed_validation_on_invalid_business_id(value): assert isinstance(fi_business_id(value), ValidationFailure) -@pytest.mark.parametrize(('value',), [ - ('010190-002R',), - ('010101-0101',), - ('010101+0101',), - ('010101A0101',), - ('010190-900P',), -]) +@pytest.mark.parametrize( + ("value",), + [ + ("010190-002R",), + ("010101-0101",), + ("010101+0101",), + ("010101A0101",), + ("010190-900P",), + ], +) def test_returns_true_on_valid_ssn(value): assert fi_ssn(value) -@pytest.mark.parametrize(('value',), [ - (None,), - ('',), - ('010190-001P',), # Too low serial - ('010190-000N',), # Too low serial - ('000190-0023',), # Invalid day - ('010090-002X',), # Invalid month - ('010190-002r',), # Invalid checksum - ('101010-0102',), - ('10a010-0101',), - ('101010-0\xe401',), - ('101010b0101',) -]) +@pytest.mark.parametrize( + ("value",), + [ + (None,), + ("",), + ("010190-001P",), # Too low serial + ("010190-000N",), # Too low serial + ("000190-0023",), # Invalid day + ("010090-002X",), # Invalid month + ("010190-002r",), # Invalid checksum + ("101010-0102",), + ("10a010-0101",), + ("101010-0\xe401",), + ("101010b0101",), + ], +) def test_returns_failed_validation_on_invalid_ssn(value): assert isinstance(fi_ssn(value), ValidationFailure) def test_returns_failed_validation_on_temporal_ssn_when_not_allowed(): assert isinstance( - fi_ssn('010190-900P', allow_temporal_ssn=False), - ValidationFailure + fi_ssn("010190-900P", allow_temporal_ssn=False), ValidationFailure ) diff --git a/tests/test_between.py b/tests/test_between.py index 45f0eeeb..8a532ead 100644 --- a/tests/test_between.py +++ b/tests/test_between.py @@ -4,30 +4,23 @@ import validators -@pytest.mark.parametrize(('value', 'min', 'max'), [ - (12, 11, 13), - (12, None, 14), - (12, 11, None), - (12, 12, 12) -]) +@pytest.mark.parametrize( + ("value", "min", "max"), + [(12, 11, 13), (12, None, 14), (12, 11, None), (12, 12, 12)], +) def test_returns_true_on_valid_range(value, min, max): assert validators.between(value, min=min, max=max) -@pytest.mark.parametrize(('value', 'min', 'max'), [ - (12, 13, 12), - (12, None, None), -]) +@pytest.mark.parametrize(("value", "min", "max"), [(12, 13, 12), (12, None, None),]) def test_raises_assertion_error_for_invalid_args(value, min, max): with pytest.raises(AssertionError): assert validators.between(value, min=min, max=max) -@pytest.mark.parametrize(('value', 'min', 'max'), [ - (12, 13, 14), - (12, None, 11), - (12, 13, None) -]) +@pytest.mark.parametrize( + ("value", "min", "max"), [(12, 13, 14), (12, None, 11), (12, 13, None)] +) def test_returns_failed_validation_on_invalid_range(value, min, max): result = validators.between(value, min=min, max=max) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_card.py b/tests/test_card.py index d76dbcf2..6ac78648 100644 --- a/tests/test_card.py +++ b/tests/test_card.py @@ -10,35 +10,16 @@ mastercard, unionpay, ValidationFailure, - visa + visa, ) -visa_cards = [ - '4242424242424242', - '4000002760003184' -] -mastercard_cards = [ - '5555555555554444', - '2223003122003222' -] -amex_cards = [ - '378282246310005', - '371449635398431' -] -unionpay_cards = [ - '6200000000000005' -] -diners_cards = [ - '3056930009020004', - '36227206271667' -] -jcb_cards = [ - '3566002020360505' -] -discover_cards = [ - '6011111111111117', - '6011000990139424' -] +visa_cards = ["4242424242424242", "4000002760003184"] +mastercard_cards = ["5555555555554444", "2223003122003222"] +amex_cards = ["378282246310005", "371449635398431"] +unionpay_cards = ["6200000000000005"] +diners_cards = ["3056930009020004", "36227206271667"] +jcb_cards = ["3566002020360505"] +discover_cards = ["6011111111111117", "6011000990139424"] @pytest.mark.parametrize( @@ -55,16 +36,14 @@ def test_returns_true_on_valid_card_number(value): assert card_number(value) -@pytest.mark.parametrize('value', [ - '4242424242424240', - '4000002760003180', - '400000276000318X' -]) +@pytest.mark.parametrize( + "value", ["4242424242424240", "4000002760003180", "400000276000318X"] +) def test_returns_failed_on_valid_card_number(value): assert isinstance(card_number(value), ValidationFailure) -@pytest.mark.parametrize('value', visa_cards) +@pytest.mark.parametrize("value", visa_cards) def test_returns_true_on_valid_visa(value): assert visa(value) @@ -82,7 +61,7 @@ def test_returns_failed_on_valid_visa(value): assert isinstance(visa(value), ValidationFailure) -@pytest.mark.parametrize('value', mastercard_cards) +@pytest.mark.parametrize("value", mastercard_cards) def test_returns_true_on_valid_mastercard(value): assert mastercard(value) @@ -100,7 +79,7 @@ def test_returns_failed_on_valid_mastercard(value): assert isinstance(mastercard(value), ValidationFailure) -@pytest.mark.parametrize('value', amex_cards) +@pytest.mark.parametrize("value", amex_cards) def test_returns_true_on_valid_amex(value): assert amex(value) @@ -118,7 +97,7 @@ def test_returns_failed_on_valid_amex(value): assert isinstance(amex(value), ValidationFailure) -@pytest.mark.parametrize('value', unionpay_cards) +@pytest.mark.parametrize("value", unionpay_cards) def test_returns_true_on_valid_unionpay(value): assert unionpay(value) @@ -136,7 +115,7 @@ def test_returns_failed_on_valid_unionpay(value): assert isinstance(unionpay(value), ValidationFailure) -@pytest.mark.parametrize('value', diners_cards) +@pytest.mark.parametrize("value", diners_cards) def test_returns_true_on_valid_diners(value): assert diners(value) @@ -154,7 +133,7 @@ def test_returns_failed_on_valid_diners(value): assert isinstance(diners(value), ValidationFailure) -@pytest.mark.parametrize('value', jcb_cards) +@pytest.mark.parametrize("value", jcb_cards) def test_returns_true_on_valid_jcb(value): assert jcb(value) @@ -172,7 +151,7 @@ def test_returns_failed_on_valid_jcb(value): assert isinstance(jcb(value), ValidationFailure) -@pytest.mark.parametrize('value', discover_cards) +@pytest.mark.parametrize("value", discover_cards) def test_returns_true_on_valid_discover(value): assert discover(value) diff --git a/tests/test_domain.py b/tests/test_domain.py index f8fe35b3..82f1d916 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -4,39 +4,45 @@ from validators import domain, ValidationFailure -@pytest.mark.parametrize('value', [ - 'example.com', - 'xn----gtbspbbmkef.xn--p1ai', - 'underscore_subdomain.example.com', - 'something.versicherung', - 'someThing.versicherung', - '11.com', - '3.cn', - 'a.cn', - 'sub1.sub2.sample.co.uk', - 'somerandomexample.xn--fiqs8s', - 'kräuter.com', - 'über.com' -]) +@pytest.mark.parametrize( + "value", + [ + "example.com", + "xn----gtbspbbmkef.xn--p1ai", + "underscore_subdomain.example.com", + "something.versicherung", + "someThing.versicherung", + "11.com", + "3.cn", + "a.cn", + "sub1.sub2.sample.co.uk", + "somerandomexample.xn--fiqs8s", + "kräuter.com", + "über.com", + ], +) def test_returns_true_on_valid_domain(value): assert domain(value) -@pytest.mark.parametrize('value', [ - 'example.com/', - 'example.com:4444', - 'example.-com', - 'example.', - '-example.com', - 'example-.com', - '_example.com', - 'example_.com', - 'example', - 'a......b.com', - 'a.123', - '123.123', - '123.123.123', - '123.123.123.123' -]) +@pytest.mark.parametrize( + "value", + [ + "example.com/", + "example.com:4444", + "example.-com", + "example.", + "-example.com", + "example-.com", + "_example.com", + "example_.com", + "example", + "a......b.com", + "a.123", + "123.123", + "123.123.123", + "123.123.123.123", + ], +) def test_returns_failed_validation_on_invalid_domain(value): assert isinstance(domain(value), ValidationFailure) diff --git a/tests/test_email.py b/tests/test_email.py index 0b7f4e27..861f8ea8 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -4,42 +4,48 @@ from validators import email, ValidationFailure -@pytest.mark.parametrize(('value', 'whitelist'), [ - ('email@here.com', None), - ('weirder-email@here.and.there.com', None), - ('email@[127.0.0.1]', None), - ('example@valid-----hyphens.com', None), - ('example@valid-with-hyphens.com', None), - ('test@domain.with.idn.tld.उदाहरण.परीक्षा', None), - ('email@localhost', None), - ('email@localdomain', ['localdomain']), - ('"test@test"@example.com', None), - ('"\\\011"@here.com', None), -]) +@pytest.mark.parametrize( + ("value", "whitelist"), + [ + ("email@here.com", None), + ("weirder-email@here.and.there.com", None), + ("email@[127.0.0.1]", None), + ("example@valid-----hyphens.com", None), + ("example@valid-with-hyphens.com", None), + ("test@domain.with.idn.tld.उदाहरण.परीक्षा", None), + ("email@localhost", None), + ("email@localdomain", ["localdomain"]), + ('"test@test"@example.com', None), + ('"\\\011"@here.com', None), + ], +) def test_returns_true_on_valid_email(value, whitelist): assert email(value, whitelist=whitelist) -@pytest.mark.parametrize(('value',), [ - (None,), - ('',), - ('abc',), - ('abc@',), - ('abc@bar',), - ('a @x.cz',), - ('abc@.com',), - ('something@@somewhere.com',), - ('email@127.0.0.1',), - ('example@invalid-.com',), - ('example@-invalid.com',), - ('example@inv-.alid-.com',), - ('example@inv-.-alid.com',), - ( - 'john56789.john56789.john56789.john56789.john56789.john56789.john5' - '@example.com', - ), - # Quoted-string format (CR not allowed) - ('"\\\012"@here.com',), -]) +@pytest.mark.parametrize( + ("value",), + [ + (None,), + ("",), + ("abc",), + ("abc@",), + ("abc@bar",), + ("a @x.cz",), + ("abc@.com",), + ("something@@somewhere.com",), + ("email@127.0.0.1",), + ("example@invalid-.com",), + ("example@-invalid.com",), + ("example@inv-.alid-.com",), + ("example@inv-.-alid.com",), + ( + "john56789.john56789.john56789.john56789.john56789.john56789.john5" + "@example.com", + ), + # Quoted-string format (CR not allowed) + ('"\\\012"@here.com',), + ], +) def test_returns_failed_validation_on_invalid_email(value): assert isinstance(email(value), ValidationFailure) diff --git a/tests/test_extremes.py b/tests/test_extremes.py index d9f5023c..fab92b5f 100644 --- a/tests/test_extremes.py +++ b/tests/test_extremes.py @@ -4,12 +4,7 @@ from validators import Max, Min -@pytest.mark.parametrize(('value',), [ - (None,), - ('',), - (12,), - (Min,), -]) +@pytest.mark.parametrize(("value",), [(None,), ("",), (12,), (Min,),]) def test_max_is_greater_than_every_other_value(value): assert value < Max assert Max > value @@ -25,12 +20,7 @@ def test_other_comparison_methods_for_max(): assert not (Max != Max) -@pytest.mark.parametrize(('value',), [ - (None,), - ('',), - (12,), - (Max,), -]) +@pytest.mark.parametrize(("value",), [(None,), ("",), (12,), (Max,),]) def test_min_is_smaller_than_every_other_value(value): assert value > Min diff --git a/tests/test_iban.py b/tests/test_iban.py index 2dcca652..198a3820 100644 --- a/tests/test_iban.py +++ b/tests/test_iban.py @@ -4,18 +4,12 @@ import validators -@pytest.mark.parametrize('value', [ - 'GB82WEST12345698765432', - 'NO9386011117947' -]) +@pytest.mark.parametrize("value", ["GB82WEST12345698765432", "NO9386011117947"]) def test_returns_true_on_valid_iban(value): assert validators.iban(value) -@pytest.mark.parametrize('value', [ - 'GB81WEST12345698765432', - 'NO9186011117947' -]) +@pytest.mark.parametrize("value", ["GB81WEST12345698765432", "NO9186011117947"]) def test_returns_failed_validation_on_invalid_iban(value): result = validators.iban(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_ipv4.py b/tests/test_ipv4.py index 3dac98d8..4a506e1a 100644 --- a/tests/test_ipv4.py +++ b/tests/test_ipv4.py @@ -4,21 +4,17 @@ from validators import ipv4, ipv6, ValidationFailure -@pytest.mark.parametrize(('address',), [ - ('127.0.0.1',), - ('123.5.77.88',), - ('12.12.12.12',), -]) +@pytest.mark.parametrize( + ("address",), [("127.0.0.1",), ("123.5.77.88",), ("12.12.12.12",),] +) def test_returns_true_on_valid_ipv4_address(address): assert ipv4(address) assert not ipv6(address) -@pytest.mark.parametrize(('address',), [ - ('abc.0.0.1',), - ('1278.0.0.1',), - ('127.0.0.abc',), - ('900.200.100.75',), -]) +@pytest.mark.parametrize( + ("address",), + [("abc.0.0.1",), ("1278.0.0.1",), ("127.0.0.abc",), ("900.200.100.75",),], +) def test_returns_failed_validation_on_invalid_ipv4_address(address): assert isinstance(ipv4(address), ValidationFailure) diff --git a/tests/test_ipv4_cidr.py b/tests/test_ipv4_cidr.py index 3216a17a..6119cf5d 100644 --- a/tests/test_ipv4_cidr.py +++ b/tests/test_ipv4_cidr.py @@ -4,22 +4,17 @@ from validators import ipv4_cidr, ipv6_cidr, ValidationFailure -@pytest.mark.parametrize(('cidr',), [ - ('127.0.0.1/0',), - ('123.5.77.88/8',), - ('12.12.12.12/32',), -]) +@pytest.mark.parametrize( + ("cidr",), [("127.0.0.1/0",), ("123.5.77.88/8",), ("12.12.12.12/32",),] +) def test_returns_true_on_valid_ipv4_cidr(cidr): assert ipv4_cidr(cidr) assert not ipv6_cidr(cidr) -@pytest.mark.parametrize(('cidr',), [ - ('abc.0.0.1',), - ('1.1.1.1',), - ('1.1.1.1/-1',), - ('1.1.1.1/33',), - ('1.1.1.1/foo',), -]) +@pytest.mark.parametrize( + ("cidr",), + [("abc.0.0.1",), ("1.1.1.1",), ("1.1.1.1/-1",), ("1.1.1.1/33",), ("1.1.1.1/foo",),], +) def test_returns_failed_validation_on_invalid_ipv4_cidr(cidr): assert isinstance(ipv4_cidr(cidr), ValidationFailure) diff --git a/tests/test_ipv6.py b/tests/test_ipv6.py index 3f321404..25b0b7d8 100644 --- a/tests/test_ipv6.py +++ b/tests/test_ipv6.py @@ -4,23 +4,24 @@ from validators import ipv4, ipv6, ValidationFailure -@pytest.mark.parametrize(('address',), [ - ('::1',), - ('dead:beef:0:0:0:0:42:1',), - ('abcd:ef::42:1',), - ('0:0:0:0:0:ffff:1.2.3.4',), - ('::192.168.30.2',), -]) +@pytest.mark.parametrize( + ("address",), + [ + ("::1",), + ("dead:beef:0:0:0:0:42:1",), + ("abcd:ef::42:1",), + ("0:0:0:0:0:ffff:1.2.3.4",), + ("::192.168.30.2",), + ], +) def test_returns_true_on_valid_ipv6_address(address): assert ipv6(address) assert not ipv4(address) -@pytest.mark.parametrize(('address',), [ - ('abc.0.0.1',), - ('abcd:1234::123::1',), - ('1:2:3:4:5:6:7:8:9',), - ('abcd::1ffff',), -]) +@pytest.mark.parametrize( + ("address",), + [("abc.0.0.1",), ("abcd:1234::123::1",), ("1:2:3:4:5:6:7:8:9",), ("abcd::1ffff",),], +) def test_returns_failed_validation_on_invalid_ipv6_address(address): assert isinstance(ipv6(address), ValidationFailure) diff --git a/tests/test_ipv6_cidr.py b/tests/test_ipv6_cidr.py index 308390a9..69af24db 100644 --- a/tests/test_ipv6_cidr.py +++ b/tests/test_ipv6_cidr.py @@ -4,28 +4,34 @@ from validators import ipv4_cidr, ipv6_cidr, ValidationFailure -@pytest.mark.parametrize(('cidr',), [ - ('::1/0',), - ('dead:beef:0:0:0:0:42:1/8',), - ('abcd:ef::42:1/32',), - ('0:0:0:0:0:ffff:1.2.3.4/64',), - ('::192.168.30.2/128',), -]) +@pytest.mark.parametrize( + ("cidr",), + [ + ("::1/0",), + ("dead:beef:0:0:0:0:42:1/8",), + ("abcd:ef::42:1/32",), + ("0:0:0:0:0:ffff:1.2.3.4/64",), + ("::192.168.30.2/128",), + ], +) def test_returns_true_on_valid_ipv6_cidr(cidr): assert ipv6_cidr(cidr) assert not ipv4_cidr(cidr) -@pytest.mark.parametrize(('cidr',), [ - ('abc.0.0.1',), - ('abcd:1234::123::1',), - ('1:2:3:4:5:6:7:8:9',), - ('abcd::1ffff',), - ('1.1.1.1',), - ('::1',), - ('::1/129',), - ('::1/-1',), - ('::1/foo',), -]) +@pytest.mark.parametrize( + ("cidr",), + [ + ("abc.0.0.1",), + ("abcd:1234::123::1",), + ("1:2:3:4:5:6:7:8:9",), + ("abcd::1ffff",), + ("1.1.1.1",), + ("::1",), + ("::1/129",), + ("::1/-1",), + ("::1/foo",), + ], +) def test_returns_failed_validation_on_invalid_ipv6_cidr(cidr): assert isinstance(ipv6_cidr(cidr), ValidationFailure) diff --git a/tests/test_length.py b/tests/test_length.py index 86342f1e..3c2ef00e 100644 --- a/tests/test_length.py +++ b/tests/test_length.py @@ -4,34 +4,38 @@ import validators -@pytest.mark.parametrize(('value', 'min', 'max'), [ - ('password', 2, 10), - ('password', None, 10), - ('password', 2, None), - ('password', 8, 8) -]) +@pytest.mark.parametrize( + ("value", "min", "max"), + [ + ("password", 2, 10), + ("password", None, 10), + ("password", 2, None), + ("password", 8, 8), + ], +) def test_returns_true_on_valid_length(value, min, max): assert validators.length(value, min=min, max=max) -@pytest.mark.parametrize(('value', 'min', 'max'), [ - ('something', 13, 12), - ('something', -1, None), - ('something', -1, None), - ('something', -3, -2) -]) +@pytest.mark.parametrize( + ("value", "min", "max"), + [ + ("something", 13, 12), + ("something", -1, None), + ("something", -1, None), + ("something", -3, -2), + ], +) def test_raises_assertion_error_for_invalid_args(value, min, max): with pytest.raises(AssertionError): assert validators.length(value, min=min, max=max) -@pytest.mark.parametrize(('value', 'min', 'max'), [ - ('something', 13, 14), - ('something', None, 6), - ('something', 13, None) -]) +@pytest.mark.parametrize( + ("value", "min", "max"), + [("something", 13, 14), ("something", None, 6), ("something", 13, None)], +) def test_returns_failed_validation_on_invalid_range(value, min, max): assert isinstance( - validators.length(value, min=min, max=max), - validators.ValidationFailure + validators.length(value, min=min, max=max), validators.ValidationFailure ) diff --git a/tests/test_mac_address.py b/tests/test_mac_address.py index 756fa3ec..5350f6a7 100644 --- a/tests/test_mac_address.py +++ b/tests/test_mac_address.py @@ -4,18 +4,19 @@ from validators import mac_address, ValidationFailure -@pytest.mark.parametrize(('address',), [ - ('01:23:45:67:ab:CD',), -]) +@pytest.mark.parametrize(("address",), [("01:23:45:67:ab:CD",),]) def test_returns_true_on_valid_mac_address(address): assert mac_address(address) -@pytest.mark.parametrize(('address',), [ - ('00:00:00:00:00',), - ('01:23:45:67:89:',), - ('01:23:45:67:89:gh',), - ('123:23:45:67:89:00',), -]) +@pytest.mark.parametrize( + ("address",), + [ + ("00:00:00:00:00",), + ("01:23:45:67:89:",), + ("01:23:45:67:89:gh",), + ("123:23:45:67:89:00",), + ], +) def test_returns_failed_validation_on_invalid_mac_address(address): assert isinstance(mac_address(address), ValidationFailure) diff --git a/tests/test_md5.py b/tests/test_md5.py index 3efb1d69..75ef0a1b 100644 --- a/tests/test_md5.py +++ b/tests/test_md5.py @@ -4,19 +4,21 @@ import validators -@pytest.mark.parametrize('value', [ - 'd41d8cd98f00b204e9800998ecf8427e', - 'D41D8CD98F00B204E9800998ECF8427E' -]) +@pytest.mark.parametrize( + "value", ["d41d8cd98f00b204e9800998ecf8427e", "D41D8CD98F00B204E9800998ECF8427E"] +) def test_returns_true_on_valid_md5(value): assert validators.md5(value) -@pytest.mark.parametrize('value', [ - 'z41d8cd98f00b204e9800998ecf8427e', - 'z8cd98f00b204e9800998ecf8427e', - 'z4aaaa1d8cd98f00b204e9800998ecf8427e' -]) +@pytest.mark.parametrize( + "value", + [ + "z41d8cd98f00b204e9800998ecf8427e", + "z8cd98f00b204e9800998ecf8427e", + "z4aaaa1d8cd98f00b204e9800998ecf8427e", + ], +) def test_returns_failed_validation_on_invalid_md5(value): result = validators.md5(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_sha1.py b/tests/test_sha1.py index b729009a..104c46c7 100644 --- a/tests/test_sha1.py +++ b/tests/test_sha1.py @@ -4,19 +4,25 @@ import validators -@pytest.mark.parametrize('value', [ - 'da39a3ee5e6b4b0d3255bfef95601890afd80709', - 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709' -]) +@pytest.mark.parametrize( + "value", + [ + "da39a3ee5e6b4b0d3255bfef95601890afd80709", + "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", + ], +) def test_returns_true_on_valid_sha1(value): assert validators.sha1(value) -@pytest.mark.parametrize('value', [ - 'za39a3ee5e6b4b0d3255bfef95601890afd80709', - 'da39e5e6b4b0d3255bfef95601890afd80709', - 'daaaa39a3ee5e6b4b0d3255bfef95601890afd80709' -]) +@pytest.mark.parametrize( + "value", + [ + "za39a3ee5e6b4b0d3255bfef95601890afd80709", + "da39e5e6b4b0d3255bfef95601890afd80709", + "daaaa39a3ee5e6b4b0d3255bfef95601890afd80709", + ], +) def test_returns_failed_validation_on_invalid_sha1(value): result = validators.sha1(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_sha224.py b/tests/test_sha224.py index 225275b9..63b9376d 100644 --- a/tests/test_sha224.py +++ b/tests/test_sha224.py @@ -4,19 +4,25 @@ import validators -@pytest.mark.parametrize('value', [ - 'd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', - 'D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F' -]) +@pytest.mark.parametrize( + "value", + [ + "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + "D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F", + ], +) def test_returns_true_on_valid_sha224(value): assert validators.sha224(value) -@pytest.mark.parametrize('value', [ - 'z14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', - 'd028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', - 'daaa14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f' -]) +@pytest.mark.parametrize( + "value", + [ + "z14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + "d028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + "daaa14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + ], +) def test_returns_failed_validation_on_invalid_sha224(value): result = validators.sha224(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_sha256.py b/tests/test_sha256.py index b9c20776..20a74def 100644 --- a/tests/test_sha256.py +++ b/tests/test_sha256.py @@ -4,19 +4,25 @@ import validators -@pytest.mark.parametrize('value', [ - 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', - 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855' -]) +@pytest.mark.parametrize( + "value", + [ + "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", + ], +) def test_returns_true_on_valid_sha256(value): assert validators.sha256(value) -@pytest.mark.parametrize('value', [ - 'z3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', - 'ec44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', - 'eaaaa3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', -]) +@pytest.mark.parametrize( + "value", + [ + "z3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "ec44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "eaaaa3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + ], +) def test_returns_failed_validation_on_invalid_sha256(value): result = validators.sha256(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_sha512.py b/tests/test_sha512.py index 7a7aabba..4b553935 100644 --- a/tests/test_sha512.py +++ b/tests/test_sha512.py @@ -4,34 +4,40 @@ import validators -@pytest.mark.parametrize('value', [ - ( - 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d' - '13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' - ), - ( - 'CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D' - '13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E' - ) -]) +@pytest.mark.parametrize( + "value", + [ + ( + "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d" + "13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + ), + ( + "CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D" + "13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E" + ), + ], +) def test_returns_true_on_valid_sha512(value): assert validators.sha512(value) -@pytest.mark.parametrize('value', [ - ( - 'zf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d' - '13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' - ), - ( - 'cf8357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c' - '5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' - ), - ( - 'cf8aaaa3e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce4' - '7d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' - ) -]) +@pytest.mark.parametrize( + "value", + [ + ( + "zf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d" + "13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + ), + ( + "cf8357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c" + "5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + ), + ( + "cf8aaaa3e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce4" + "7d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + ), + ], +) def test_returns_failed_validation_on_invalid_sha512(value): result = validators.sha512(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_slug.py b/tests/test_slug.py index a42fe5f7..a96bba64 100644 --- a/tests/test_slug.py +++ b/tests/test_slug.py @@ -4,20 +4,13 @@ from validators import slug, ValidationFailure -@pytest.mark.parametrize('value', [ - '123-12312-asdasda', - '123____123', - 'dsadasd-dsadas', -]) +@pytest.mark.parametrize( + "value", ["123-12312-asdasda", "123____123", "dsadasd-dsadas",] +) def test_returns_true_on_valid_slug(value): assert slug(value) -@pytest.mark.parametrize('value', [ - 'some.slug', - '1231321%', - ' 21312', - '123asda&', -]) +@pytest.mark.parametrize("value", ["some.slug", "1231321%", " 21312", "123asda&",]) def test_returns_failed_validation_on_invalid_slug(value): assert isinstance(slug(value), ValidationFailure) diff --git a/tests/test_url.py b/tests/test_url.py index 8fcc67be..8b474df4 100644 --- a/tests/test_url.py +++ b/tests/test_url.py @@ -4,148 +4,159 @@ from validators import url, ValidationFailure -@pytest.mark.parametrize('address', [ - u'http://foobar.dk', - u'http://foobar.museum/foobar', - u'http://fo.com', - u'http://FOO.com', - u'http://foo.com/blah_blah', - u'http://foo.com/blah_blah/', - u'http://foo.com/blah_blah_(wikipedia)', - u'http://foo.com/blah_blah_(wikipedia)_(again)', - u'http://www.example.com/wpstyle/?p=364', - u'https://www.example.com/foo/?bar=baz&inga=42&quux', - u'https://www.example.com?bar=baz', - u'http://✪df.ws/123', - u'http://userid:password@example.com:8080', - u'http://userid:password@example.com:8080/', - u'http://userid@example.com', - u'http://userid@example.com/', - u'http://userid@example.com:8080', - u'http://userid@example.com:8080/', - u'http://userid:password@example.com', - u'http://userid:password@example.com/', - u'http://142.42.1.1/', - u'http://142.42.1.1:8080/', - u'http://➡.ws/䨹', - u'http://⌘.ws', - u'http://⌘.ws/', - u'http://foo.com/blah_(wikipedia)#cite-1', - u'http://foo.com/blah_(wikipedia)_blah#cite-1', - u'http://foo.com/unicode_(✪)_in_parens', - u'http://foo.com/(something)?after=parens', - u'http://☺.damowmow.com/', - u'http://code.google.com/events/#&product=browser', - u'http://j.mp', - u'ftp://foo.bar/baz', - u'http://foo.bar/?q=Test%20URL-encoded%20stuff', - u'http://مثال.إختبار', - u'http://例子.测试', - u'http://उदाहरण.परीक्षा', - u'http://www.😉.com', - u'http://😉.com/😁', - u'http://উদাহরণ.বাংলা', - u'http://xn--d5b6ci4b4b3a.xn--54b7fta0cc', - u'http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com', - u'http://1337.net', - u'http://a.b-c.de', - u'http://223.255.255.254', - u'http://10.1.1.0', - u'http://10.1.1.1', - u'http://10.1.1.254', - u'http://10.1.1.255', - u'http://127.0.0.1:8080', - u'http://127.0.10.150', - u'http://localhost', - u'http://localhost:8000', - u'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html', - u'http://[1080:0:0:0:8:800:200C:417A]/index.html', - u'http://[3ffe:2a00:100:7031::1]', - u'http://[1080::8:800:200C:417A]/foo', - u'http://[::192.9.5.5]/ipng', - u'http://[::FFFF:129.144.52.38]:80/index.html', - u'http://[2010:836B:4179::836B:4179]', -]) +@pytest.mark.parametrize( + "address", + [ + u"http://foobar.dk", + u"http://foobar.museum/foobar", + u"http://fo.com", + u"http://FOO.com", + u"http://foo.com/blah_blah", + u"http://foo.com/blah_blah/", + u"http://foo.com/blah_blah_(wikipedia)", + u"http://foo.com/blah_blah_(wikipedia)_(again)", + u"http://www.example.com/wpstyle/?p=364", + u"https://www.example.com/foo/?bar=baz&inga=42&quux", + u"https://www.example.com?bar=baz", + u"http://✪df.ws/123", + u"http://userid:password@example.com:8080", + u"http://userid:password@example.com:8080/", + u"http://userid@example.com", + u"http://userid@example.com/", + u"http://userid@example.com:8080", + u"http://userid@example.com:8080/", + u"http://userid:password@example.com", + u"http://userid:password@example.com/", + u"http://142.42.1.1/", + u"http://142.42.1.1:8080/", + u"http://➡.ws/䨹", + u"http://⌘.ws", + u"http://⌘.ws/", + u"http://foo.com/blah_(wikipedia)#cite-1", + u"http://foo.com/blah_(wikipedia)_blah#cite-1", + u"http://foo.com/unicode_(✪)_in_parens", + u"http://foo.com/(something)?after=parens", + u"http://☺.damowmow.com/", + u"http://code.google.com/events/#&product=browser", + u"http://j.mp", + u"ftp://foo.bar/baz", + u"http://foo.bar/?q=Test%20URL-encoded%20stuff", + u"http://مثال.إختبار", + u"http://例子.测试", + u"http://उदाहरण.परीक्षा", + u"http://www.😉.com", + u"http://😉.com/😁", + u"http://উদাহরণ.বাংলা", + u"http://xn--d5b6ci4b4b3a.xn--54b7fta0cc", + u"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", + u"http://1337.net", + u"http://a.b-c.de", + u"http://223.255.255.254", + u"http://10.1.1.0", + u"http://10.1.1.1", + u"http://10.1.1.254", + u"http://10.1.1.255", + u"http://127.0.0.1:8080", + u"http://127.0.10.150", + u"http://localhost", + u"http://localhost:8000", + u"http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", + u"http://[1080:0:0:0:8:800:200C:417A]/index.html", + u"http://[3ffe:2a00:100:7031::1]", + u"http://[1080::8:800:200C:417A]/foo", + u"http://[::192.9.5.5]/ipng", + u"http://[::FFFF:129.144.52.38]:80/index.html", + u"http://[2010:836B:4179::836B:4179]", + ], +) def test_returns_true_on_valid_url(address): assert url(address) -@pytest.mark.parametrize('address, public', [ - (u'http://foo.bar', True), - (u'http://username:password@example.com:4010/', False), - (u'http://username:password@112.168.10.10:4010/', True), - (u'http://username:password@192.168.10.10:4010/', False), - (u'http://10.0.10.1', False), - (u'http://127.0.0.1', False), -]) +@pytest.mark.parametrize( + "address, public", + [ + (u"http://foo.bar", True), + (u"http://username:password@example.com:4010/", False), + (u"http://username:password@112.168.10.10:4010/", True), + (u"http://username:password@192.168.10.10:4010/", False), + (u"http://10.0.10.1", False), + (u"http://127.0.0.1", False), + ], +) def test_returns_true_on_valid_public_url(address, public): assert url(address, public=public) -@pytest.mark.parametrize('address', [ - 'http://foobar', - 'foobar.dk', - 'http://127.0.0/asdf', - 'http://foobar.d', - 'http://foobar.12', - 'http://foobar', - 'htp://foobar.com', - 'http://foobar..com', - 'http://fo..com', - 'http://', - 'http://.', - 'http://..', - 'http://../', - 'http://?', - 'http://??', - 'http://??/', - 'http://#', - 'http://##', - 'http://##/', - 'http://foo.bar?q=Spaces should be encoded', - '//', - '//a', - '///a', - '///', - 'http:///a', - 'foo.com', - 'rdar://1234', - 'h://test', - 'http:// shouldfail.com', - ':// should fail', - 'http://foo.bar/foo(bar)baz quux', - 'ftps://foo.bar/', - 'http://-error-.invalid/', - 'http://a.b--c.de/', - 'http://-a.b.co', - 'http://a.b-.co', - 'http://0.0.0.0', - 'http://224.1.1.1', - 'http://1.1.1.1.1', - 'http://123.123.123', - 'http://3628126748', - 'http://.www.foo.bar/', - 'http://www.foo.bar./', - 'http://.www.foo.bar./', - 'http://127.12.0.260', - 'http://example.com/">user@example.com', - 'http://[2010:836B:4179::836B:4179', - 'http://2010:836B:4179::836B:4179', - 'http://2010:836B:4179::836B:4179:80/index.html', -]) +@pytest.mark.parametrize( + "address", + [ + "http://foobar", + "foobar.dk", + "http://127.0.0/asdf", + "http://foobar.d", + "http://foobar.12", + "http://foobar", + "htp://foobar.com", + "http://foobar..com", + "http://fo..com", + "http://", + "http://.", + "http://..", + "http://../", + "http://?", + "http://??", + "http://??/", + "http://#", + "http://##", + "http://##/", + "http://foo.bar?q=Spaces should be encoded", + "//", + "//a", + "///a", + "///", + "http:///a", + "foo.com", + "rdar://1234", + "h://test", + "http:// shouldfail.com", + ":// should fail", + "http://foo.bar/foo(bar)baz quux", + "ftps://foo.bar/", + "http://-error-.invalid/", + "http://a.b--c.de/", + "http://-a.b.co", + "http://a.b-.co", + "http://0.0.0.0", + "http://224.1.1.1", + "http://1.1.1.1.1", + "http://123.123.123", + "http://3628126748", + "http://.www.foo.bar/", + "http://www.foo.bar./", + "http://.www.foo.bar./", + "http://127.12.0.260", + 'http://example.com/">user@example.com', + "http://[2010:836B:4179::836B:4179", + "http://2010:836B:4179::836B:4179", + "http://2010:836B:4179::836B:4179:80/index.html", + ], +) def test_returns_failed_validation_on_invalid_url(address): assert isinstance(url(address), ValidationFailure) -@pytest.mark.parametrize('address, public', [ - (u'http://username:password@192.168.10.10:4010/', True), - (u'http://10.0.10.1', True), - (u'http://127.0.0.1', True), - (u'foo://127.0.0.1', True), - (u'http://username:password@127.0.0.1:8080', True), - (u'http://localhost', True), - (u'http://localhost:8000', True), - -]) +@pytest.mark.parametrize( + "address, public", + [ + (u"http://username:password@192.168.10.10:4010/", True), + (u"http://10.0.10.1", True), + (u"http://127.0.0.1", True), + (u"foo://127.0.0.1", True), + (u"http://username:password@127.0.0.1:8080", True), + (u"http://localhost", True), + (u"http://localhost:8000", True), + ], +) def test_returns_failed_validation_on_invalid_public_url(address, public): assert isinstance(url(address, public=public), ValidationFailure) diff --git a/tests/test_uuid.py b/tests/test_uuid.py index 42415c2a..22d5835d 100644 --- a/tests/test_uuid.py +++ b/tests/test_uuid.py @@ -4,18 +4,19 @@ from validators import uuid, ValidationFailure -@pytest.mark.parametrize(('value',), [ - ('2bc1c94f-0deb-43e9-92a1-4775189ec9f8',), -]) +@pytest.mark.parametrize(("value",), [("2bc1c94f-0deb-43e9-92a1-4775189ec9f8",),]) def test_returns_true_on_valid_mac_address(value): assert uuid(value) -@pytest.mark.parametrize(('value',), [ - ('2bc1c94f-deb-43e9-92a1-4775189ec9f8',), - ('2bc1c94f-0deb-43e9-92a1-4775189ec9f',), - ('gbc1c94f-0deb-43e9-92a1-4775189ec9f8',), - ('2bc1c94f 0deb-43e9-92a1-4775189ec9f8',), -]) +@pytest.mark.parametrize( + ("value",), + [ + ("2bc1c94f-deb-43e9-92a1-4775189ec9f8",), + ("2bc1c94f-0deb-43e9-92a1-4775189ec9f",), + ("gbc1c94f-0deb-43e9-92a1-4775189ec9f8",), + ("2bc1c94f 0deb-43e9-92a1-4775189ec9f8",), + ], +) def test_returns_failed_validation_on_invalid_mac_address(value): assert isinstance(uuid(value), ValidationFailure) diff --git a/tests/test_validation_failure.py b/tests/test_validation_failure.py index 0601aa6f..9bc6f937 100644 --- a/tests/test_validation_failure.py +++ b/tests/test_validation_failure.py @@ -2,9 +2,7 @@ import validators -obj_repr = ( - "ValidationFailure(func=between" -) +obj_repr = "ValidationFailure(func=between" class TestValidationFailure(object): diff --git a/validators/__init__.py b/validators/__init__.py index 24ba8911..6bee54dc 100644 --- a/validators/__init__.py +++ b/validators/__init__.py @@ -1,14 +1,5 @@ from .between import between -from .card import ( - amex, - card_number, - diners, - discover, - jcb, - mastercard, - unionpay, - visa -) +from .card import amex, card_number, diners, discover, jcb, mastercard, unionpay, visa from .domain import domain from .email import email from .extremes import Max, Min @@ -24,11 +15,40 @@ from .utils import ValidationFailure, validator from .uuid import uuid -__all__ = ('between', 'domain', 'email', 'Max', 'Min', 'md5', 'sha1', 'sha224', - 'sha256', 'sha512', 'fi_business_id', 'fi_ssn', 'iban', 'ipv4', - 'ipv4_cidr', 'ipv6', 'ipv6_cidr', 'length', 'mac_address', 'slug', - 'truthy', 'url', 'ValidationFailure', 'validator', 'uuid', - 'card_number', 'visa', 'mastercard', 'amex', 'unionpay', 'diners', - 'jcb', 'discover') +__all__ = ( + "between", + "domain", + "email", + "Max", + "Min", + "md5", + "sha1", + "sha224", + "sha256", + "sha512", + "fi_business_id", + "fi_ssn", + "iban", + "ipv4", + "ipv4_cidr", + "ipv6", + "ipv6_cidr", + "length", + "mac_address", + "slug", + "truthy", + "url", + "ValidationFailure", + "validator", + "uuid", + "card_number", + "visa", + "mastercard", + "amex", + "unionpay", + "diners", + "jcb", + "discover", +) -__version__ = '0.17.1' +__version__ = "0.17.1" diff --git a/validators/between.py b/validators/between.py index 46f223c9..a381d719 100644 --- a/validators/between.py +++ b/validators/between.py @@ -44,9 +44,7 @@ def between(value, min=None, max=None): .. versionadded:: 0.2 """ if min is None and max is None: - raise AssertionError( - 'At least one of `min` or `max` must be specified.' - ) + raise AssertionError("At least one of `min` or `max` must be specified.") if min is None: min = Min if max is None: @@ -56,6 +54,6 @@ def between(value, min=None, max=None): except TypeError: min_gt_max = max < min if min_gt_max: - raise AssertionError('`min` cannot be more than `max`.') + raise AssertionError("`min` cannot be more than `max`.") return min <= value and max >= value diff --git a/validators/card.py b/validators/card.py index 8b8cbeea..0fe0d95d 100644 --- a/validators/card.py +++ b/validators/card.py @@ -51,7 +51,7 @@ def visa(value): :param value: Visa card number string to validate """ - pattern = re.compile(r'^4') + pattern = re.compile(r"^4") return card_number(value) and len(value) == 16 and pattern.match(value) @@ -72,7 +72,7 @@ def mastercard(value): :param value: Mastercard card number string to validate """ - pattern = re.compile(r'^(51|52|53|54|55|22|23|24|25|26|27)') + pattern = re.compile(r"^(51|52|53|54|55|22|23|24|25|26|27)") return card_number(value) and len(value) == 16 and pattern.match(value) @@ -93,7 +93,7 @@ def amex(value): :param value: American Express card number string to validate """ - pattern = re.compile(r'^(34|37)') + pattern = re.compile(r"^(34|37)") return card_number(value) and len(value) == 15 and pattern.match(value) @@ -114,7 +114,7 @@ def unionpay(value): :param value: UnionPay card number string to validate """ - pattern = re.compile(r'^62') + pattern = re.compile(r"^62") return card_number(value) and len(value) == 16 and pattern.match(value) @@ -135,10 +135,8 @@ def diners(value): :param value: Diners Club card number string to validate """ - pattern = re.compile(r'^(30|36|38|39)') - return ( - card_number(value) and len(value) in [14, 16] and pattern.match(value) - ) + pattern = re.compile(r"^(30|36|38|39)") + return card_number(value) and len(value) in [14, 16] and pattern.match(value) @validator @@ -158,7 +156,7 @@ def jcb(value): :param value: JCB card number string to validate """ - pattern = re.compile(r'^35') + pattern = re.compile(r"^35") return card_number(value) and len(value) == 16 and pattern.match(value) @@ -179,5 +177,5 @@ def discover(value): :param value: Discover card number string to validate """ - pattern = re.compile(r'^(60|64|65)') + pattern = re.compile(r"^(60|64|65)") return card_number(value) and len(value) == 16 and pattern.match(value) diff --git a/validators/domain.py b/validators/domain.py index 1c1ce232..52effb43 100644 --- a/validators/domain.py +++ b/validators/domain.py @@ -11,14 +11,14 @@ text_type = unicode pattern = re.compile( - r'^(?:[a-zA-Z0-9]' # First character of the domain - r'(?:[a-zA-Z0-9-_]{0,61}[A-Za-z0-9])?\.)' # Sub domain + hostname - r'+[A-Za-z0-9][A-Za-z0-9-_]{0,61}' # First 61 characters of the gTLD - r'[A-Za-z]$' # Last character of the gTLD + r"^(?:[a-zA-Z0-9]" # First character of the domain + r"(?:[a-zA-Z0-9-_]{0,61}[A-Za-z0-9])?\.)" # Sub domain + hostname + r"+[A-Za-z0-9][A-Za-z0-9-_]{0,61}" # First 61 characters of the gTLD + r"[A-Za-z]$" # Last character of the gTLD ) -def to_unicode(obj, charset='utf-8', errors='strict'): +def to_unicode(obj, charset="utf-8", errors="strict"): if obj is None: return None if not isinstance(obj, bytes): @@ -57,6 +57,6 @@ def domain(value): :param value: domain string to validate """ try: - return pattern.match(to_unicode(value).encode('idna').decode('ascii')) + return pattern.match(to_unicode(value).encode("idna").decode("ascii")) except (UnicodeError, AttributeError): return False diff --git a/validators/email.py b/validators/email.py index 229c8e46..87cf04ee 100644 --- a/validators/email.py +++ b/validators/email.py @@ -4,22 +4,21 @@ user_regex = re.compile( # dot-atom - r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+" - r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" + r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+" r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" # quoted-string r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|' r"""\\[\001-\011\013\014\016-\177])*"$)""", - re.IGNORECASE + re.IGNORECASE, ) domain_regex = re.compile( # domain - r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' - r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)' + r"(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+" + r"(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)" # literal form, ipv4 address (SMTP 4.1.3) - r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' - r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$', - re.IGNORECASE) -domain_whitelist = ['localhost'] + r"|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)" r"(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$", + re.IGNORECASE, +) +domain_whitelist = ["localhost"] @validator @@ -54,10 +53,10 @@ def email(value, whitelist=None): if whitelist is None: whitelist = domain_whitelist - if not value or '@' not in value: + if not value or "@" not in value: return False - user_part, domain_part = value.rsplit('@', 1) + user_part, domain_part = value.rsplit("@", 1) if not user_regex.match(user_part): return False @@ -68,7 +67,7 @@ def email(value, whitelist=None): if domain_part not in whitelist and not domain_regex.match(domain_part): # Try for possible IDN domain-part try: - domain_part = domain_part.encode('idna').decode('ascii') + domain_part = domain_part.encode("idna").decode("ascii") return domain_regex.match(domain_part) except UnicodeError: return False diff --git a/validators/extremes.py b/validators/extremes.py index 43d168a7..b5b5e040 100644 --- a/validators/extremes.py +++ b/validators/extremes.py @@ -23,6 +23,7 @@ class Min(object): .. versionadded:: 0.2 """ + def __lt__(self, other): if other is Min: return False @@ -51,6 +52,7 @@ class Max(object): .. versionadded:: 0.2 """ + def __gt__(self, other): if other is Max: return False diff --git a/validators/hashes.py b/validators/hashes.py index 4db7f78e..5c45f475 100644 --- a/validators/hashes.py +++ b/validators/hashes.py @@ -2,26 +2,11 @@ from .utils import validator -md5_regex = re.compile( - r"^[0-9a-f]{32}$", - re.IGNORECASE -) -sha1_regex = re.compile( - r"^[0-9a-f]{40}$", - re.IGNORECASE -) -sha224_regex = re.compile( - r"^[0-9a-f]{56}$", - re.IGNORECASE -) -sha256_regex = re.compile( - r"^[0-9a-f]{64}$", - re.IGNORECASE -) -sha512_regex = re.compile( - r"^[0-9a-f]{128}$", - re.IGNORECASE -) +md5_regex = re.compile(r"^[0-9a-f]{32}$", re.IGNORECASE) +sha1_regex = re.compile(r"^[0-9a-f]{40}$", re.IGNORECASE) +sha224_regex = re.compile(r"^[0-9a-f]{56}$", re.IGNORECASE) +sha256_regex = re.compile(r"^[0-9a-f]{64}$", re.IGNORECASE) +sha512_regex = re.compile(r"^[0-9a-f]{128}$", re.IGNORECASE) @validator diff --git a/validators/i18n/__init__.py b/validators/i18n/__init__.py index 12775c6c..d651de88 100644 --- a/validators/i18n/__init__.py +++ b/validators/i18n/__init__.py @@ -1,4 +1,4 @@ # TODO: remove, let the user import it if they really want it from .fi import fi_business_id, fi_ssn # noqa -__all__ = ('fi_business_id', 'fi_ssn') +__all__ = ("fi_business_id", "fi_ssn") diff --git a/validators/i18n/es.py b/validators/i18n/es.py index ed2e2a63..965867db 100644 --- a/validators/i18n/es.py +++ b/validators/i18n/es.py @@ -1,7 +1,12 @@ # -*- coding: utf-8 -*- from validators.utils import validator -__all__ = ('es_cif', 'es_nif', 'es_nie', 'es_doi',) +__all__ = ( + "es_cif", + "es_nif", + "es_nie", + "es_doi", +) def nif_nie_validation(doi, number_by_letter, special_cases): @@ -14,7 +19,7 @@ def nif_nie_validation(doi, number_by_letter, special_cases): if doi in special_cases: return False - table = 'TRWAGMYFPDXBNJZSQVHLCKE' + table = "TRWAGMYFPDXBNJZSQVHLCKE" if len(doi) != 9: return False @@ -66,7 +71,7 @@ def es_cif(doi): if len(doi) != 9: return False - table = 'JABCDEFGHI' + table = "JABCDEFGHI" first_chr = doi[0] doi_body = doi[1:8] control = doi[8] @@ -86,11 +91,11 @@ def es_cif(doi): res = (10 - (even_result + odd_result) % 10) % 10 - if first_chr in 'ABEH': # Number type + if first_chr in "ABEH": # Number type return str(res) == control - elif first_chr in 'PSQW': # Letter type + elif first_chr in "PSQW": # Letter type return table[res] == control - elif first_chr not in 'CDFGJNRUV': + elif first_chr not in "CDFGJNRUV": return False return control == str(res) or control == table[res] @@ -125,8 +130,8 @@ def es_nif(doi): :param doi: DOI to validate """ - number_by_letter = {'L': '0', 'M': '0', 'K': '0'} - special_cases = ['X0000000T', '00000000T', '00000001R'] + number_by_letter = {"L": "0", "M": "0", "K": "0"} + special_cases = ["X0000000T", "00000000T", "00000001R"] return nif_nie_validation(doi, number_by_letter, special_cases) @@ -159,8 +164,8 @@ def es_nie(doi): :param doi: DOI to validate """ - number_by_letter = {'X': '0', 'Y': '1', 'Z': '2'} - special_cases = ['X0000000T'] + number_by_letter = {"X": "0", "Y": "1", "Z": "2"} + special_cases = ["X0000000T"] # NIE must must start with X Y or Z if not doi or doi[0] not in number_by_letter.keys(): diff --git a/validators/i18n/fi.py b/validators/i18n/fi.py index 2e5eb578..59ffc3dc 100644 --- a/validators/i18n/fi.py +++ b/validators/i18n/fi.py @@ -2,8 +2,8 @@ from validators.utils import validator -business_id_pattern = re.compile(r'^[0-9]{7}-[0-9]$') -ssn_checkmarks = '0123456789ABCDEFHJKLMNPRSTUVWXY' +business_id_pattern = re.compile(r"^[0-9]{7}-[0-9]$") +ssn_checkmarks = "0123456789ABCDEFHJKLMNPRSTUVWXY" ssn_pattern = re.compile( r"""^ (?P(0[1-9]|[1-2]\d|3[01]) @@ -11,8 +11,10 @@ (\d{{2}})) [A+-] (?P(\d{{3}})) - (?P[{checkmarks}])$""".format(checkmarks=ssn_checkmarks), - re.VERBOSE + (?P[{checkmarks}])$""".format( + checkmarks=ssn_checkmarks + ), + re.VERBOSE, ) @@ -85,10 +87,9 @@ def fi_ssn(ssn, allow_temporal_ssn=True): if not result: return False gd = result.groupdict() - checksum = int(gd['date'] + gd['serial']) + checksum = int(gd["date"] + gd["serial"]) return ( - int(gd['serial']) >= 2 and - (allow_temporal_ssn or int(gd['serial']) <= 899) and - ssn_checkmarks[checksum % len(ssn_checkmarks)] == - gd['checksum'] + int(gd["serial"]) >= 2 + and (allow_temporal_ssn or int(gd["serial"]) <= 899) + and ssn_checkmarks[checksum % len(ssn_checkmarks)] == gd["checksum"] ) diff --git a/validators/iban.py b/validators/iban.py index 7413d127..bdf5da4a 100644 --- a/validators/iban.py +++ b/validators/iban.py @@ -2,9 +2,7 @@ from .utils import validator -regex = ( - r'^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$' -) +regex = r"^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$" pattern = re.compile(regex) @@ -14,7 +12,7 @@ def char_value(char): if char.isdigit(): return int(char) else: - return 10 + ord(char) - ord('A') + return 10 + ord(char) - ord("A") def modcheck(value): @@ -25,8 +23,8 @@ def modcheck(value): # convert letters to numbers converted = [char_value(char) for char in rearranged] # interpret as integer - integerized = int(''.join([str(i) for i in converted])) - return (integerized % 97 == 1) + integerized = int("".join([str(i) for i in converted])) + return integerized % 97 == 1 @validator diff --git a/validators/ip_address.py b/validators/ip_address.py index ba36cdc6..072f20ed 100644 --- a/validators/ip_address.py +++ b/validators/ip_address.py @@ -23,7 +23,7 @@ def ipv4(value): :param value: IP address string to validate """ - groups = value.split('.') + groups = value.split(".") if len(groups) != 4 or any(not x.isdigit() for x in groups): return False return all(0 <= int(part) < 256 for part in groups) @@ -46,7 +46,7 @@ def ipv4_cidr(value): ValidationFailure(func=ipv4_cidr, args={'value': '1.1.1.1'}) """ try: - prefix, suffix = value.split('/', 2) + prefix, suffix = value.split("/", 2) except ValueError: return False if not ipv4(prefix) or not suffix.isdigit(): @@ -83,10 +83,10 @@ def ipv6(value): :param value: IP address string to validate """ - ipv6_groups = value.split(':') + ipv6_groups = value.split(":") if len(ipv6_groups) == 1: return False - ipv4_groups = ipv6_groups[-1].split('.') + ipv4_groups = ipv6_groups[-1].split(".") if len(ipv4_groups) > 1: if not ipv4(ipv6_groups[-1]): @@ -136,7 +136,7 @@ def ipv6_cidr(value): ValidationFailure(func=ipv6_cidr, args={'value': '::1'}) """ try: - prefix, suffix = value.split('/', 2) + prefix, suffix = value.split("/", 2) except ValueError: return False if not ipv6(prefix) or not suffix.isdigit(): diff --git a/validators/length.py b/validators/length.py index d0f91fd3..00036c64 100644 --- a/validators/length.py +++ b/validators/length.py @@ -31,7 +31,5 @@ def length(value, min=None, max=None): .. versionadded:: 0.2 """ if (min is not None and min < 0) or (max is not None and max < 0): - raise AssertionError( - '`min` and `max` need to be greater than zero.' - ) + raise AssertionError("`min` and `max` need to be greater than zero.") return between(len(value), min=min, max=max) diff --git a/validators/mac_address.py b/validators/mac_address.py index bdb19947..64eecab6 100644 --- a/validators/mac_address.py +++ b/validators/mac_address.py @@ -2,7 +2,7 @@ from .utils import validator -pattern = re.compile(r'^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$') +pattern = re.compile(r"^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$") @validator diff --git a/validators/slug.py b/validators/slug.py index 83bfd4b1..33c818e3 100644 --- a/validators/slug.py +++ b/validators/slug.py @@ -2,7 +2,7 @@ from .utils import validator -slug_regex = re.compile(r'^[-a-zA-Z0-9_]+$') +slug_regex = re.compile(r"^[-a-zA-Z0-9_]+$") @validator diff --git a/validators/truthy.py b/validators/truthy.py index 2744bd5b..f23bbe60 100644 --- a/validators/truthy.py +++ b/validators/truthy.py @@ -35,7 +35,4 @@ def truthy(value): .. versionadded:: 0.2 """ - return ( - value and - (not isinstance(value, six.string_types) or value.strip()) - ) + return value and (not isinstance(value, six.string_types) or value.strip()) diff --git a/validators/url.py b/validators/url.py index fe2cbf53..c430d2e5 100644 --- a/validators/url.py +++ b/validators/url.py @@ -21,9 +21,7 @@ r"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + r"))" r"|" # private & local hosts - r"(?P" - r"(?:localhost))" - r"|" + r"(?P" r"(?:localhost))" r"|" # IP address dotted notation octets # excludes loopback network 0.0.0.0 # excludes reserved space >= 224.0.0.0 @@ -66,8 +64,7 @@ r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}" # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 # (IPv4-Embedded IPv6 Address) - r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" - r")\]|" + r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" r")\]|" # host name r"(?:(?:(?:xn--)|[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]-?)*" r"[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]+)" @@ -85,9 +82,8 @@ # query string r"(?:\?\S*)?" # fragment - r"(?:#\S*)?" - r"$", - re.UNICODE | re.IGNORECASE + r"(?:#\S*)?" r"$", + re.UNICODE | re.IGNORECASE, ) pattern = re.compile(regex) @@ -150,5 +146,5 @@ def url(value, public=False): return result return result and not any( - (result.groupdict().get(key) for key in ('private_ip', 'private_host')) + (result.groupdict().get(key) for key in ("private_ip", "private_host")) ) diff --git a/validators/utils.py b/validators/utils.py index 0d2d9714..8339186e 100644 --- a/validators/utils.py +++ b/validators/utils.py @@ -12,11 +12,9 @@ def __init__(self, func, args): self.__dict__.update(args) def __repr__(self): - return u'ValidationFailure(func={func}, args={args})'.format( + return u"ValidationFailure(func={func}, args={args})".format( func=self.func.__name__, - args=dict( - [(k, v) for (k, v) in self.__dict__.items() if k != 'func'] - ) + args=dict([(k, v) for (k, v) in self.__dict__.items() if k != "func"]), ) def __str__(self): @@ -43,17 +41,9 @@ def func_args_as_dict(func, args, kwargs): _getargspec = inspect.getfullargspec arg_names = list( - OrderedDict.fromkeys( - itertools.chain( - _getargspec(func)[0], - kwargs.keys() - ) - ) - ) - return OrderedDict( - list(six.moves.zip(arg_names, args)) + - list(kwargs.items()) + OrderedDict.fromkeys(itertools.chain(_getargspec(func)[0], kwargs.keys())) ) + return OrderedDict(list(six.moves.zip(arg_names, args)) + list(kwargs.items())) def validator(func, *args, **kwargs): @@ -79,11 +69,11 @@ def validator(func, *args, **kwargs): :param args: positional function arguments :param kwargs: key value function arguments """ + def wrapper(func, *args, **kwargs): value = func(*args, **kwargs) if not value: - return ValidationFailure( - func, func_args_as_dict(func, args, kwargs) - ) + return ValidationFailure(func, func_args_as_dict(func, args, kwargs)) return True + return decorator(wrapper, func) diff --git a/validators/uuid.py b/validators/uuid.py index f073b8d0..75fe8548 100644 --- a/validators/uuid.py +++ b/validators/uuid.py @@ -2,7 +2,7 @@ from .utils import validator -pattern = re.compile(r'^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') +pattern = re.compile(r"^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$") @validator From fa6a72966a8da76e0ab04b83e8893551a15e74e9 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:24:03 +0200 Subject: [PATCH 02/11] moved version info to setup.py --- setup.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/setup.py b/setup.py index a151d45c..5af113a7 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,6 @@ """ import os -import re import sys from setuptools import find_packages, setup @@ -16,15 +15,6 @@ HERE = os.path.dirname(os.path.abspath(__file__)) -def get_version(): - filename = os.path.join(HERE, "validators", "__init__.py") - print(filename) - with open(filename) as f: - contents = f.read() - 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", "pre-commit",], } @@ -36,7 +26,7 @@ def get_version(): setup( name="validators", - version=get_version(), + version="0.18.0", url="https://github.com/kvesteri/validators", license="MIT", author="Konsta Vesterinen", From 6d180c40f7f4481a28d2b507728f479df1019a05 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:32:37 +0200 Subject: [PATCH 03/11] :white_check_mark: fix btc_address test --- .travis.yml | 7 +++---- Makefile | 3 +++ validators/__init__.py | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c936244..5e70ebcd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,8 +8,7 @@ matrix: 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 diff --git a/Makefile b/Makefile index 95a6f6aa..026c22d1 100644 --- a/Makefile +++ b/Makefile @@ -6,3 +6,6 @@ lint: install: pip install -e ".[test]" + +test: + py.test --doctest-glob="*.rst" --doctest-modules --ignore=setup.py diff --git a/validators/__init__.py b/validators/__init__.py index d1054644..2f67e592 100644 --- a/validators/__init__.py +++ b/validators/__init__.py @@ -1,4 +1,5 @@ from .between import between +from .btc_address import btc_address from .card import amex, card_number, diners, discover, jcb, mastercard, unionpay, visa from .domain import domain from .email import email @@ -49,6 +50,7 @@ "diners", "jcb", "discover", + "btc_address", ) __version__ = "0.18.0" From e83db0baab58468e115fad19ea84ac3c91301628 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:43:07 +0200 Subject: [PATCH 04/11] :pencil: add make commands in readme --- README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.rst b/README.rst index 32f57ca4..d677643f 100644 --- a/README.rst +++ b/README.rst @@ -18,6 +18,15 @@ schema. True +Development +----------- + +To install the package for development use :bash:`make install`, to run tests use :bash:`make test` and finally to run check linting run :bash:`make lint`. + +Pre-commit hooks are run as soon as you commit something. + +To run pre-commit hooks manually :bash:`pre-commit run --all-files`. + Resources --------- From deb6411db74ddf829584231b05195f8eb6edfdf9 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:45:17 +0200 Subject: [PATCH 05/11] :fire: remove black from pre-commit yaml --- .pre-commit-config.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b1f197c..a9421a8f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,4 @@ repos: -- repo: https://github.com/ambv/black - rev: stable - hooks: - - id: black - language_version: python3.8 - - - repo: https://gitlab.com/pycqa/flake8 rev: 3.7.9 hooks: From 125e35610cd2a78fdf3f5b95c5b0f4f108788ad0 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:53:53 +0200 Subject: [PATCH 06/11] :pencil: fix/readme --- README.rst | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index d677643f..863fb47d 100644 --- a/README.rst +++ b/README.rst @@ -21,11 +21,25 @@ schema. Development ----------- -To install the package for development use :bash:`make install`, to run tests use :bash:`make test` and finally to run check linting run :bash:`make lint`. +To install the package for development use `make install`, to run tests use :bash:`make test` and finally to run check linting run :bash:`make lint`. + +.. 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 :bash:`pre-commit run --all-files`. +To run pre-commit hooks manually + +.. code-block:: bash + + pre-commit run --all-files Resources --------- From 5ef74dcaa1ac1250958976aaa441cda4f5715a5e Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:55:38 +0200 Subject: [PATCH 07/11] :fire: fix/readme, remove previous commands --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 863fb47d..7eaab956 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ schema. Development ----------- -To install the package for development use `make install`, to run tests use :bash:`make test` and finally to run check linting run :bash:`make lint`. +To install the package for development use the following commands, .. code-block:: bash From 22f83f27722c716bffac504e6b6e1c05409a7d60 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Tue, 25 Aug 2020 11:00:08 +0200 Subject: [PATCH 08/11] :art: Changed double quoutes to single quotes --- docs/conf.py | 162 +++++++++--------- setup.cfg | 2 +- tests/i18n/test_es.py | 116 ++++++------- tests/i18n/test_fi.py | 46 +++--- tests/test_between.py | 6 +- tests/test_card.py | 46 +++--- tests/test_domain.py | 56 +++---- tests/test_email.py | 48 +++--- tests/test_extremes.py | 4 +- tests/test_iban.py | 4 +- tests/test_ipv4.py | 6 +- tests/test_ipv4_cidr.py | 6 +- tests/test_ipv6.py | 16 +- tests/test_ipv6_cidr.py | 32 ++-- tests/test_length.py | 24 +-- tests/test_mac_address.py | 12 +- tests/test_md5.py | 10 +- tests/test_sha1.py | 14 +- tests/test_sha224.py | 14 +- tests/test_sha256.py | 14 +- tests/test_sha512.py | 24 +-- tests/test_slug.py | 4 +- tests/test_url.py | 273 +++++++++++++++---------------- tests/test_uuid.py | 12 +- tests/test_validation_failure.py | 2 +- validators/__init__.py | 70 ++++---- validators/between.py | 4 +- validators/card.py | 14 +- validators/domain.py | 12 +- validators/email.py | 23 +-- validators/extremes.py | 2 - validators/hashes.py | 25 ++- validators/i18n/__init__.py | 2 +- validators/i18n/es.py | 25 ++- validators/i18n/fi.py | 19 +-- validators/iban.py | 10 +- validators/ip_address.py | 10 +- validators/length.py | 4 +- validators/mac_address.py | 2 +- validators/slug.py | 2 +- validators/truthy.py | 5 +- validators/url.py | 14 +- validators/utils.py | 24 ++- validators/uuid.py | 2 +- 44 files changed, 616 insertions(+), 606 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e74fd5b2..ec0f32aa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,43 +20,43 @@ # 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("..")) +sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -# needs_sphinx = '1.0' +#needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.doctest", - "sphinx.ext.intersphinx", - "sphinx.ext.todo", - "sphinx.ext.coverage", - "sphinx.ext.pngmath", - "sphinx.ext.mathjax", - "sphinx.ext.ifconfig", - "sphinx.ext.viewcode", + 'sphinx.ext.autodoc', + 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', + 'sphinx.ext.todo', + 'sphinx.ext.coverage', + 'sphinx.ext.pngmath', + 'sphinx.ext.mathjax', + 'sphinx.ext.ifconfig', + 'sphinx.ext.viewcode', ] # Add any paths that contain templates here, relative to this directory. -templates_path = ["_templates"] +templates_path = ['_templates'] # The suffix of source filenames. -source_suffix = ".rst" +source_suffix = '.rst' # The encoding of source files. -# source_encoding = 'utf-8-sig' +#source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = "index" +master_doc = 'index' # General information about the project. -project = u"validators" -copyright = u"2013-2014, Konsta Vesterinen" +project = u'validators' +copyright = u'2013-2014, Konsta Vesterinen' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -69,171 +69,168 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -# language = None +#language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -# today = '' +#today = '' # Else, today_fmt is used as the format for a strftime call. -# today_fmt = '%B %d, %Y' +#today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. -exclude_patterns = ["_build"] +exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all # documents. -# default_role = None +#default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -# add_function_parentheses = True +#add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -# add_module_names = True +#add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -# show_authors = False +#show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = "sphinx" +pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. -# modindex_common_prefix = [] +#modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -# keep_warnings = False +#keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = "default" +html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -# html_theme_options = {} +#html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -# html_theme_path = [] +#html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -# html_title = None +#html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -# html_short_title = None +#html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -# html_logo = None +#html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -# html_favicon = None +#html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -# html_extra_path = [] +#html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -# html_last_updated_fmt = '%b %d, %Y' +#html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -# html_use_smartypants = True +#html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -# html_sidebars = {} +#html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -# html_additional_pages = {} +#html_additional_pages = {} # If false, no module index is generated. -# html_domain_indices = True +#html_domain_indices = True # If false, no index is generated. -# html_use_index = True +#html_use_index = True # If true, the index is split into individual pages for each letter. -# html_split_index = False +#html_split_index = False # If true, links to the reST sources are added to the pages. -# html_show_sourcelink = True +#html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -# html_show_sphinx = True +#html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -# html_show_copyright = True +#html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -# html_use_opensearch = '' +#html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -# html_file_suffix = None +#html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = "validatorsdoc" +htmlhelp_basename = 'validatorsdoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - #'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). - #'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. - #'preamble': '', +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ( - "index", - "validators.tex", - u"validators Documentation", - u"Konsta Vesterinen", - "manual", - ), + ('index', 'validators.tex', u'validators Documentation', + u'Konsta Vesterinen', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -# latex_logo = None +#latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -# latex_use_parts = False +#latex_use_parts = False # If true, show page references after internal links. -# latex_show_pagerefs = False +#latex_show_pagerefs = False # If true, show URL addresses after external links. -# latex_show_urls = False +#latex_show_urls = False # Documents to append as an appendix to all manuals. -# latex_appendices = [] +#latex_appendices = [] # If false, no module index is generated. -# latex_domain_indices = True +#latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -241,11 +238,12 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ("index", "validators", u"validators Documentation", [u"Konsta Vesterinen"], 1) + ('index', 'validators', u'validators Documentation', + [u'Konsta Vesterinen'], 1) ] # If true, show URL addresses after external links. -# man_show_urls = False +#man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -254,29 +252,23 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ( - "index", - "validators", - u"validators Documentation", - u"Konsta Vesterinen", - "validators", - "One line description of project.", - "Miscellaneous", - ), + ('index', 'validators', u'validators Documentation', + u'Konsta Vesterinen', 'validators', 'One line description of project.', + 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. -# texinfo_appendices = [] +#texinfo_appendices = [] # If false, no module index is generated. -# texinfo_domain_indices = True +#texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -# texinfo_show_urls = 'footnote' +#texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -# texinfo_no_detailmenu = False +#texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {"http://docs.python.org/": None} +intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/setup.cfg b/setup.cfg index 4332c7d7..c5686b21 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,7 +6,7 @@ order_by_type=false include_trailing_comma=True [flake8] -ignore = D10,E203,E501,W503,E231,E265 +ignore = D10,E203,E501,W503,E231,E265,W504,E122,E121 max-line-length = 88 select = A,B,C4,D,E,F,M,Q,T,W,ABS,BLK inline-quotes = " diff --git a/tests/i18n/test_es.py b/tests/i18n/test_es.py index 4edb2b90..168c9e9f 100644 --- a/tests/i18n/test_es.py +++ b/tests/i18n/test_es.py @@ -6,43 +6,43 @@ @pytest.mark.parametrize( - ("value",), + ('value',), [ - ("B25162520",), - ("U4839822F",), - ("B96817697",), - ("P7067074J",), - ("Q7899705C",), - ("C75098681",), - ("G76061860",), - ("C71345375",), - ("G20558169",), - ("U5021960I",), + ('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",), + ('value',), [ - ("X0095892M",), - ("X8868108K",), - ("X2911154K",), - ("Y2584969J",), - ("X7536157T",), - ("Y5840388N",), - ("Z2915723H",), - ("Y4002236C",), - ("X7750702R",), - ("Y0408759V",), + ('X0095892M',), + ('X8868108K',), + ('X2911154K',), + ('Y2584969J',), + ('X7536157T',), + ('Y5840388N',), + ('Z2915723H',), + ('Y4002236C',), + ('X7750702R',), + ('Y0408759V',), ], ) def test_returns_true_on_valid_nie(value): @@ -50,31 +50,31 @@ def test_returns_true_on_valid_nie(value): @pytest.mark.parametrize( - ("value",), + ('value',), [ - ("K0000023T",), - ("L0000024R",), - ("M0000025W",), - ("00000026A",), - ("00000027G",), - ("00000028M",), - ("00000029Y",), - ("00000030F",), - ("00000031P",), - ("00000032D",), - ("00000033X",), - ("00000034B",), - ("00000035N",), - ("00000036J",), - ("00000037Z",), - ("00000038S",), - ("00000039Q",), - ("00000040V",), - ("00000041H",), - ("00000042L",), - ("00000043C",), - ("00000044K",), - ("00000045E",), + ('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): @@ -82,7 +82,7 @@ def test_returns_true_on_valid_nif(value): @pytest.mark.parametrize( - ("value",), [("12345",), ("X0000000T",), ("00000000T",), ("00000001R",),] + ('value',), [('12345',), ('X0000000T',), ('00000000T',), ('00000001R',),] ) def test_returns_false_on_invalid_nif(value): result = es_nif(value) @@ -90,20 +90,20 @@ def test_returns_false_on_invalid_nif(value): @pytest.mark.parametrize( - ("value",), + ('value',), [ # CIFs - ("B25162520",), - ("U4839822F",), - ("B96817697",), + ('B25162520',), + ('U4839822F',), + ('B96817697',), # NIEs - ("X0095892M",), - ("X8868108K",), - ("X2911154K",), + ('X0095892M',), + ('X8868108K',), + ('X2911154K',), # NIFs - ("26643189N",), - ("07060225F",), - ("49166693F",), + ('26643189N',), + ('07060225F',), + ('49166693F',), ], ) def test_returns_true_on_valid_doi(value): diff --git a/tests/i18n/test_fi.py b/tests/i18n/test_fi.py index d2991b19..0557a614 100644 --- a/tests/i18n/test_fi.py +++ b/tests/i18n/test_fi.py @@ -6,11 +6,11 @@ @pytest.mark.parametrize( - ("value",), + ('value',), [ - ("2336509-6",), # Supercell - ("0112038-9",), # Fast Monkeys - ("2417581-7",), # Nokia + ('2336509-6',), # Supercell + ('0112038-9',), # Fast Monkeys + ('2417581-7',), # Nokia ], ) def test_returns_true_on_valid_business_id(value): @@ -18,20 +18,20 @@ def test_returns_true_on_valid_business_id(value): @pytest.mark.parametrize( - ("value",), [(None,), ("",), ("1233312312",), ("1333333-8",), ("1231233-9",),] + ('value',), [(None,), ('',), ('1233312312',), ('1333333-8',), ('1231233-9',),] ) def test_returns_failed_validation_on_invalid_business_id(value): assert isinstance(fi_business_id(value), ValidationFailure) @pytest.mark.parametrize( - ("value",), + ('value',), [ - ("010190-002R",), - ("010101-0101",), - ("010101+0101",), - ("010101A0101",), - ("010190-900P",), + ('010190-002R',), + ('010101-0101',), + ('010101+0101',), + ('010101A0101',), + ('010190-900P',), ], ) def test_returns_true_on_valid_ssn(value): @@ -39,19 +39,19 @@ def test_returns_true_on_valid_ssn(value): @pytest.mark.parametrize( - ("value",), + ('value',), [ (None,), - ("",), - ("010190-001P",), # Too low serial - ("010190-000N",), # Too low serial - ("000190-0023",), # Invalid day - ("010090-002X",), # Invalid month - ("010190-002r",), # Invalid checksum - ("101010-0102",), - ("10a010-0101",), - ("101010-0\xe401",), - ("101010b0101",), + ('',), + ('010190-001P',), # Too low serial + ('010190-000N',), # Too low serial + ('000190-0023',), # Invalid day + ('010090-002X',), # Invalid month + ('010190-002r',), # Invalid checksum + ('101010-0102',), + ('10a010-0101',), + ('101010-0\xe401',), + ('101010b0101',), ], ) def test_returns_failed_validation_on_invalid_ssn(value): @@ -60,5 +60,5 @@ def test_returns_failed_validation_on_invalid_ssn(value): def test_returns_failed_validation_on_temporal_ssn_when_not_allowed(): assert isinstance( - fi_ssn("010190-900P", allow_temporal_ssn=False), ValidationFailure + fi_ssn('010190-900P', allow_temporal_ssn=False), ValidationFailure ) diff --git a/tests/test_between.py b/tests/test_between.py index 8a532ead..ee10f9b8 100644 --- a/tests/test_between.py +++ b/tests/test_between.py @@ -5,21 +5,21 @@ @pytest.mark.parametrize( - ("value", "min", "max"), + ('value', 'min', 'max'), [(12, 11, 13), (12, None, 14), (12, 11, None), (12, 12, 12)], ) def test_returns_true_on_valid_range(value, min, max): assert validators.between(value, min=min, max=max) -@pytest.mark.parametrize(("value", "min", "max"), [(12, 13, 12), (12, None, None),]) +@pytest.mark.parametrize(('value', 'min', 'max'), [(12, 13, 12), (12, None, None),]) def test_raises_assertion_error_for_invalid_args(value, min, max): with pytest.raises(AssertionError): assert validators.between(value, min=min, max=max) @pytest.mark.parametrize( - ("value", "min", "max"), [(12, 13, 14), (12, None, 11), (12, 13, None)] + ('value', 'min', 'max'), [(12, 13, 14), (12, None, 11), (12, 13, None)] ) def test_returns_failed_validation_on_invalid_range(value, min, max): result = validators.between(value, min=min, max=max) diff --git a/tests/test_card.py b/tests/test_card.py index 6ac78648..378658c3 100644 --- a/tests/test_card.py +++ b/tests/test_card.py @@ -13,17 +13,17 @@ visa, ) -visa_cards = ["4242424242424242", "4000002760003184"] -mastercard_cards = ["5555555555554444", "2223003122003222"] -amex_cards = ["378282246310005", "371449635398431"] -unionpay_cards = ["6200000000000005"] -diners_cards = ["3056930009020004", "36227206271667"] -jcb_cards = ["3566002020360505"] -discover_cards = ["6011111111111117", "6011000990139424"] +visa_cards = ['4242424242424242', '4000002760003184'] +mastercard_cards = ['5555555555554444', '2223003122003222'] +amex_cards = ['378282246310005', '371449635398431'] +unionpay_cards = ['6200000000000005'] +diners_cards = ['3056930009020004', '36227206271667'] +jcb_cards = ['3566002020360505'] +discover_cards = ['6011111111111117', '6011000990139424'] @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + amex_cards @@ -37,19 +37,19 @@ def test_returns_true_on_valid_card_number(value): @pytest.mark.parametrize( - "value", ["4242424242424240", "4000002760003180", "400000276000318X"] + 'value', ['4242424242424240', '4000002760003180', '400000276000318X'] ) def test_returns_failed_on_valid_card_number(value): assert isinstance(card_number(value), ValidationFailure) -@pytest.mark.parametrize("value", visa_cards) +@pytest.mark.parametrize('value', visa_cards) def test_returns_true_on_valid_visa(value): assert visa(value) @pytest.mark.parametrize( - "value", + 'value', mastercard_cards + amex_cards + unionpay_cards @@ -61,13 +61,13 @@ def test_returns_failed_on_valid_visa(value): assert isinstance(visa(value), ValidationFailure) -@pytest.mark.parametrize("value", mastercard_cards) +@pytest.mark.parametrize('value', mastercard_cards) def test_returns_true_on_valid_mastercard(value): assert mastercard(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + amex_cards + unionpay_cards @@ -79,13 +79,13 @@ def test_returns_failed_on_valid_mastercard(value): assert isinstance(mastercard(value), ValidationFailure) -@pytest.mark.parametrize("value", amex_cards) +@pytest.mark.parametrize('value', amex_cards) def test_returns_true_on_valid_amex(value): assert amex(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + unionpay_cards @@ -97,13 +97,13 @@ def test_returns_failed_on_valid_amex(value): assert isinstance(amex(value), ValidationFailure) -@pytest.mark.parametrize("value", unionpay_cards) +@pytest.mark.parametrize('value', unionpay_cards) def test_returns_true_on_valid_unionpay(value): assert unionpay(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + amex_cards @@ -115,13 +115,13 @@ def test_returns_failed_on_valid_unionpay(value): assert isinstance(unionpay(value), ValidationFailure) -@pytest.mark.parametrize("value", diners_cards) +@pytest.mark.parametrize('value', diners_cards) def test_returns_true_on_valid_diners(value): assert diners(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + amex_cards @@ -133,13 +133,13 @@ def test_returns_failed_on_valid_diners(value): assert isinstance(diners(value), ValidationFailure) -@pytest.mark.parametrize("value", jcb_cards) +@pytest.mark.parametrize('value', jcb_cards) def test_returns_true_on_valid_jcb(value): assert jcb(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + amex_cards @@ -151,13 +151,13 @@ def test_returns_failed_on_valid_jcb(value): assert isinstance(jcb(value), ValidationFailure) -@pytest.mark.parametrize("value", discover_cards) +@pytest.mark.parametrize('value', discover_cards) def test_returns_true_on_valid_discover(value): assert discover(value) @pytest.mark.parametrize( - "value", + 'value', visa_cards + mastercard_cards + amex_cards diff --git a/tests/test_domain.py b/tests/test_domain.py index 82f1d916..eefc8784 100644 --- a/tests/test_domain.py +++ b/tests/test_domain.py @@ -5,20 +5,20 @@ @pytest.mark.parametrize( - "value", + 'value', [ - "example.com", - "xn----gtbspbbmkef.xn--p1ai", - "underscore_subdomain.example.com", - "something.versicherung", - "someThing.versicherung", - "11.com", - "3.cn", - "a.cn", - "sub1.sub2.sample.co.uk", - "somerandomexample.xn--fiqs8s", - "kräuter.com", - "über.com", + 'example.com', + 'xn----gtbspbbmkef.xn--p1ai', + 'underscore_subdomain.example.com', + 'something.versicherung', + 'someThing.versicherung', + '11.com', + '3.cn', + 'a.cn', + 'sub1.sub2.sample.co.uk', + 'somerandomexample.xn--fiqs8s', + 'kräuter.com', + 'über.com', ], ) def test_returns_true_on_valid_domain(value): @@ -26,22 +26,22 @@ def test_returns_true_on_valid_domain(value): @pytest.mark.parametrize( - "value", + 'value', [ - "example.com/", - "example.com:4444", - "example.-com", - "example.", - "-example.com", - "example-.com", - "_example.com", - "example_.com", - "example", - "a......b.com", - "a.123", - "123.123", - "123.123.123", - "123.123.123.123", + 'example.com/', + 'example.com:4444', + 'example.-com', + 'example.', + '-example.com', + 'example-.com', + '_example.com', + 'example_.com', + 'example', + 'a......b.com', + 'a.123', + '123.123', + '123.123.123', + '123.123.123.123', ], ) def test_returns_failed_validation_on_invalid_domain(value): diff --git a/tests/test_email.py b/tests/test_email.py index 861f8ea8..8cfe576f 100644 --- a/tests/test_email.py +++ b/tests/test_email.py @@ -5,16 +5,16 @@ @pytest.mark.parametrize( - ("value", "whitelist"), + ('value', 'whitelist'), [ - ("email@here.com", None), - ("weirder-email@here.and.there.com", None), - ("email@[127.0.0.1]", None), - ("example@valid-----hyphens.com", None), - ("example@valid-with-hyphens.com", None), - ("test@domain.with.idn.tld.उदाहरण.परीक्षा", None), - ("email@localhost", None), - ("email@localdomain", ["localdomain"]), + ('email@here.com', None), + ('weirder-email@here.and.there.com', None), + ('email@[127.0.0.1]', None), + ('example@valid-----hyphens.com', None), + ('example@valid-with-hyphens.com', None), + ('test@domain.with.idn.tld.उदाहरण.परीक्षा', None), + ('email@localhost', None), + ('email@localdomain', ['localdomain']), ('"test@test"@example.com', None), ('"\\\011"@here.com', None), ], @@ -24,24 +24,24 @@ def test_returns_true_on_valid_email(value, whitelist): @pytest.mark.parametrize( - ("value",), + ('value',), [ (None,), - ("",), - ("abc",), - ("abc@",), - ("abc@bar",), - ("a @x.cz",), - ("abc@.com",), - ("something@@somewhere.com",), - ("email@127.0.0.1",), - ("example@invalid-.com",), - ("example@-invalid.com",), - ("example@inv-.alid-.com",), - ("example@inv-.-alid.com",), + ('',), + ('abc',), + ('abc@',), + ('abc@bar',), + ('a @x.cz',), + ('abc@.com',), + ('something@@somewhere.com',), + ('email@127.0.0.1',), + ('example@invalid-.com',), + ('example@-invalid.com',), + ('example@inv-.alid-.com',), + ('example@inv-.-alid.com',), ( - "john56789.john56789.john56789.john56789.john56789.john56789.john5" - "@example.com", + 'john56789.john56789.john56789.john56789.john56789.john56789.john5' + '@example.com', ), # Quoted-string format (CR not allowed) ('"\\\012"@here.com',), diff --git a/tests/test_extremes.py b/tests/test_extremes.py index fab92b5f..5bc1e0e3 100644 --- a/tests/test_extremes.py +++ b/tests/test_extremes.py @@ -4,7 +4,7 @@ from validators import Max, Min -@pytest.mark.parametrize(("value",), [(None,), ("",), (12,), (Min,),]) +@pytest.mark.parametrize(('value',), [(None,), ('',), (12,), (Min,),]) def test_max_is_greater_than_every_other_value(value): assert value < Max assert Max > value @@ -20,7 +20,7 @@ def test_other_comparison_methods_for_max(): assert not (Max != Max) -@pytest.mark.parametrize(("value",), [(None,), ("",), (12,), (Max,),]) +@pytest.mark.parametrize(('value',), [(None,), ('',), (12,), (Max,),]) def test_min_is_smaller_than_every_other_value(value): assert value > Min diff --git a/tests/test_iban.py b/tests/test_iban.py index 198a3820..26aa2557 100644 --- a/tests/test_iban.py +++ b/tests/test_iban.py @@ -4,12 +4,12 @@ import validators -@pytest.mark.parametrize("value", ["GB82WEST12345698765432", "NO9386011117947"]) +@pytest.mark.parametrize('value', ['GB82WEST12345698765432', 'NO9386011117947']) def test_returns_true_on_valid_iban(value): assert validators.iban(value) -@pytest.mark.parametrize("value", ["GB81WEST12345698765432", "NO9186011117947"]) +@pytest.mark.parametrize('value', ['GB81WEST12345698765432', 'NO9186011117947']) def test_returns_failed_validation_on_invalid_iban(value): result = validators.iban(value) assert isinstance(result, validators.ValidationFailure) diff --git a/tests/test_ipv4.py b/tests/test_ipv4.py index 4a506e1a..829cdc1e 100644 --- a/tests/test_ipv4.py +++ b/tests/test_ipv4.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize( - ("address",), [("127.0.0.1",), ("123.5.77.88",), ("12.12.12.12",),] + ('address',), [('127.0.0.1',), ('123.5.77.88',), ('12.12.12.12',),] ) def test_returns_true_on_valid_ipv4_address(address): assert ipv4(address) @@ -13,8 +13,8 @@ def test_returns_true_on_valid_ipv4_address(address): @pytest.mark.parametrize( - ("address",), - [("abc.0.0.1",), ("1278.0.0.1",), ("127.0.0.abc",), ("900.200.100.75",),], + ('address',), + [('abc.0.0.1',), ('1278.0.0.1',), ('127.0.0.abc',), ('900.200.100.75',),], ) def test_returns_failed_validation_on_invalid_ipv4_address(address): assert isinstance(ipv4(address), ValidationFailure) diff --git a/tests/test_ipv4_cidr.py b/tests/test_ipv4_cidr.py index 6119cf5d..eb130baa 100644 --- a/tests/test_ipv4_cidr.py +++ b/tests/test_ipv4_cidr.py @@ -5,7 +5,7 @@ @pytest.mark.parametrize( - ("cidr",), [("127.0.0.1/0",), ("123.5.77.88/8",), ("12.12.12.12/32",),] + ('cidr',), [('127.0.0.1/0',), ('123.5.77.88/8',), ('12.12.12.12/32',),] ) def test_returns_true_on_valid_ipv4_cidr(cidr): assert ipv4_cidr(cidr) @@ -13,8 +13,8 @@ def test_returns_true_on_valid_ipv4_cidr(cidr): @pytest.mark.parametrize( - ("cidr",), - [("abc.0.0.1",), ("1.1.1.1",), ("1.1.1.1/-1",), ("1.1.1.1/33",), ("1.1.1.1/foo",),], + ('cidr',), + [('abc.0.0.1',), ('1.1.1.1',), ('1.1.1.1/-1',), ('1.1.1.1/33',), ('1.1.1.1/foo',),], ) def test_returns_failed_validation_on_invalid_ipv4_cidr(cidr): assert isinstance(ipv4_cidr(cidr), ValidationFailure) diff --git a/tests/test_ipv6.py b/tests/test_ipv6.py index 25b0b7d8..4c650e9c 100644 --- a/tests/test_ipv6.py +++ b/tests/test_ipv6.py @@ -5,13 +5,13 @@ @pytest.mark.parametrize( - ("address",), + ('address',), [ - ("::1",), - ("dead:beef:0:0:0:0:42:1",), - ("abcd:ef::42:1",), - ("0:0:0:0:0:ffff:1.2.3.4",), - ("::192.168.30.2",), + ('::1',), + ('dead:beef:0:0:0:0:42:1',), + ('abcd:ef::42:1',), + ('0:0:0:0:0:ffff:1.2.3.4',), + ('::192.168.30.2',), ], ) def test_returns_true_on_valid_ipv6_address(address): @@ -20,8 +20,8 @@ def test_returns_true_on_valid_ipv6_address(address): @pytest.mark.parametrize( - ("address",), - [("abc.0.0.1",), ("abcd:1234::123::1",), ("1:2:3:4:5:6:7:8:9",), ("abcd::1ffff",),], + ('address',), + [('abc.0.0.1',), ('abcd:1234::123::1',), ('1:2:3:4:5:6:7:8:9',), ('abcd::1ffff',),], ) def test_returns_failed_validation_on_invalid_ipv6_address(address): assert isinstance(ipv6(address), ValidationFailure) diff --git a/tests/test_ipv6_cidr.py b/tests/test_ipv6_cidr.py index 69af24db..cd28206d 100644 --- a/tests/test_ipv6_cidr.py +++ b/tests/test_ipv6_cidr.py @@ -5,13 +5,13 @@ @pytest.mark.parametrize( - ("cidr",), + ('cidr',), [ - ("::1/0",), - ("dead:beef:0:0:0:0:42:1/8",), - ("abcd:ef::42:1/32",), - ("0:0:0:0:0:ffff:1.2.3.4/64",), - ("::192.168.30.2/128",), + ('::1/0',), + ('dead:beef:0:0:0:0:42:1/8',), + ('abcd:ef::42:1/32',), + ('0:0:0:0:0:ffff:1.2.3.4/64',), + ('::192.168.30.2/128',), ], ) def test_returns_true_on_valid_ipv6_cidr(cidr): @@ -20,17 +20,17 @@ def test_returns_true_on_valid_ipv6_cidr(cidr): @pytest.mark.parametrize( - ("cidr",), + ('cidr',), [ - ("abc.0.0.1",), - ("abcd:1234::123::1",), - ("1:2:3:4:5:6:7:8:9",), - ("abcd::1ffff",), - ("1.1.1.1",), - ("::1",), - ("::1/129",), - ("::1/-1",), - ("::1/foo",), + ('abc.0.0.1',), + ('abcd:1234::123::1',), + ('1:2:3:4:5:6:7:8:9',), + ('abcd::1ffff',), + ('1.1.1.1',), + ('::1',), + ('::1/129',), + ('::1/-1',), + ('::1/foo',), ], ) def test_returns_failed_validation_on_invalid_ipv6_cidr(cidr): diff --git a/tests/test_length.py b/tests/test_length.py index 3c2ef00e..04a04438 100644 --- a/tests/test_length.py +++ b/tests/test_length.py @@ -5,12 +5,12 @@ @pytest.mark.parametrize( - ("value", "min", "max"), + ('value', 'min', 'max'), [ - ("password", 2, 10), - ("password", None, 10), - ("password", 2, None), - ("password", 8, 8), + ('password', 2, 10), + ('password', None, 10), + ('password', 2, None), + ('password', 8, 8), ], ) def test_returns_true_on_valid_length(value, min, max): @@ -18,12 +18,12 @@ def test_returns_true_on_valid_length(value, min, max): @pytest.mark.parametrize( - ("value", "min", "max"), + ('value', 'min', 'max'), [ - ("something", 13, 12), - ("something", -1, None), - ("something", -1, None), - ("something", -3, -2), + ('something', 13, 12), + ('something', -1, None), + ('something', -1, None), + ('something', -3, -2), ], ) def test_raises_assertion_error_for_invalid_args(value, min, max): @@ -32,8 +32,8 @@ def test_raises_assertion_error_for_invalid_args(value, min, max): @pytest.mark.parametrize( - ("value", "min", "max"), - [("something", 13, 14), ("something", None, 6), ("something", 13, None)], + ('value', 'min', 'max'), + [('something', 13, 14), ('something', None, 6), ('something', 13, None)], ) def test_returns_failed_validation_on_invalid_range(value, min, max): assert isinstance( diff --git a/tests/test_mac_address.py b/tests/test_mac_address.py index 5350f6a7..3eaeaf0d 100644 --- a/tests/test_mac_address.py +++ b/tests/test_mac_address.py @@ -4,18 +4,18 @@ from validators import mac_address, ValidationFailure -@pytest.mark.parametrize(("address",), [("01:23:45:67:ab:CD",),]) +@pytest.mark.parametrize(('address',), [('01:23:45:67:ab:CD',),]) def test_returns_true_on_valid_mac_address(address): assert mac_address(address) @pytest.mark.parametrize( - ("address",), + ('address',), [ - ("00:00:00:00:00",), - ("01:23:45:67:89:",), - ("01:23:45:67:89:gh",), - ("123:23:45:67:89:00",), + ('00:00:00:00:00',), + ('01:23:45:67:89:',), + ('01:23:45:67:89:gh',), + ('123:23:45:67:89:00',), ], ) def test_returns_failed_validation_on_invalid_mac_address(address): diff --git a/tests/test_md5.py b/tests/test_md5.py index 75ef0a1b..0a5fd689 100644 --- a/tests/test_md5.py +++ b/tests/test_md5.py @@ -5,18 +5,18 @@ @pytest.mark.parametrize( - "value", ["d41d8cd98f00b204e9800998ecf8427e", "D41D8CD98F00B204E9800998ECF8427E"] + 'value', ['d41d8cd98f00b204e9800998ecf8427e', 'D41D8CD98F00B204E9800998ECF8427E'] ) def test_returns_true_on_valid_md5(value): assert validators.md5(value) @pytest.mark.parametrize( - "value", + 'value', [ - "z41d8cd98f00b204e9800998ecf8427e", - "z8cd98f00b204e9800998ecf8427e", - "z4aaaa1d8cd98f00b204e9800998ecf8427e", + 'z41d8cd98f00b204e9800998ecf8427e', + 'z8cd98f00b204e9800998ecf8427e', + 'z4aaaa1d8cd98f00b204e9800998ecf8427e', ], ) def test_returns_failed_validation_on_invalid_md5(value): diff --git a/tests/test_sha1.py b/tests/test_sha1.py index 104c46c7..727a961f 100644 --- a/tests/test_sha1.py +++ b/tests/test_sha1.py @@ -5,10 +5,10 @@ @pytest.mark.parametrize( - "value", + 'value', [ - "da39a3ee5e6b4b0d3255bfef95601890afd80709", - "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709", + 'da39a3ee5e6b4b0d3255bfef95601890afd80709', + 'DA39A3EE5E6B4B0D3255BFEF95601890AFD80709', ], ) def test_returns_true_on_valid_sha1(value): @@ -16,11 +16,11 @@ def test_returns_true_on_valid_sha1(value): @pytest.mark.parametrize( - "value", + 'value', [ - "za39a3ee5e6b4b0d3255bfef95601890afd80709", - "da39e5e6b4b0d3255bfef95601890afd80709", - "daaaa39a3ee5e6b4b0d3255bfef95601890afd80709", + 'za39a3ee5e6b4b0d3255bfef95601890afd80709', + 'da39e5e6b4b0d3255bfef95601890afd80709', + 'daaaa39a3ee5e6b4b0d3255bfef95601890afd80709', ], ) def test_returns_failed_validation_on_invalid_sha1(value): diff --git a/tests/test_sha224.py b/tests/test_sha224.py index 63b9376d..e508b370 100644 --- a/tests/test_sha224.py +++ b/tests/test_sha224.py @@ -5,10 +5,10 @@ @pytest.mark.parametrize( - "value", + 'value', [ - "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", - "D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F", + 'd14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', + 'D14A028C2A3A2BC9476102BB288234C415A2B01F828EA62AC5B3E42F', ], ) def test_returns_true_on_valid_sha224(value): @@ -16,11 +16,11 @@ def test_returns_true_on_valid_sha224(value): @pytest.mark.parametrize( - "value", + 'value', [ - "z14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", - "d028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", - "daaa14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", + 'z14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', + 'd028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', + 'daaa14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f', ], ) def test_returns_failed_validation_on_invalid_sha224(value): diff --git a/tests/test_sha256.py b/tests/test_sha256.py index 20a74def..8c9bbcb6 100644 --- a/tests/test_sha256.py +++ b/tests/test_sha256.py @@ -5,10 +5,10 @@ @pytest.mark.parametrize( - "value", + 'value', [ - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855", + 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + 'E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855', ], ) def test_returns_true_on_valid_sha256(value): @@ -16,11 +16,11 @@ def test_returns_true_on_valid_sha256(value): @pytest.mark.parametrize( - "value", + 'value', [ - "z3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "ec44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "eaaaa3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + 'z3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + 'ec44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', + 'eaaaa3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', ], ) def test_returns_failed_validation_on_invalid_sha256(value): diff --git a/tests/test_sha512.py b/tests/test_sha512.py index 4b553935..28d2d8d7 100644 --- a/tests/test_sha512.py +++ b/tests/test_sha512.py @@ -5,15 +5,15 @@ @pytest.mark.parametrize( - "value", + 'value', [ ( - "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d" - "13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d' + '13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' ), ( - "CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D" - "13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E" + 'CF83E1357EEFB8BDF1542850D66D8007D620E4050B5715DC83F4A921D36CE9CE47D0D' + '13C5D85F2B0FF8318D2877EEC2F63B931BD47417A81A538327AF927DA3E' ), ], ) @@ -22,19 +22,19 @@ def test_returns_true_on_valid_sha512(value): @pytest.mark.parametrize( - "value", + 'value', [ ( - "zf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d" - "13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + 'zf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d' + '13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' ), ( - "cf8357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c" - "5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + 'cf8357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c' + '5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' ), ( - "cf8aaaa3e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce4" - "7d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" + 'cf8aaaa3e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce4' + '7d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e' ), ], ) diff --git a/tests/test_slug.py b/tests/test_slug.py index a96bba64..8a74a780 100644 --- a/tests/test_slug.py +++ b/tests/test_slug.py @@ -5,12 +5,12 @@ @pytest.mark.parametrize( - "value", ["123-12312-asdasda", "123____123", "dsadasd-dsadas",] + 'value', ['123-12312-asdasda', '123____123', 'dsadasd-dsadas',] ) def test_returns_true_on_valid_slug(value): assert slug(value) -@pytest.mark.parametrize("value", ["some.slug", "1231321%", " 21312", "123asda&",]) +@pytest.mark.parametrize('value', ['some.slug', '1231321%', ' 21312', '123asda&',]) def test_returns_failed_validation_on_invalid_slug(value): assert isinstance(slug(value), ValidationFailure) diff --git a/tests/test_url.py b/tests/test_url.py index 8b474df4..8fcc67be 100644 --- a/tests/test_url.py +++ b/tests/test_url.py @@ -4,159 +4,148 @@ from validators import url, ValidationFailure -@pytest.mark.parametrize( - "address", - [ - u"http://foobar.dk", - u"http://foobar.museum/foobar", - u"http://fo.com", - u"http://FOO.com", - u"http://foo.com/blah_blah", - u"http://foo.com/blah_blah/", - u"http://foo.com/blah_blah_(wikipedia)", - u"http://foo.com/blah_blah_(wikipedia)_(again)", - u"http://www.example.com/wpstyle/?p=364", - u"https://www.example.com/foo/?bar=baz&inga=42&quux", - u"https://www.example.com?bar=baz", - u"http://✪df.ws/123", - u"http://userid:password@example.com:8080", - u"http://userid:password@example.com:8080/", - u"http://userid@example.com", - u"http://userid@example.com/", - u"http://userid@example.com:8080", - u"http://userid@example.com:8080/", - u"http://userid:password@example.com", - u"http://userid:password@example.com/", - u"http://142.42.1.1/", - u"http://142.42.1.1:8080/", - u"http://➡.ws/䨹", - u"http://⌘.ws", - u"http://⌘.ws/", - u"http://foo.com/blah_(wikipedia)#cite-1", - u"http://foo.com/blah_(wikipedia)_blah#cite-1", - u"http://foo.com/unicode_(✪)_in_parens", - u"http://foo.com/(something)?after=parens", - u"http://☺.damowmow.com/", - u"http://code.google.com/events/#&product=browser", - u"http://j.mp", - u"ftp://foo.bar/baz", - u"http://foo.bar/?q=Test%20URL-encoded%20stuff", - u"http://مثال.إختبار", - u"http://例子.测试", - u"http://उदाहरण.परीक्षा", - u"http://www.😉.com", - u"http://😉.com/😁", - u"http://উদাহরণ.বাংলা", - u"http://xn--d5b6ci4b4b3a.xn--54b7fta0cc", - u"http://-.~_!$&'()*+,;=:%40:80%2f::::::@example.com", - u"http://1337.net", - u"http://a.b-c.de", - u"http://223.255.255.254", - u"http://10.1.1.0", - u"http://10.1.1.1", - u"http://10.1.1.254", - u"http://10.1.1.255", - u"http://127.0.0.1:8080", - u"http://127.0.10.150", - u"http://localhost", - u"http://localhost:8000", - u"http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", - u"http://[1080:0:0:0:8:800:200C:417A]/index.html", - u"http://[3ffe:2a00:100:7031::1]", - u"http://[1080::8:800:200C:417A]/foo", - u"http://[::192.9.5.5]/ipng", - u"http://[::FFFF:129.144.52.38]:80/index.html", - u"http://[2010:836B:4179::836B:4179]", - ], -) +@pytest.mark.parametrize('address', [ + u'http://foobar.dk', + u'http://foobar.museum/foobar', + u'http://fo.com', + u'http://FOO.com', + u'http://foo.com/blah_blah', + u'http://foo.com/blah_blah/', + u'http://foo.com/blah_blah_(wikipedia)', + u'http://foo.com/blah_blah_(wikipedia)_(again)', + u'http://www.example.com/wpstyle/?p=364', + u'https://www.example.com/foo/?bar=baz&inga=42&quux', + u'https://www.example.com?bar=baz', + u'http://✪df.ws/123', + u'http://userid:password@example.com:8080', + u'http://userid:password@example.com:8080/', + u'http://userid@example.com', + u'http://userid@example.com/', + u'http://userid@example.com:8080', + u'http://userid@example.com:8080/', + u'http://userid:password@example.com', + u'http://userid:password@example.com/', + u'http://142.42.1.1/', + u'http://142.42.1.1:8080/', + u'http://➡.ws/䨹', + u'http://⌘.ws', + u'http://⌘.ws/', + u'http://foo.com/blah_(wikipedia)#cite-1', + u'http://foo.com/blah_(wikipedia)_blah#cite-1', + u'http://foo.com/unicode_(✪)_in_parens', + u'http://foo.com/(something)?after=parens', + u'http://☺.damowmow.com/', + u'http://code.google.com/events/#&product=browser', + u'http://j.mp', + u'ftp://foo.bar/baz', + u'http://foo.bar/?q=Test%20URL-encoded%20stuff', + u'http://مثال.إختبار', + u'http://例子.测试', + u'http://उदाहरण.परीक्षा', + u'http://www.😉.com', + u'http://😉.com/😁', + u'http://উদাহরণ.বাংলা', + u'http://xn--d5b6ci4b4b3a.xn--54b7fta0cc', + u'http://-.~_!$&\'()*+,;=:%40:80%2f::::::@example.com', + u'http://1337.net', + u'http://a.b-c.de', + u'http://223.255.255.254', + u'http://10.1.1.0', + u'http://10.1.1.1', + u'http://10.1.1.254', + u'http://10.1.1.255', + u'http://127.0.0.1:8080', + u'http://127.0.10.150', + u'http://localhost', + u'http://localhost:8000', + u'http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html', + u'http://[1080:0:0:0:8:800:200C:417A]/index.html', + u'http://[3ffe:2a00:100:7031::1]', + u'http://[1080::8:800:200C:417A]/foo', + u'http://[::192.9.5.5]/ipng', + u'http://[::FFFF:129.144.52.38]:80/index.html', + u'http://[2010:836B:4179::836B:4179]', +]) def test_returns_true_on_valid_url(address): assert url(address) -@pytest.mark.parametrize( - "address, public", - [ - (u"http://foo.bar", True), - (u"http://username:password@example.com:4010/", False), - (u"http://username:password@112.168.10.10:4010/", True), - (u"http://username:password@192.168.10.10:4010/", False), - (u"http://10.0.10.1", False), - (u"http://127.0.0.1", False), - ], -) +@pytest.mark.parametrize('address, public', [ + (u'http://foo.bar', True), + (u'http://username:password@example.com:4010/', False), + (u'http://username:password@112.168.10.10:4010/', True), + (u'http://username:password@192.168.10.10:4010/', False), + (u'http://10.0.10.1', False), + (u'http://127.0.0.1', False), +]) def test_returns_true_on_valid_public_url(address, public): assert url(address, public=public) -@pytest.mark.parametrize( - "address", - [ - "http://foobar", - "foobar.dk", - "http://127.0.0/asdf", - "http://foobar.d", - "http://foobar.12", - "http://foobar", - "htp://foobar.com", - "http://foobar..com", - "http://fo..com", - "http://", - "http://.", - "http://..", - "http://../", - "http://?", - "http://??", - "http://??/", - "http://#", - "http://##", - "http://##/", - "http://foo.bar?q=Spaces should be encoded", - "//", - "//a", - "///a", - "///", - "http:///a", - "foo.com", - "rdar://1234", - "h://test", - "http:// shouldfail.com", - ":// should fail", - "http://foo.bar/foo(bar)baz quux", - "ftps://foo.bar/", - "http://-error-.invalid/", - "http://a.b--c.de/", - "http://-a.b.co", - "http://a.b-.co", - "http://0.0.0.0", - "http://224.1.1.1", - "http://1.1.1.1.1", - "http://123.123.123", - "http://3628126748", - "http://.www.foo.bar/", - "http://www.foo.bar./", - "http://.www.foo.bar./", - "http://127.12.0.260", - 'http://example.com/">user@example.com', - "http://[2010:836B:4179::836B:4179", - "http://2010:836B:4179::836B:4179", - "http://2010:836B:4179::836B:4179:80/index.html", - ], -) +@pytest.mark.parametrize('address', [ + 'http://foobar', + 'foobar.dk', + 'http://127.0.0/asdf', + 'http://foobar.d', + 'http://foobar.12', + 'http://foobar', + 'htp://foobar.com', + 'http://foobar..com', + 'http://fo..com', + 'http://', + 'http://.', + 'http://..', + 'http://../', + 'http://?', + 'http://??', + 'http://??/', + 'http://#', + 'http://##', + 'http://##/', + 'http://foo.bar?q=Spaces should be encoded', + '//', + '//a', + '///a', + '///', + 'http:///a', + 'foo.com', + 'rdar://1234', + 'h://test', + 'http:// shouldfail.com', + ':// should fail', + 'http://foo.bar/foo(bar)baz quux', + 'ftps://foo.bar/', + 'http://-error-.invalid/', + 'http://a.b--c.de/', + 'http://-a.b.co', + 'http://a.b-.co', + 'http://0.0.0.0', + 'http://224.1.1.1', + 'http://1.1.1.1.1', + 'http://123.123.123', + 'http://3628126748', + 'http://.www.foo.bar/', + 'http://www.foo.bar./', + 'http://.www.foo.bar./', + 'http://127.12.0.260', + 'http://example.com/">user@example.com', + 'http://[2010:836B:4179::836B:4179', + 'http://2010:836B:4179::836B:4179', + 'http://2010:836B:4179::836B:4179:80/index.html', +]) def test_returns_failed_validation_on_invalid_url(address): assert isinstance(url(address), ValidationFailure) -@pytest.mark.parametrize( - "address, public", - [ - (u"http://username:password@192.168.10.10:4010/", True), - (u"http://10.0.10.1", True), - (u"http://127.0.0.1", True), - (u"foo://127.0.0.1", True), - (u"http://username:password@127.0.0.1:8080", True), - (u"http://localhost", True), - (u"http://localhost:8000", True), - ], -) +@pytest.mark.parametrize('address, public', [ + (u'http://username:password@192.168.10.10:4010/', True), + (u'http://10.0.10.1', True), + (u'http://127.0.0.1', True), + (u'foo://127.0.0.1', True), + (u'http://username:password@127.0.0.1:8080', True), + (u'http://localhost', True), + (u'http://localhost:8000', True), + +]) def test_returns_failed_validation_on_invalid_public_url(address, public): assert isinstance(url(address, public=public), ValidationFailure) diff --git a/tests/test_uuid.py b/tests/test_uuid.py index 22d5835d..c8258e12 100644 --- a/tests/test_uuid.py +++ b/tests/test_uuid.py @@ -4,18 +4,18 @@ from validators import uuid, ValidationFailure -@pytest.mark.parametrize(("value",), [("2bc1c94f-0deb-43e9-92a1-4775189ec9f8",),]) +@pytest.mark.parametrize(('value',), [('2bc1c94f-0deb-43e9-92a1-4775189ec9f8',),]) def test_returns_true_on_valid_mac_address(value): assert uuid(value) @pytest.mark.parametrize( - ("value",), + ('value',), [ - ("2bc1c94f-deb-43e9-92a1-4775189ec9f8",), - ("2bc1c94f-0deb-43e9-92a1-4775189ec9f",), - ("gbc1c94f-0deb-43e9-92a1-4775189ec9f8",), - ("2bc1c94f 0deb-43e9-92a1-4775189ec9f8",), + ('2bc1c94f-deb-43e9-92a1-4775189ec9f8',), + ('2bc1c94f-0deb-43e9-92a1-4775189ec9f',), + ('gbc1c94f-0deb-43e9-92a1-4775189ec9f8',), + ('2bc1c94f 0deb-43e9-92a1-4775189ec9f8',), ], ) def test_returns_failed_validation_on_invalid_mac_address(value): diff --git a/tests/test_validation_failure.py b/tests/test_validation_failure.py index 9bc6f937..e3a915d6 100644 --- a/tests/test_validation_failure.py +++ b/tests/test_validation_failure.py @@ -2,7 +2,7 @@ import validators -obj_repr = "ValidationFailure(func=between" +obj_repr = ('ValidationFailure(func=between') class TestValidationFailure(object): diff --git a/validators/__init__.py b/validators/__init__.py index 2f67e592..5b354e67 100644 --- a/validators/__init__.py +++ b/validators/__init__.py @@ -17,40 +17,40 @@ from .uuid import uuid __all__ = ( - "between", - "domain", - "email", - "Max", - "Min", - "md5", - "sha1", - "sha224", - "sha256", - "sha512", - "fi_business_id", - "fi_ssn", - "iban", - "ipv4", - "ipv4_cidr", - "ipv6", - "ipv6_cidr", - "length", - "mac_address", - "slug", - "truthy", - "url", - "ValidationFailure", - "validator", - "uuid", - "card_number", - "visa", - "mastercard", - "amex", - "unionpay", - "diners", - "jcb", - "discover", - "btc_address", + 'between', + 'domain', + 'email', + 'Max', + 'Min', + 'md5', + 'sha1', + 'sha224', + 'sha256', + 'sha512', + 'fi_business_id', + 'fi_ssn', + 'iban', + 'ipv4', + 'ipv4_cidr', + 'ipv6', + 'ipv6_cidr', + 'length', + 'mac_address', + 'slug', + 'truthy', + 'url', + 'ValidationFailure', + 'validator', + 'uuid', + 'card_number', + 'visa', + 'mastercard', + 'amex', + 'unionpay', + 'diners', + 'jcb', + 'discover', + 'btc_address', ) -__version__ = "0.18.0" +__version__ = '0.18.0' diff --git a/validators/between.py b/validators/between.py index a381d719..6d67c372 100644 --- a/validators/between.py +++ b/validators/between.py @@ -44,7 +44,7 @@ def between(value, min=None, max=None): .. versionadded:: 0.2 """ if min is None and max is None: - raise AssertionError("At least one of `min` or `max` must be specified.") + raise AssertionError('At least one of `min` or `max` must be specified.') if min is None: min = Min if max is None: @@ -54,6 +54,6 @@ def between(value, min=None, max=None): except TypeError: min_gt_max = max < min if min_gt_max: - raise AssertionError("`min` cannot be more than `max`.") + raise AssertionError('`min` cannot be more than `max`.') return min <= value and max >= value diff --git a/validators/card.py b/validators/card.py index 0fe0d95d..c8eed55e 100644 --- a/validators/card.py +++ b/validators/card.py @@ -51,7 +51,7 @@ def visa(value): :param value: Visa card number string to validate """ - pattern = re.compile(r"^4") + pattern = re.compile(r'^4') return card_number(value) and len(value) == 16 and pattern.match(value) @@ -72,7 +72,7 @@ def mastercard(value): :param value: Mastercard card number string to validate """ - pattern = re.compile(r"^(51|52|53|54|55|22|23|24|25|26|27)") + pattern = re.compile(r'^(51|52|53|54|55|22|23|24|25|26|27)') return card_number(value) and len(value) == 16 and pattern.match(value) @@ -93,7 +93,7 @@ def amex(value): :param value: American Express card number string to validate """ - pattern = re.compile(r"^(34|37)") + pattern = re.compile(r'^(34|37)') return card_number(value) and len(value) == 15 and pattern.match(value) @@ -114,7 +114,7 @@ def unionpay(value): :param value: UnionPay card number string to validate """ - pattern = re.compile(r"^62") + pattern = re.compile(r'^62') return card_number(value) and len(value) == 16 and pattern.match(value) @@ -135,7 +135,7 @@ def diners(value): :param value: Diners Club card number string to validate """ - pattern = re.compile(r"^(30|36|38|39)") + pattern = re.compile(r'^(30|36|38|39)') return card_number(value) and len(value) in [14, 16] and pattern.match(value) @@ -156,7 +156,7 @@ def jcb(value): :param value: JCB card number string to validate """ - pattern = re.compile(r"^35") + pattern = re.compile(r'^35') return card_number(value) and len(value) == 16 and pattern.match(value) @@ -177,5 +177,5 @@ def discover(value): :param value: Discover card number string to validate """ - pattern = re.compile(r"^(60|64|65)") + pattern = re.compile(r'^(60|64|65)') return card_number(value) and len(value) == 16 and pattern.match(value) diff --git a/validators/domain.py b/validators/domain.py index 52effb43..1c1ce232 100644 --- a/validators/domain.py +++ b/validators/domain.py @@ -11,14 +11,14 @@ text_type = unicode pattern = re.compile( - r"^(?:[a-zA-Z0-9]" # First character of the domain - r"(?:[a-zA-Z0-9-_]{0,61}[A-Za-z0-9])?\.)" # Sub domain + hostname - r"+[A-Za-z0-9][A-Za-z0-9-_]{0,61}" # First 61 characters of the gTLD - r"[A-Za-z]$" # Last character of the gTLD + r'^(?:[a-zA-Z0-9]' # First character of the domain + r'(?:[a-zA-Z0-9-_]{0,61}[A-Za-z0-9])?\.)' # Sub domain + hostname + r'+[A-Za-z0-9][A-Za-z0-9-_]{0,61}' # First 61 characters of the gTLD + r'[A-Za-z]$' # Last character of the gTLD ) -def to_unicode(obj, charset="utf-8", errors="strict"): +def to_unicode(obj, charset='utf-8', errors='strict'): if obj is None: return None if not isinstance(obj, bytes): @@ -57,6 +57,6 @@ def domain(value): :param value: domain string to validate """ try: - return pattern.match(to_unicode(value).encode("idna").decode("ascii")) + return pattern.match(to_unicode(value).encode('idna').decode('ascii')) except (UnicodeError, AttributeError): return False diff --git a/validators/email.py b/validators/email.py index 87cf04ee..229c8e46 100644 --- a/validators/email.py +++ b/validators/email.py @@ -4,21 +4,22 @@ user_regex = re.compile( # dot-atom - r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+" r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" + r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+" + r"(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" # quoted-string r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|' r"""\\[\001-\011\013\014\016-\177])*"$)""", - re.IGNORECASE, + re.IGNORECASE ) domain_regex = re.compile( # domain - r"(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+" - r"(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)" + r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+' + r'(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)' # literal form, ipv4 address (SMTP 4.1.3) - r"|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)" r"(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$", - re.IGNORECASE, -) -domain_whitelist = ["localhost"] + r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)' + r'(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$', + re.IGNORECASE) +domain_whitelist = ['localhost'] @validator @@ -53,10 +54,10 @@ def email(value, whitelist=None): if whitelist is None: whitelist = domain_whitelist - if not value or "@" not in value: + if not value or '@' not in value: return False - user_part, domain_part = value.rsplit("@", 1) + user_part, domain_part = value.rsplit('@', 1) if not user_regex.match(user_part): return False @@ -67,7 +68,7 @@ def email(value, whitelist=None): if domain_part not in whitelist and not domain_regex.match(domain_part): # Try for possible IDN domain-part try: - domain_part = domain_part.encode("idna").decode("ascii") + domain_part = domain_part.encode('idna').decode('ascii') return domain_regex.match(domain_part) except UnicodeError: return False diff --git a/validators/extremes.py b/validators/extremes.py index b5b5e040..43d168a7 100644 --- a/validators/extremes.py +++ b/validators/extremes.py @@ -23,7 +23,6 @@ class Min(object): .. versionadded:: 0.2 """ - def __lt__(self, other): if other is Min: return False @@ -52,7 +51,6 @@ class Max(object): .. versionadded:: 0.2 """ - def __gt__(self, other): if other is Max: return False diff --git a/validators/hashes.py b/validators/hashes.py index 5c45f475..4db7f78e 100644 --- a/validators/hashes.py +++ b/validators/hashes.py @@ -2,11 +2,26 @@ from .utils import validator -md5_regex = re.compile(r"^[0-9a-f]{32}$", re.IGNORECASE) -sha1_regex = re.compile(r"^[0-9a-f]{40}$", re.IGNORECASE) -sha224_regex = re.compile(r"^[0-9a-f]{56}$", re.IGNORECASE) -sha256_regex = re.compile(r"^[0-9a-f]{64}$", re.IGNORECASE) -sha512_regex = re.compile(r"^[0-9a-f]{128}$", re.IGNORECASE) +md5_regex = re.compile( + r"^[0-9a-f]{32}$", + re.IGNORECASE +) +sha1_regex = re.compile( + r"^[0-9a-f]{40}$", + re.IGNORECASE +) +sha224_regex = re.compile( + r"^[0-9a-f]{56}$", + re.IGNORECASE +) +sha256_regex = re.compile( + r"^[0-9a-f]{64}$", + re.IGNORECASE +) +sha512_regex = re.compile( + r"^[0-9a-f]{128}$", + re.IGNORECASE +) @validator diff --git a/validators/i18n/__init__.py b/validators/i18n/__init__.py index d651de88..12775c6c 100644 --- a/validators/i18n/__init__.py +++ b/validators/i18n/__init__.py @@ -1,4 +1,4 @@ # TODO: remove, let the user import it if they really want it from .fi import fi_business_id, fi_ssn # noqa -__all__ = ("fi_business_id", "fi_ssn") +__all__ = ('fi_business_id', 'fi_ssn') diff --git a/validators/i18n/es.py b/validators/i18n/es.py index 965867db..ed2e2a63 100644 --- a/validators/i18n/es.py +++ b/validators/i18n/es.py @@ -1,12 +1,7 @@ # -*- coding: utf-8 -*- from validators.utils import validator -__all__ = ( - "es_cif", - "es_nif", - "es_nie", - "es_doi", -) +__all__ = ('es_cif', 'es_nif', 'es_nie', 'es_doi',) def nif_nie_validation(doi, number_by_letter, special_cases): @@ -19,7 +14,7 @@ def nif_nie_validation(doi, number_by_letter, special_cases): if doi in special_cases: return False - table = "TRWAGMYFPDXBNJZSQVHLCKE" + table = 'TRWAGMYFPDXBNJZSQVHLCKE' if len(doi) != 9: return False @@ -71,7 +66,7 @@ def es_cif(doi): if len(doi) != 9: return False - table = "JABCDEFGHI" + table = 'JABCDEFGHI' first_chr = doi[0] doi_body = doi[1:8] control = doi[8] @@ -91,11 +86,11 @@ def es_cif(doi): res = (10 - (even_result + odd_result) % 10) % 10 - if first_chr in "ABEH": # Number type + if first_chr in 'ABEH': # Number type return str(res) == control - elif first_chr in "PSQW": # Letter type + elif first_chr in 'PSQW': # Letter type return table[res] == control - elif first_chr not in "CDFGJNRUV": + elif first_chr not in 'CDFGJNRUV': return False return control == str(res) or control == table[res] @@ -130,8 +125,8 @@ def es_nif(doi): :param doi: DOI to validate """ - number_by_letter = {"L": "0", "M": "0", "K": "0"} - special_cases = ["X0000000T", "00000000T", "00000001R"] + number_by_letter = {'L': '0', 'M': '0', 'K': '0'} + special_cases = ['X0000000T', '00000000T', '00000001R'] return nif_nie_validation(doi, number_by_letter, special_cases) @@ -164,8 +159,8 @@ def es_nie(doi): :param doi: DOI to validate """ - number_by_letter = {"X": "0", "Y": "1", "Z": "2"} - special_cases = ["X0000000T"] + number_by_letter = {'X': '0', 'Y': '1', 'Z': '2'} + special_cases = ['X0000000T'] # NIE must must start with X Y or Z if not doi or doi[0] not in number_by_letter.keys(): diff --git a/validators/i18n/fi.py b/validators/i18n/fi.py index 59ffc3dc..2e5eb578 100644 --- a/validators/i18n/fi.py +++ b/validators/i18n/fi.py @@ -2,8 +2,8 @@ from validators.utils import validator -business_id_pattern = re.compile(r"^[0-9]{7}-[0-9]$") -ssn_checkmarks = "0123456789ABCDEFHJKLMNPRSTUVWXY" +business_id_pattern = re.compile(r'^[0-9]{7}-[0-9]$') +ssn_checkmarks = '0123456789ABCDEFHJKLMNPRSTUVWXY' ssn_pattern = re.compile( r"""^ (?P(0[1-9]|[1-2]\d|3[01]) @@ -11,10 +11,8 @@ (\d{{2}})) [A+-] (?P(\d{{3}})) - (?P[{checkmarks}])$""".format( - checkmarks=ssn_checkmarks - ), - re.VERBOSE, + (?P[{checkmarks}])$""".format(checkmarks=ssn_checkmarks), + re.VERBOSE ) @@ -87,9 +85,10 @@ def fi_ssn(ssn, allow_temporal_ssn=True): if not result: return False gd = result.groupdict() - checksum = int(gd["date"] + gd["serial"]) + checksum = int(gd['date'] + gd['serial']) return ( - int(gd["serial"]) >= 2 - and (allow_temporal_ssn or int(gd["serial"]) <= 899) - and ssn_checkmarks[checksum % len(ssn_checkmarks)] == gd["checksum"] + int(gd['serial']) >= 2 and + (allow_temporal_ssn or int(gd['serial']) <= 899) and + ssn_checkmarks[checksum % len(ssn_checkmarks)] == + gd['checksum'] ) diff --git a/validators/iban.py b/validators/iban.py index bdf5da4a..7413d127 100644 --- a/validators/iban.py +++ b/validators/iban.py @@ -2,7 +2,9 @@ from .utils import validator -regex = r"^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$" +regex = ( + r'^[A-Z]{2}[0-9]{2}[A-Z0-9]{11,30}$' +) pattern = re.compile(regex) @@ -12,7 +14,7 @@ def char_value(char): if char.isdigit(): return int(char) else: - return 10 + ord(char) - ord("A") + return 10 + ord(char) - ord('A') def modcheck(value): @@ -23,8 +25,8 @@ def modcheck(value): # convert letters to numbers converted = [char_value(char) for char in rearranged] # interpret as integer - integerized = int("".join([str(i) for i in converted])) - return integerized % 97 == 1 + integerized = int(''.join([str(i) for i in converted])) + return (integerized % 97 == 1) @validator diff --git a/validators/ip_address.py b/validators/ip_address.py index 072f20ed..ba36cdc6 100644 --- a/validators/ip_address.py +++ b/validators/ip_address.py @@ -23,7 +23,7 @@ def ipv4(value): :param value: IP address string to validate """ - groups = value.split(".") + groups = value.split('.') if len(groups) != 4 or any(not x.isdigit() for x in groups): return False return all(0 <= int(part) < 256 for part in groups) @@ -46,7 +46,7 @@ def ipv4_cidr(value): ValidationFailure(func=ipv4_cidr, args={'value': '1.1.1.1'}) """ try: - prefix, suffix = value.split("/", 2) + prefix, suffix = value.split('/', 2) except ValueError: return False if not ipv4(prefix) or not suffix.isdigit(): @@ -83,10 +83,10 @@ def ipv6(value): :param value: IP address string to validate """ - ipv6_groups = value.split(":") + ipv6_groups = value.split(':') if len(ipv6_groups) == 1: return False - ipv4_groups = ipv6_groups[-1].split(".") + ipv4_groups = ipv6_groups[-1].split('.') if len(ipv4_groups) > 1: if not ipv4(ipv6_groups[-1]): @@ -136,7 +136,7 @@ def ipv6_cidr(value): ValidationFailure(func=ipv6_cidr, args={'value': '::1'}) """ try: - prefix, suffix = value.split("/", 2) + prefix, suffix = value.split('/', 2) except ValueError: return False if not ipv6(prefix) or not suffix.isdigit(): diff --git a/validators/length.py b/validators/length.py index 00036c64..d0f91fd3 100644 --- a/validators/length.py +++ b/validators/length.py @@ -31,5 +31,7 @@ def length(value, min=None, max=None): .. versionadded:: 0.2 """ if (min is not None and min < 0) or (max is not None and max < 0): - raise AssertionError("`min` and `max` need to be greater than zero.") + raise AssertionError( + '`min` and `max` need to be greater than zero.' + ) return between(len(value), min=min, max=max) diff --git a/validators/mac_address.py b/validators/mac_address.py index 64eecab6..bdb19947 100644 --- a/validators/mac_address.py +++ b/validators/mac_address.py @@ -2,7 +2,7 @@ from .utils import validator -pattern = re.compile(r"^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$") +pattern = re.compile(r'^(?:[0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$') @validator diff --git a/validators/slug.py b/validators/slug.py index 33c818e3..83bfd4b1 100644 --- a/validators/slug.py +++ b/validators/slug.py @@ -2,7 +2,7 @@ from .utils import validator -slug_regex = re.compile(r"^[-a-zA-Z0-9_]+$") +slug_regex = re.compile(r'^[-a-zA-Z0-9_]+$') @validator diff --git a/validators/truthy.py b/validators/truthy.py index f23bbe60..2744bd5b 100644 --- a/validators/truthy.py +++ b/validators/truthy.py @@ -35,4 +35,7 @@ def truthy(value): .. versionadded:: 0.2 """ - return value and (not isinstance(value, six.string_types) or value.strip()) + return ( + value and + (not isinstance(value, six.string_types) or value.strip()) + ) diff --git a/validators/url.py b/validators/url.py index c430d2e5..fe2cbf53 100644 --- a/validators/url.py +++ b/validators/url.py @@ -21,7 +21,9 @@ r"(?:172\.(?:1[6-9]|2\d|3[0-1])" + ip_middle_octet + ip_last_octet + r"))" r"|" # private & local hosts - r"(?P" r"(?:localhost))" r"|" + r"(?P" + r"(?:localhost))" + r"|" # IP address dotted notation octets # excludes loopback network 0.0.0.0 # excludes reserved space >= 224.0.0.0 @@ -64,7 +66,8 @@ r"((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}" # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 # (IPv4-Embedded IPv6 Address) - r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" r")\]|" + r"(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" + r")\]|" # host name r"(?:(?:(?:xn--)|[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]-?)*" r"[a-z\u00a1-\uffff\U00010000-\U0010ffff0-9]+)" @@ -82,8 +85,9 @@ # query string r"(?:\?\S*)?" # fragment - r"(?:#\S*)?" r"$", - re.UNICODE | re.IGNORECASE, + r"(?:#\S*)?" + r"$", + re.UNICODE | re.IGNORECASE ) pattern = re.compile(regex) @@ -146,5 +150,5 @@ def url(value, public=False): return result return result and not any( - (result.groupdict().get(key) for key in ("private_ip", "private_host")) + (result.groupdict().get(key) for key in ('private_ip', 'private_host')) ) diff --git a/validators/utils.py b/validators/utils.py index 8339186e..0d2d9714 100644 --- a/validators/utils.py +++ b/validators/utils.py @@ -12,9 +12,11 @@ def __init__(self, func, args): self.__dict__.update(args) def __repr__(self): - return u"ValidationFailure(func={func}, args={args})".format( + return u'ValidationFailure(func={func}, args={args})'.format( func=self.func.__name__, - args=dict([(k, v) for (k, v) in self.__dict__.items() if k != "func"]), + args=dict( + [(k, v) for (k, v) in self.__dict__.items() if k != 'func'] + ) ) def __str__(self): @@ -41,9 +43,17 @@ def func_args_as_dict(func, args, kwargs): _getargspec = inspect.getfullargspec arg_names = list( - OrderedDict.fromkeys(itertools.chain(_getargspec(func)[0], kwargs.keys())) + OrderedDict.fromkeys( + itertools.chain( + _getargspec(func)[0], + kwargs.keys() + ) + ) + ) + return OrderedDict( + list(six.moves.zip(arg_names, args)) + + list(kwargs.items()) ) - return OrderedDict(list(six.moves.zip(arg_names, args)) + list(kwargs.items())) def validator(func, *args, **kwargs): @@ -69,11 +79,11 @@ def validator(func, *args, **kwargs): :param args: positional function arguments :param kwargs: key value function arguments """ - def wrapper(func, *args, **kwargs): value = func(*args, **kwargs) if not value: - return ValidationFailure(func, func_args_as_dict(func, args, kwargs)) + return ValidationFailure( + func, func_args_as_dict(func, args, kwargs) + ) return True - return decorator(wrapper, func) diff --git a/validators/uuid.py b/validators/uuid.py index 75fe8548..f073b8d0 100644 --- a/validators/uuid.py +++ b/validators/uuid.py @@ -2,7 +2,7 @@ from .utils import validator -pattern = re.compile(r"^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$") +pattern = re.compile(r'^[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$') @validator From 5a830783550955ccdb9577ae1528602b1364887e Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Fri, 28 Aug 2020 15:50:09 +0200 Subject: [PATCH 09/11] :art: revert back double quotes to single quotes --- setup.py | 55 +++++++++++++++++++++++++++---------------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/setup.py b/setup.py index 5af113a7..28401853 100644 --- a/setup.py +++ b/setup.py @@ -14,47 +14,46 @@ PY3 = sys.version_info[0] == 3 HERE = os.path.dirname(os.path.abspath(__file__)) - extras_require = { - "test": ["pytest>=2.2.3", "flake8>=2.4.0", "isort>=4.2.2", "pre-commit",], + 'test': ['pytest>=2.2.3', 'flake8>=2.4.0', 'isort>=4.2.2', 'pre-commit',], } install_requires = [ - "six>=1.4.0", - "decorator>=3.4.0", + 'six>=1.4.0', + 'decorator>=3.4.0', ] setup( - name="validators", - version="0.18.0", - url="https://github.com/kvesteri/validators", - license="MIT", - author="Konsta Vesterinen", - author_email="konsta@fastmonkeys.com", - description="Python Data Validation for Humans™.", + name='validators', + version='0.18.0', + url='https://github.com/kvesteri/validators', + license='MIT', + author='Konsta Vesterinen', + author_email='konsta@fastmonkeys.com', + description='Python Data Validation for Humans™.', long_description=__doc__, - packages=find_packages(".", exclude=["tests", "tests.*"]), + packages=find_packages('.', exclude=['tests', 'tests.*']), zip_safe=False, include_package_data=True, - platforms="any", + platforms='any', install_requires=install_requires, build_requires=install_requires, extras_require=extras_require, classifiers=[ - "Environment :: Web Environment", - "Intended Audience :: Developers", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", - "Programming Language :: Python :: 3.6", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: Implementation :: CPython", - "Programming Language :: Python :: Implementation :: PyPy", - "Topic :: Internet :: WWW/HTTP :: Dynamic Content", - "Topic :: Software Development :: Libraries :: Python Modules", + 'Environment :: Web Environment', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: Implementation :: CPython', + 'Programming Language :: Python :: Implementation :: PyPy', + 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', + 'Topic :: Software Development :: Libraries :: Python Modules', ], - python_requires=">=3.4", + python_requires='>=3.4', ) From c194397d926f4f8c24177dec415d25a0f113b932 Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:26:36 +0200 Subject: [PATCH 10/11] Update setup.py --- setup.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 28401853..431144a8 100644 --- a/setup.py +++ b/setup.py @@ -14,6 +14,14 @@ PY3 = sys.version_info[0] == 3 HERE = os.path.dirname(os.path.abspath(__file__)) + +def get_version(): + filename = os.path.join(HERE, 'validators', '__init__.py') + with open(filename) as f: + contents = f.read() + 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', 'pre-commit',], } @@ -25,7 +33,7 @@ setup( name='validators', - version='0.18.0', + version=get_version(), url='https://github.com/kvesteri/validators', license='MIT', author='Konsta Vesterinen', From 7e844135f73db47f95e9a8ff1d6ea07e85f0d0ca Mon Sep 17 00:00:00 2001 From: Jay Vala <24193355+jdvala@users.noreply.github.com> Date: Mon, 31 Aug 2020 09:29:02 +0200 Subject: [PATCH 11/11] :arrow_up: added re --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 431144a8..e0be793e 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ """ import os +import re import sys from setuptools import find_packages, setup