Skip to content

Commit

Permalink
Merge pull request #3419 from ajcerejeira/ajcerejeira/django-username…
Browse files Browse the repository at this point in the history
…-field
  • Loading branch information
Zac-HD committed Jul 25, 2022
2 parents d53b129 + 5c5acbc commit 2ace082
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Expand Up @@ -56,11 +56,11 @@ jobs:
- check-django40
- check-django32
- check-django22
- check-pandas14
- check-pandas13
- check-pandas12
- check-pandas11
- check-pandas10
- check-pandas25
fail-fast: false
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.rst
Expand Up @@ -12,6 +12,7 @@ their individual contributions.
* `Adam Johnson <https://github.com/adamchainz>`_
* `Adam Sven Johnson <https://www.github.com/pkqk>`_
* `Afrida Tabassum <https://github.com/oxfordhalfblood>`_ (afrida@gmail.com)
* `Afonso Silva <https://github.com/ajcerejeira>`_ (ajcerejeira@gmail.com)
* `Akash Suresh <https://www.github.com/akash-suresh>`_ (akashsuresh36@gmail.com)
* `Alex Gaynor <https://github.com/alex>`_
* `Alex Stapleton <https://www.github.com/public>`_
Expand Down
6 changes: 6 additions & 0 deletions hypothesis-python/RELEASE.rst
@@ -0,0 +1,6 @@
RELEASE_TYPE: minor

:func:`~hypothesis.extra.django.from_field` now supports ``UsernameField``
from :mod:`django.contrib.auth.forms`.

Thanks to Afonso Silva for reporting and working on :issue:`3417`.
2 changes: 1 addition & 1 deletion hypothesis-python/docs/conf.py
Expand Up @@ -89,7 +89,7 @@ def setup(app):
"sphinx": ("https://www.sphinx-doc.org/en/master/", None),
}

autodoc_mock_imports = ["numpy", "pandas", "redis"]
autodoc_mock_imports = ["numpy", "pandas", "redis", "django"]

codeautolink_autodoc_inject = False
codeautolink_global_preface = """
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/docs/numpy.rst
Expand Up @@ -47,7 +47,7 @@ Supported versions
There is quite a lot of variation between pandas versions. We only
commit to supporting the latest version of pandas, but older minor versions are
supported on a "best effort" basis. Hypothesis is currently tested against
and confirmed working with every Pandas minor version from 0.25 through to 1.3.
and confirmed working with every Pandas minor version from 1.0 through to 1.4.

Releases that are not the latest patch release of their minor version are not
tested or officially supported, but will probably also work unless you hit a
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/setup.py
Expand Up @@ -59,7 +59,7 @@ def local_file(name):
"dateutil": ["python-dateutil>=1.4"],
"lark": ["lark-parser>=0.6.5"],
"numpy": ["numpy>=1.9.0"],
"pandas": ["pandas>=0.25"],
"pandas": ["pandas>=1.0"],
"pytest": ["pytest>=4.6"],
"dpcontracts": ["dpcontracts>=0.4"],
"redis": ["redis>=3.0.0"],
Expand Down
2 changes: 2 additions & 0 deletions hypothesis-python/src/hypothesis/extra/django/_fields.py
Expand Up @@ -17,6 +17,7 @@

import django
from django import forms as df
from django.contrib.auth.forms import UsernameField
from django.core.validators import (
validate_ipv4_address,
validate_ipv6_address,
Expand Down Expand Up @@ -223,6 +224,7 @@ def _for_binary(field):
@register_for(dm.TextField)
@register_for(df.CharField)
@register_for(df.RegexField)
@register_for(UsernameField)
def _for_text(field):
# We can infer a vastly more precise strategy by considering the
# validators as well as the field type. This is a minimal proof of
Expand Down
2 changes: 1 addition & 1 deletion hypothesis-python/src/hypothesis/extra/pytz.py
Expand Up @@ -23,7 +23,7 @@
import datetime as dt

import pytz
from pytz.tzfile import StaticTzInfo
from pytz.tzfile import StaticTzInfo # type: ignore # considered private by typeshed

from hypothesis import strategies as st
from hypothesis.strategies._internal.utils import cacheable, defines_strategy
Expand Down
Expand Up @@ -142,7 +142,7 @@ def __init__(self, member):

# When we're trying to figure out what state a string leads to we will
# end up searching to find a suitable candidate. By putting states in
# a self-organisating list we ideally minimise the number of lookups.
# a self-organising list we ideally minimise the number of lookups.
self.__self_organising_states = SelfOrganisingList(self.__states)

self.start = 0
Expand Down
9 changes: 9 additions & 0 deletions hypothesis-python/tests/django/toystore/forms.py
Expand Up @@ -9,6 +9,7 @@
# obtain one at https://mozilla.org/MPL/2.0/.

from django import forms
from django.contrib.auth.forms import ReadOnlyPasswordHashField, UsernameField
from django.core.validators import (
MaxLengthValidator,
MaxValueValidator,
Expand Down Expand Up @@ -212,3 +213,11 @@ def __init__(self, subfield_count=12, **kwargs):

class ShortStringForm(ReprForm):
_not_too_long = forms.CharField(max_length=20, required=False)


class UsernameForm(ReprForm):
username = UsernameField()


class ReadOnlyPasswordHashFieldForm(ReprForm):
password = ReadOnlyPasswordHashField()
9 changes: 9 additions & 0 deletions hypothesis-python/tests/django/toystore/test_given_forms.py
Expand Up @@ -29,6 +29,7 @@
SlugFieldForm,
TemporalFieldForm,
URLFieldForm,
UsernameForm,
UUIDFieldForm,
WithValidatorsForm,
)
Expand Down Expand Up @@ -118,3 +119,11 @@ def test_tight_validators_form(self, x):
self.assertTrue(1 <= x.data["_decimal_one_to_five"] <= 5)
self.assertTrue(1 <= x.data["_float_one_to_five"] <= 5)
self.assertTrue(5 <= len(x.data["_string_five_to_ten"]) <= 10)

@given(from_form(UsernameForm))
def test_username_form(self, username_form):
self.assertTrue(username_form.is_valid())

@given(from_form(UsernameForm))
def test_read_only_password_hash_field_form(self, password_form):
self.assertTrue(password_form.is_valid())
1 change: 1 addition & 0 deletions hypothesis-python/tests/nocover/test_regex.py
Expand Up @@ -47,6 +47,7 @@ def conservative_regex(draw):
assume(COMBINED_MATCHER.search(result) is None)
control = sum(result.count(c) for c in "?+*")
assume(control <= 3)
assume(I_WITH_DOT not in result) # known to be weird
return result


Expand Down
22 changes: 11 additions & 11 deletions hypothesis-python/tox.ini
Expand Up @@ -42,19 +42,12 @@ commands=
python -bb -X dev -m pytest tests/quality/ -n auto

# Note: when adding or removing tested Pandas versions, make sure to update the
# docs in numpy.py too. To see current download rates of each minor version:
# https://pepy.tech/project/pandas?versions=0.25.*&versions=1.0.*&versions=1.1.*&versions=1.2.*&versions=1.3.*
[testenv:pandas25]
deps =
-r../requirements/test.txt
pandas~=0.25.0
commands =
python -bb -X dev -m pytest tests/pandas -n auto

# docs in numpy.rst too. To see current download rates of each minor version:
# https://pepy.tech/project/pandas?versions=0.25.*&versions=1.0.*&versions=1.1.*&versions=1.2.*&versions=1.3.*&versions=1.4.*
[testenv:pandas10]
deps =
-r../requirements/test.txt
pandas~=1.0.0
pandas~=1.0.5
commands =
python -bb -X dev -m pytest tests/pandas -n auto

Expand All @@ -75,7 +68,14 @@ commands =
[testenv:pandas13]
deps =
-r../requirements/test.txt
pandas~=1.3.4
pandas~=1.3.5
commands =
python -bb -X dev -m pytest tests/pandas -n auto

[testenv:pandas14]
deps =
-r../requirements/test.txt
pandas~=1.4.3
commands =
python -bb -X dev -m pytest tests/pandas -n auto
# Adding a new pandas? See comment above!
Expand Down
2 changes: 1 addition & 1 deletion requirements/coverage.txt
Expand Up @@ -28,7 +28,7 @@ exceptiongroup==1.0.0rc8 ; python_version < "3.11"
# via hypothesis (hypothesis-python/setup.py)
execnet==1.9.0
# via pytest-xdist
fakeredis==1.8.1
fakeredis==1.8.2
# via -r requirements/coverage.in
iniconfig==1.1.1
# via pytest
Expand Down
12 changes: 6 additions & 6 deletions requirements/tools.txt
Expand Up @@ -111,7 +111,7 @@ flake8-helper==0.2.1
# via flake8-strftime
flake8-mutable==1.2.0
# via -r requirements/tools.in
flake8-noqa==1.2.5
flake8-noqa==1.2.7
# via -r requirements/tools.in
flake8-pie==0.15.0
# via -r requirements/tools.in
Expand Down Expand Up @@ -170,7 +170,7 @@ matplotlib-inline==0.1.3
# via ipython
mccabe==0.6.1
# via flake8
mypy==0.961
mypy==0.971
# via -r requirements/tools.in
mypy-extensions==0.4.3
# via
Expand Down Expand Up @@ -239,15 +239,15 @@ pygments==2.12.0
# sphinx
pyparsing==3.0.9
# via packaging
pyright==1.1.261
pyright==1.1.263
# via -r requirements/tools.in
pytest==7.1.2
# via -r requirements/tools.in
python-dateutil==2.8.2
# via -r requirements/tools.in
pytz==2022.1
# via babel
pyupgrade==2.37.1
pyupgrade==2.37.2
# via shed
pyyaml==6.0
# via
Expand Down Expand Up @@ -347,9 +347,9 @@ types-click==7.1.8
# via -r requirements/tools.in
types-pkg-resources==0.1.3
# via -r requirements/tools.in
types-pytz==2022.1.1
types-pytz==2022.1.2
# via -r requirements/tools.in
types-redis==4.3.4
types-redis==4.3.11
# via -r requirements/tools.in
typing-extensions==4.3.0
# via
Expand Down
2 changes: 1 addition & 1 deletion tooling/src/hypothesistooling/__main__.py
Expand Up @@ -440,7 +440,7 @@ def standard_tox_task(name):

for n in [22, 32, 40]:
standard_tox_task(f"django{n}")
for n in [25, 10, 11, 12, 13]:
for n in [10, 11, 12, 13, 14]:
standard_tox_task(f"pandas{n}")

standard_tox_task("coverage")
Expand Down

0 comments on commit 2ace082

Please sign in to comment.