Skip to content

Commit

Permalink
Add hypothesis
Browse files Browse the repository at this point in the history
  • Loading branch information
micktwomey committed Feb 5, 2021
1 parent aecf975 commit 35ae4ed
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install pytest
run: pip install 'pytest>=6.2.2'
run: pip install 'pytest>=6.2.2' 'hypothesis>=6.1.1' 'pytz>=2021.1'
- name: pytest
run: pytest -vv --tb=short

Expand All @@ -39,6 +39,6 @@ jobs:
- name: Update pip
run: python -m pip install --upgrade pip
- name: Install mypy
run: python -m pip install --upgrade 'mypy>=0.800' 'pytest>=6.2.2'
run: python -m pip install --upgrade 'mypy>=0.800' 'pytest>=6.2.2' 'hypothesis>=6.1.1' 'pytz>=2021.1'
- name: Lint with mypy
run: mypy --strict iso8601
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
build
dist
.vscode
.hypothesis
24 changes: 22 additions & 2 deletions iso8601/test_iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import copy
import datetime
import pickle
import typing

import hypothesis
import hypothesis.strategies
import hypothesis.extra.pytz
import pytest

from iso8601 import iso8601
from . import iso8601


def test_iso8601_regex() -> None:
Expand Down Expand Up @@ -257,3 +259,21 @@ def test_parse_valid_date(
if isoformat:
assert parsed.isoformat() == isoformat
assert iso8601.parse_date(parsed.isoformat()) == parsed # Test round trip


@hypothesis.given(s=hypothesis.strategies.datetimes())
def test_hypothesis_valid_naive_datetimes(s: datetime.datetime) -> None:
as_string = s.isoformat()
parsed = iso8601.parse_date(as_string, default_timezone=None)
print(f"{s!r} {as_string!r} {parsed!r}")
assert s == parsed


@hypothesis.given(
s=hypothesis.strategies.datetimes(timezones=hypothesis.extra.pytz.timezones())
)
def test_hypothesis_valid_datetimes_with_timezone(s: datetime.datetime) -> None:
as_string = s.isoformat()
parsed = iso8601.parse_date(as_string)
print(f"{s!r} {as_string!r} {parsed!r}")
assert s == parsed
58 changes: 57 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pylint = "^2.6.0"
isort = "^5.7.0"
tox = "^3.21.4"
pytest = "^6.2.2"
hypothesis = "^6.1.1"
pytz = "^2021.1"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ python =
pypy3: pypy3

[testenv]
deps=pytest>=6.2.2
deps=
pytest>=6.2.2
hypothesis>=6.1.1
pytz>=2021.1
commands=py.test -vv --tb=short iso8601
setenv =
LC_ALL=C

0 comments on commit 35ae4ed

Please sign in to comment.